Exemple #1
0
 private static Boolean KawigiEdit_RunTest(int testNum, double p0, double[] p1, double p2, Boolean hasAnswer, double[] p3)
 {
     Console.Write("Test " + testNum + ": [" + p0 + "," + "{");
     for (int i = 0; p1.Length > i; ++i) {
         if (i > 0) {
             Console.Write(",");
         }
         Console.Write(p1[i]);
     }
     Console.Write("}" + "," + p2);
     Console.WriteLine("]");
     FixedPoint obj;
     double[] answer;
     obj = new FixedPoint();
     DateTime startTime = DateTime.Now;
     answer = obj.find(p0, p1, p2);
     DateTime endTime = DateTime.Now;
     Boolean res;
     res = true;
     Console.WriteLine("Time: " + (endTime - startTime).TotalSeconds + " seconds");
     if (hasAnswer) {
         Console.WriteLine("Desired answer:");
         Console.Write("\t" + "{");
         for (int i = 0; p3.Length > i; ++i) {
             if (i > 0) {
                 Console.Write(",");
             }
             Console.Write(p3[i]);
         }
         Console.WriteLine("}");
     }
     Console.WriteLine("Your answer:");
     Console.Write("\t" + "{");
     for (int i = 0; answer.Length > i; ++i) {
         if (i > 0) {
             Console.Write(",");
         }
         Console.Write(answer[i]);
     }
     Console.WriteLine("}");
     if (hasAnswer) {
         if (answer.Length != p3.Length) {
             res = false;
         } else {
             for (int i = 0; answer.Length > i; ++i) {
                 if (Math.Abs(p3[i] - answer[i]) > 1e-9 * Math.Max(1.0, Math.Abs(p3[i]))) {
                     res = false;
                 }
             }
         }
     }
     if (!res) {
         Console.WriteLine("DOESN'T MATCH!!!!");
     } else if ((endTime - startTime).TotalSeconds >= 2) {
         Console.WriteLine("FAIL the timeout");
         res = false;
     } else if (hasAnswer) {
         Console.WriteLine("Match :-)");
     } else {
         Console.WriteLine("OK, but is it right?");
     }
     Console.WriteLine("");
     return res;
 }