tbf/TBFTests/Entities/MeasurementCorrectionTest.cs

65 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using Config.Entities;
using JetBrains.Annotations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TBFTests.Entities
{
[TestClass]
[TestSubject(typeof(MeasurementCorrection))]
public class MeasurementCorrectionTest
{
[TestMethod]
public void GetCorrection()
{
double rawValue, expectedVal;
IList<MeasurementCorrection> corrections;
corrections = new List<MeasurementCorrection>(2);
MeasurementCorrection Lo, Hi;
Lo = new MeasurementCorrection(1);
Lo.Measurement = 0.04; //CorrectionValLo;
Lo.Correction = 0.0F; //MsrdValLimLo;
corrections.Add(Lo);
Hi = new MeasurementCorrection(2);
Hi.Measurement = 0.22F;//CorrectionValHi;
Hi.Correction = 2.0F;//MsrdValLimHi;
corrections.Add(Hi);
expectedVal = Lo.Correction;
rawValue = Lo.Measurement; //Ampers
double CorrectionVal = MeasurementCorrection.GetCorrection(rawValue, corrections);
Console.WriteLine("{0} Correction - rawValue: {1} CorrectionVal: {2}", "TEST " + rawValue, rawValue, CorrectionVal);
Assert.IsTrue(expectedVal == CorrectionVal);
expectedVal = Hi.Correction;
rawValue = Hi.Measurement; //Ampers
CorrectionVal = MeasurementCorrection.GetCorrection(rawValue, corrections);
Console.WriteLine("{0} Correction - rawValue: {1} CorrectionVal: {2}", "TEST " + rawValue, rawValue, CorrectionVal);
Assert.IsTrue(expectedVal == CorrectionVal);
double toler = 0.3;
expectedVal = 1.24; //bar
rawValue = 0.152; //Ampers
CorrectionVal = MeasurementCorrection.GetCorrection(rawValue, corrections);
Console.WriteLine("{0} Correction - rawValue: {1} CorrectionVal: {2}", "TEST " + rawValue, rawValue, CorrectionVal);
Assert.IsTrue((expectedVal + toler) >= CorrectionVal && (expectedVal - toler) <= CorrectionVal);
toler = 0.0001;
expectedVal = 1.0;
rawValue = Lo.Measurement + ((Hi.Measurement - Lo.Measurement) / 2.0); //Ampers 0.129999999403954
CorrectionVal = MeasurementCorrection.GetCorrection(rawValue, corrections);
Console.WriteLine("{0} Correction - rawValue: {1} CorrectionVal: {2}", "TEST " + rawValue, rawValue, CorrectionVal);
Assert.IsTrue((expectedVal + toler) >= CorrectionVal && (expectedVal - toler) <= CorrectionVal);
}
}
}