public void testPi_D() { bool OSProc = System.Environment.Is64BitProcess; REngine.SetEnvironmentVariables(); REngine engineObj = REngine.GetInstance(); // Loading a library from R engineObj.Evaluate("library(catR)"); // Dichotomous Items DataFrame DichoItems = engineObj.Evaluate("DichoItems <- genDichoMatrix(items = 100)").AsDataFrame(); engineObj.SetSymbol("DichoItems", DichoItems); // Adapting with the existing "CAT-Items" type (Wrapper) CATItems itemBank = new CATItems(DichoItems[0].Select(y => (double)y).ToArray(), DichoItems[1].Select(y => (double)y).ToArray(), DichoItems[2].Select(y => (double)y).ToArray(), DichoItems[3].Select(y => (double)y).ToArray()); #region "Test block for Ability Values (th)" PiList objPI = null; int decimalPoint = 4; double[] th_Values = CatRcs.Utils.CommonHelper.Sequence(-6, 6, by: 1); Console.WriteLine("******* TEST for Ability value Theta ********"); for (int k = 0; k < th_Values.Length; k++) { // Sequence Generation for Theta (Ability) values NumericVector th_val = engineObj.CreateNumericVector(new double[] { th_Values[k] }); engineObj.SetSymbol("th_val", th_val); // Calling the "Pi" from R GenericVector result_Pi = engineObj.Evaluate("result_Pi <- Pi(th = th_val, DichoItems, D = 1)").AsList(); // Getting the function result NumericVector Pi = result_Pi[0].AsNumeric(); NumericVector dPi = result_Pi[1].AsNumeric(); NumericVector d2Pi = result_Pi[2].AsNumeric(); NumericVector d3Pi = result_Pi[3].AsNumeric(); Console.WriteLine("Value of Theta: " + th_Values[k]); objPI = CatRLib.Pi_D(th_Values[k], itemBank, "", 1); #region "Pi" int z = 0; resultFlag = true; Console.WriteLine("****** Pi ******"); for (int i = 0; i < Pi.Length; i++) { z = i + 1; // item number if (decimal.Round(Convert.ToDecimal(Pi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.Pi[i]), decimalPoint)) { //Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } } Assert.IsTrue(resultFlag, "Passed"); Console.WriteLine("Values of Pi are Matched!"); #endregion #region "dPi" z = 0; resultFlag = true; Console.WriteLine("****** dPi ******"); for (int i = 0; i < dPi.Length; i++) { z = i + 1; // item number if (decimal.Round(Convert.ToDecimal(dPi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.dPi[i]), decimalPoint)) { //Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of dPi are Matched!"); #endregion #region "d2Pi" z = 0; resultFlag = true; Console.WriteLine("****** d2Pi ******"); for (int i = 0; i < d2Pi.Length; i++) { z = i + 1; // item number if (decimal.Round(Convert.ToDecimal(d2Pi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.d2Pi[i]), decimalPoint)) { //Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of d2Pi are Matched!"); #endregion #region "d3Pi" z = 0; resultFlag = true; Console.WriteLine("****** d3Pi ******"); for (int i = 0; i < d3Pi.Length; i++) { z = i + 1; // item number if (decimal.Round(Convert.ToDecimal(d3Pi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.d3Pi[i]), decimalPoint)) { //Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of d3Pi are Matched!"); #endregion } Assert.IsTrue(resultFlag); #endregion #region "Test block for Metric values" objPI = null; double[] D_Values = CatRcs.Utils.CommonHelper.Sequence(0.5, 1, by: 0.1); Console.WriteLine("******* TEST for Metric Constant ********"); for (int k = 0; k < D_Values.Length; k++) { // Sequence Generation for Theta (Ability) values NumericVector D_val = engineObj.CreateNumericVector(new double[] { D_Values[k] }); engineObj.SetSymbol("D_val", D_val); // Calling the "Pi" from R GenericVector result_Pi = engineObj.Evaluate("result_Pi <- Pi(th = 0, DichoItems, D = D_val)").AsList(); // Getting the function result NumericVector Pi = result_Pi[0].AsNumeric(); NumericVector dPi = result_Pi[1].AsNumeric(); NumericVector d2Pi = result_Pi[2].AsNumeric(); NumericVector d3Pi = result_Pi[3].AsNumeric(); Console.WriteLine("Value of Metric constant: " + D_Values[k]); objPI = CatRLib.Pi_D(0, itemBank, "", D_Values[k]); #region "Pi" int z = 0; resultFlag = true; Console.WriteLine("****** Pi ******"); for (int i = 0; i < Pi.Length; i++) { z = i + 1; // item number if (decimal.Round(Convert.ToDecimal(Pi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.Pi[i]), decimalPoint)) { //Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of Pi are matched!"); #endregion #region "dPi" z = 0; resultFlag = true; Console.WriteLine("****** dPi ******"); for (int i = 0; i < dPi.Length; i++) { z = i + 1; // item number if (decimal.Round(Convert.ToDecimal(dPi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.dPi[i]), decimalPoint)) { //Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of dPi are matched!"); #endregion #region "d2Pi" z = 0; resultFlag = true; Console.WriteLine("****** d2Pi ******"); for (int i = 0; i < d2Pi.Length; i++) { z = i + 1; // item number if (decimal.Round(Convert.ToDecimal(d2Pi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.d2Pi[i]), decimalPoint)) { //Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of d2Pi are Matched!"); #endregion #region "d3Pi" z = 0; resultFlag = true; Console.WriteLine("****** d3Pi ******"); for (int i = 0; i < d3Pi.Length; i++) { z = i + 1; // item number if (decimal.Round(Convert.ToDecimal(d3Pi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.d3Pi[i]), decimalPoint)) { //Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of d3Pi are Matched!"); #endregion } #endregion }