我的代码是
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);
}
我的代码正常工作。但是我想在一行中测试流体密度和其他特征。我不想每个都测试,因为ı具有很多特征。有一种方法可以测试此代码,例如(assert.true(precision.almostEqual(double,double, double,double,MaximumAbsoluteError)
答案 0 :(得分:0)
当然,这就是所谓的函数重载
void f(int a)
void f(int a, int b)
然后您可以同时调用两者:
f(3)
并且:
f(2, 8)
答案 1 :(得分:0)
您可以创建自己的方法,其中的值将作为params
参数给出。
public void AssertThatAlmostEqual(double precision, params double[] values)
{
var isAlmostEqual = Precision.AlmostEqual(double.Min(), double.Max(), precision);
Assert.IsTrue(isAlmostEqual);
}
正在测试
AssertThatAlmostEqual(0.01, actual1, actual2, actual3, expected);