-
Notifications
You must be signed in to change notification settings - Fork 1
/
MathematicalTestHarness.java
208 lines (185 loc) · 9.95 KB
/
MathematicalTestHarness.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Calculus;
import Calculus.MathsContxtLAv.*;
import static Calculus.MathsContxtLAv.MyFuncExpress;
import static Calculus.MathsContxtLAv.eatAll;
import static Calculus.MathsContxtLAv.parse;
import static Calculus.UsageCalculus.EndTestCase;
import static Calculus.UsageCalculus.UserTestPredicate;
import static Calculus.UsageCalculus.mainRegressionIntegrTest;
import static Calculus.UsageCalculus.mainRegresssionDiffTest;
import static Calculus.UsageCalculus.mainRegresssionHghLvlExprODETest;
import static Calculus.UsageCalculus.mainRegresssionPredicate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import org.apache.log4j.Logger;
/**
*
* @author Administrator
*/
public class MathematicalTestHarness {
public static Logger log = Logger.getLogger(MathematicalTestHarness.class.getName());
static Map<String, Double> variables = new HashMap<>();
public static String TestDiffWithRespTo = "x";
public static boolean LowInitFlagRecordTime = false;
public static double CompletionTime = 0.0;
public static void main(String... args) {
if (LowInitFlagRecordTime == false) {
LocalDateTime current = LocalDateTime.now();
String[] TimeTaken = current.toString().split(":");
CompletionTime = Double.parseDouble(TimeTaken[1]);
System.out.println("MathematicalTestHarness:Started:Run Started Time:" + current + " ");
}
String StartMyTestCase = "1000";//4022//4019//1003//80003//50001//1000; //Test Case Number : Options :All or a Single Number
String EndMyTestCase = "110023";//110023; //Test Case Number : Options :All or a Single Number
int MaxDiffOrder = 5; // Maximum Differentiation Order (with Answers): 5 :Integration Order (with Answers): 5;
double NumberOfTestCases = Double.parseDouble(EndMyTestCase) - Double.parseDouble(StartMyTestCase);
variables.put(TestDiffWithRespTo, 0.0);
variables.put("Index", 1.0);
variables.put("StartMyTestCase", Double.parseDouble(StartMyTestCase));
String Exprn = "Index*x+StartMyTestCase";
System.out.println(" MathematicalTestHarness:TestHarness Equation=" + Exprn);
Expression expValue;
expValue = parse(Exprn, variables, TestDiffWithRespTo, "Silent", LogLevel.Off);
StartMyTestCase = "" + Math.round(expValue.eval());
System.out.println(" MathematicalTestHarness:Result(Expn Value:StartMyTestCase)=" + expValue.eval());
variables.put(TestDiffWithRespTo, NumberOfTestCases);
expValue = parse(Exprn, variables, TestDiffWithRespTo, "Silent", LogLevel.Off);
EndMyTestCase = "" + Math.round(expValue.eval());
System.out.println(" MathematicalTestHarness:Result(Expn Value:EndMyTestCase)=" + expValue.eval());
String TestCaseType = "LimitedRegression";//Test Suite Type:Individual OR LimitedRegression OR Regression
//Options( MaxDiffOrder, StartMyTestCase, EndMyTestCase , TestCaseType);
String xExprn = "Regression";
System.out.print("Do you want to run Regression OR 1 Equation Demo(UserInteractive) OR HghLvlExprODE: [" + xExprn + "]:");
Scanner scanner = new Scanner(System.in);
String TempxExprn = xExprn.trim();
TempxExprn = scanner.nextLine();
if (TempxExprn.equalsIgnoreCase("")) {
;
} else if (TempxExprn.equalsIgnoreCase("Regression")) {
;
} else if ((TempxExprn.equalsIgnoreCase("Demo")) || (TempxExprn.equalsIgnoreCase("UserInteractive"))) {
xExprn = "UserInteractive";
} else if (TempxExprn.equalsIgnoreCase("HghLvlExprODE")) {
xExprn = "HghLvlExprODE";
}
xExprn = xExprn.trim();
xExprn = eatAll(xExprn, ' ');
System.out.println("You Entered:" + xExprn);
if (xExprn.equalsIgnoreCase("Regression")) {
System.out.println(" MathematicalTestHarness:MaxDiffOrder=" + MaxDiffOrder);
TestHarnessClass MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
TestDiff(MaxDiffOrder, MyTestData);
MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
TestIntegr(MaxDiffOrder, MyTestData);
//TestPredicateMisc();
} else if (xExprn.equalsIgnoreCase("UserInteractive")) {
MathsContxtLAv.xmain();
}else if (xExprn.equalsIgnoreCase("HghLvlExprODE")) {
TestHarnessClass MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
mainRegresssionHghLvlExprODETest(MaxDiffOrder,MyTestData);
}
if (LowInitFlagRecordTime == false) {
LocalDateTime current = LocalDateTime.now();
String[] TimeTaken = current.toString().split(":");
CompletionTime = Double.parseDouble(TimeTaken[1]) - CompletionTime;
System.out.println("MathematicalTestHarness:Completed:Run Started Time:" + current + " " + " CompletionTime=" + CompletionTime + " minutes");
LowInitFlagRecordTime = true;
}
}
public static void mainMathPredicate(String... args) {
Map<String, Double> variables = new HashMap<>();
//String Exprn = TestPredicate();
String Exprn = UserTestPredicate;
String DiffWithRespTo = "x";
PredicateSep.PredicateBool expValue;
MyFuncExpress();
Exprn = eatAll(Exprn, ' ');
int i = 1;
for (double x = 0, y = 0; i < 10; y++, x++, i++) {
variables.put("x", x);
variables.put("y", y);
System.out.println("mainMathPredicate: x=" + x + " y=" + y + " Exprn=" + Exprn);
expValue = PredicateSep.parsePredicate(Exprn, variables, "Silent", MathsContxtLAv.LogLevel.Off);
System.out.println(" mainMathPredicate:Result(Logical Value)=" + expValue.eval());
System.out.print(System.lineSeparator());
}
}
public static void TestDiff(int MaxDiffOrder, TestHarnessClass MyTestData) {
mainRegresssionDiffTest(MaxDiffOrder, MyTestData);
//PalinController( MaxDiffOrder, StartMyTestCase, EndMyTestCase, "Diff");
//PalinControllerSame( MaxDiffOrder, StartMyTestCase, EndMyTestCase, "Diff");
//Exprn = "x^80+x^45+x^251-x^3+25";
//DiffLimitTestCase( 80, Exprn);
}
public static void TestIntegr(int MaxDiffOrder, TestHarnessClass MyTestData) {
mainRegressionIntegrTest(MaxDiffOrder, MyTestData);
//PalinController( MaxDiffOrder, StartMyTestCase, EndMyTestCase, "Integral");
//PalinControllerSame( MaxDiffOrder, StartMyTestCase, EndMyTestCase, "Integral");
//Exprn = "x^80+x^45+x^251-x^3+25";
//IntegralLimitTest( 80, Exprn);
}
public static void TestPredicateMisc() {
String StartMyTestCase = "100";//100; // Test Case Number : Options :All or a Single Number
String EndMyTestCase = "227";//227; // Test Case Number : Options :All or a Single Number
String TestCaseType = "LimitedRegression";//Test Suite Type:Individual OR LimitedRegression OR Regression
TestHarnessClass MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
StartMyTestCase = "100";
EndTestCase = 227;
MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
EndTestCase = 227;
//mainMathPredicate(args);
mainRegresssionPredicate(MyTestData);
StartMyTestCase = "100";
EndTestCase = 225;
MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
EndTestCase = 225;
//mainRegresssionExpr(MyTestData);
StartMyTestCase = "100";
EndTestCase = 225;
MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
EndTestCase = 225;
//mainRegresssionAlgebra(MyTestData);
StartMyTestCase = "100";
EndTestCase = 225;
MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
EndTestCase = 225;
//mainRegresssionSubs(MyTestData);
StartMyTestCase = "102";
EndTestCase = 102;
MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
EndTestCase = 102;
//mainRegresssionFInverse(MyTestData);
}
public static void Options(int MaxDiffOrder, String StartMyTestCase, String EndMyTestCase, String TestCaseType) {
String xExprn = "Regression";
System.out.print("Do you want to run Regression OR 1 Equation Demo(UserInteractive): [" + xExprn + "]:");
Scanner scanner = new Scanner(System.in);
String TempxExprn = xExprn.trim();
TempxExprn = scanner.nextLine();
if (TempxExprn.equalsIgnoreCase("")) {
;
} else if (TempxExprn.equalsIgnoreCase("Regression")) {
;
} else if ((TempxExprn.equalsIgnoreCase("Demo")) || (TempxExprn.equalsIgnoreCase("UserInteractive"))) {
xExprn = "UserInteractive";
}
xExprn = xExprn.trim();
xExprn = eatAll(xExprn, ' ');
System.out.println("You Entered:" + xExprn);
if (xExprn.equalsIgnoreCase("Regression")) {
TestHarnessClass MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
TestDiff(MaxDiffOrder, MyTestData);
MyTestData = new TestHarnessClass(14, StartMyTestCase, EndMyTestCase, TestCaseType);
TestIntegr(MaxDiffOrder, MyTestData);
} else if (xExprn.equalsIgnoreCase("UserInteractive")) {
MathsContxtLAv.xmain();
}
}
}