2

My code is

   public void Compare_CoolProp_with_CoreMediumDensity() {
        Water coreWater = new Water(Pressure.FromPascals(101325), Temperature.FromKelvins(300));

        GetCoolPropOriginal asd = new GetCoolPropOriginal();
        GetCoolProp asdf = new GetCoolProp();
        Pressure pressure = Pressure.FromPascals(101325);
        Temperature temperature = Temperature.FromKelvins(300);
        double actual = (CoolProp.PropsSI("D", "P", 101325, "T", 300, "Water"));
        double actual2 = asd.GetDensity("P", 101325, "T", 300, "Water");
        double actual3= asdf.GetDensity(pressure, temperature,"Water"); 
        double  expected = coreWater.ThermodynamicState.Density.KilogramsPerCubicMeter;
        //double expected3 = coreWater.ThermodynamicState.Temperature.DegreesCelsius;
        List<double> liste = new List<double>();
        liste.Add(actual);
        liste.Add(actual2);
        liste.Add(actual3);
        liste.Add(expected);
        Boolean boola = true;
        for (int i = 0; i < liste.Count-1; i++)
        {
            for (int j = i+1; j < liste.Count; j++)
            {
                if (!Precision.AlmostEqual(liste[i], liste[j], 0.01))
                {
                    boola = false;
                }  
            }
        }

      Assert.True(boola);
    }

My code is work. But I want to test my fluids density and other features in one line.I dont want for each because ı have a lot of feature.İs there a way to test this code like (assert.true(precision.almostEqual(double,double,double,double,MaximumAbsoluteError)

Oliver Hader
  • 4,093
  • 1
  • 25
  • 47
ORHAN TOPDAĞ
  • 157
  • 1
  • 1
  • 11

2 Answers2

0

Sure, it's called overloading of a function

void f(int a)
void f(int a, int b)

Then you can call both:

f(3) 

And:

f(2, 8)
Matěj Štágl
  • 870
  • 1
  • 9
  • 27
0

You can create your own method where values will be given as params arguments.

public void AssertThatAlmostEqual(double precision, params double[] values)
{
    var isAlmostEqual = Precision.AlmostEqual(double.Min(), double.Max(), precision);
    Assert.IsTrue(isAlmostEqual);
}

In test

AssertThatAlmostEqual(0.01, actual1, actual2, actual3, expected);
Fabio
  • 31,528
  • 4
  • 33
  • 72
  • Yes I can do it but ı want to test my class with xunits original methods.thank you but ı dont want xunit change.Is there original method in xunit can do it. – ORHAN TOPDAĞ Jul 27 '18 at 08:16
  • @ORHANTOPDAĞ, you don't need to change xunit methods. You will just create new one in the same class where your test methods are – Fabio Jul 27 '18 at 08:28