mardi 17 juillet 2018

c# xunit colour testing not work

 [Theory]
    [InlineData(0.75)]
    public void ColorBindTest2(double max)
    {
        DefaultColorUnit.MediumColorStatic = Colors.Yellow;
        DefaultColorUnit.HighColorStatic = Colors.Red;
        var excepted = Colors.Orange;

        Color actual = _asd.renkata(max).Item2;

        Assert.Equal(excepted.R, actual.R);
        Assert.Equal(excepted.G, actual.G);
        Assert.Equal(excepted.B, actual.B);
    }

This is my unit testing code and below is my real code

public Tuple<Brush, Color> renkata(double val)
{

    byte r1 = DefaultColorUnit.LowColorStatic.R;
    byte g1 = DefaultColorUnit.LowColorStatic.G;
    byte b1 = DefaultColorUnit.LowColorStatic.B;


    byte r2 = DefaultColorUnit.MediumColorStatic.R;
    byte g2 = DefaultColorUnit.MediumColorStatic.G;
    byte b2 = DefaultColorUnit.MediumColorStatic.B;


    byte r3 = DefaultColorUnit.HighColorStatic.R;
    byte g3 = DefaultColorUnit.HighColorStatic.G;
    byte b3 = DefaultColorUnit.HighColorStatic.B;
    if (val <= 1 && val > 0.5)
    {
        val = 2 * (Math.Abs(0.5 - val));

        Color p1 = new Color();

        byte r = (byte)((r3 * val) + r2 * (1 - val));
        byte g = (byte)((g3 * val) + g2 * (1 - val));
        byte b = (byte)((b3 * val) + b2 * (1 - val));
        p1 = Color.FromRgb(r, g, b);
        Brush sold = new SolidColorBrush(Color.FromRgb(r, g, b));

        return new Tuple<Brush, Color>(sold, p1);


    }
    else if (val == 0.5)
    {

        Brush sold = new SolidColorBrush(Color.FromRgb(r2, g2, b2));
        Color p1 = (Color.FromRgb(r2, g2, b2));

        return new Tuple<Brush, Color>(sold, p1);

    }
    else if (val < 0.5 && val >= 0)
    {
        val = 2 * (Math.Abs(0.5 - val));
        val = 1 - val;
        Color p1 = new Color();

        byte r = (byte)((r2 * val) + r1 * (1 - val));
        byte g = (byte)((g2 * val) + g1 * (1 - val));
        byte b = (byte)((b2 * val) + b1 * (1 - val));
        p1 = Color.FromRgb(r, g, b);

        SolidColorBrush sold = new SolidColorBrush(Color.FromRgb(r, g, b));


        return new Tuple<Brush, Color>(sold, p1);
    }
    else if (val > 1)
    {
        SolidColorBrush sold = new SolidColorBrush(Colors.Black);
        Color p1 = Colors.Black;
        return new Tuple<Brush, Color>(sold, p1);
    }
    else if (val < 0)
    {
        SolidColorBrush sold = new SolidColorBrush(Colors.White);
        Color p1 = Colors.White;
        return new Tuple<Brush, Color>(sold, p1);
    }
    else
    {
        SolidColorBrush sold = new SolidColorBrush(Colors.Blue);
        Color p1 = Colors.Blue;
        return new Tuple<Brush, Color>(sold, p1);
    }
}

I want to testing my color calculator from three color colour gradient. color.orange in visual studio is 255 165 0 but my orange is 255 127 0 my code is loking good on running. but testing it is not real orange where is my wrong is my code calculate wrong color rgb or colors.orange is not real orange.

Aucun commentaire:

Enregistrer un commentaire