public void TestCalcMeanValue() { var values = new decimal[] { 1, 2, 3, 4, 5 }; var u = ValidateWindow.CalcMeanValue(values); Assert.AreEqual(3, u); //抓住异常 Assert.Throws(typeof(InvalidParameterExcepiton), () => ValidateWindow.CalcMeanValue(null)); ////50个数据的类型各式各样 var values2 = new decimal[] { 2, 2.7m, 11, 0.5m, 6.9m, 11.88m, 4, 5.8m, 44, 63, 25.7m, 44, 11, 23, 35, 444, 2, 22.444m, 1, 3, 0, -0.6m, -9, -11, 66, 45, 33, 21, 31, 29, 54, -8.9m, 3, 6, 9, 8, 10, 11, 21, 14, 16, 17, 19, 21, 11, 13, 23, 1, 3, 8 }; var u2 = ValidateWindow.CalcMeanValue(values2); Assert.AreEqual(24.53, Math.Round(u2, 2)); Assert.Throws(typeof(InvalidParameterExcepiton), () => ValidateWindow.CalcRValue(new decimal[] {})); }
public void TestInitCalcRValue() { var values = new decimal[] { 1, 2, 3, 4, 5 }; const decimal kT = 0.5m; var initR = ValidateWindow.CalcRValue(values, kT); Assert.AreEqual(2, initR); //抓住异常1 var values1 = new decimal[] { 1, 34, 56, 90, 222, 555 }; Assert.Throws(typeof(UnStableWindowExcepiton), () => ValidateWindow.CalcRValue(values1, kT)); //抓住异常2 Assert.Throws(typeof(InvalidParameterExcepiton), () => ValidateWindow.CalcRValue(null, kT)); ////50个数据的类型各式各样--需要知道我们数据返回的小数点个数! var values2 = new decimal[] { 2, 2.7m, 11, 0.5m, 6.9m, 11.88m, 4, 5.8m, 44, 63, 25.7m, 44, 11, 23, 35, 444, 2, 22, 1, 3, 0, -0.6m, -9, -11, 66, 45, 33, 21, 31, 29, 54, -8.9m, 3, 6, 9, 8, 10, 11, 21, 14, 16, 17, 19, 21, 11, 13, 23, 1, 3, 8 }; const decimal kT2 = 3; var initR2 = ValidateWindow.CalcRValue(values2, kT2); Assert.AreEqual(35.48, Math.Round(initR2, 2)); //抓住异常1 const decimal kT3 = 2; Assert.Throws(typeof(UnStableWindowExcepiton), () => ValidateWindow.CalcRValue(values2, kT3)); }