-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArmitheticCalculatorTestBase.cpp
61 lines (53 loc) · 1.57 KB
/
ArmitheticCalculatorTestBase.cpp
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
#include "ArmitheticCalculatorTestBase.h"
#include "ArithmeticCalculator.h"
#include "LinkedList.h"
#include <math.h>
#include <string>
#include <iostream>
using namespace std;
struct Test {
const char* Equation;
double Result;
};
void RunTest(Test test) {
ArithmeticCalculator* calculator = new ArithmeticCalculator();
double result = calculator->Solve(_strdup(test.Equation));
if (fabs(result - test.Result) > 0.001) {
cout << "WRONG [";
cout << test.Equation;
cout << "] should equal [";
cout << test.Result;
cout << "] but equals [";
cout << result;
cout << "] WRONG";
}
else {
cout << "[";
cout << test.Equation;
cout << "] equals [";
cout << result;
cout << "]";
}
cout << "\n";
}
void ArmitheticCalculatorTest::Run() {
LinkedList<Test>* testSet = new LinkedList<Test>();
testSet->Append({ "(2 + sin(3)) * (min(4,5) + 6) * -7", -149.878 });
testSet->Append({ "0", 0 });
testSet->Append({ "-5", -5 });
testSet->Append({ "sin(3)", 0.141 });
testSet->Append({ "min(4.64,5.1)", 4.64 });
testSet->Append({ "1+nsd(100,200)", 101 });
testSet->Append({ "-1+1+nsn(86,128)", 5504 });
testSet->Append({ "sin(1)+cos(2)+tan(3)", 0.283 });
testSet->Append({ "cos(2)+(sin(2))+tan(1.4)-1", 5.291 });
testSet->Append({ "sqrt(2) + exp(5)", 149.827 });
testSet->Append({ "((1+2)*(3+4))/((5+6)*(7-8))", -1.91 });
testSet->Append({ "min(1+3,5)", 4 });
testSet->Append({ "max((2 + sin(3)) * (min(4,5) + 6) * -7, ((1+2)*(3+4))/((5+6)*(7-8)))", -1.91 });
testSet->MoveFirst();
while (!testSet->AtEnd()) {
RunTest(testSet->GetCurrent());
testSet->MoveNext();
}
}