-
Notifications
You must be signed in to change notification settings - Fork 0
/
Driver.java
139 lines (102 loc) · 3.96 KB
/
Driver.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
/*
* Driver
*
* version 3
*
* August 3, 2019
*
* Copyright © 2019 Sabrina Kim, Martial Pastor, Keven Presseau-St-Laurent, Marco Tropiano, Diana Zitting-Rioux.
* All rights reserved.
*/
import java.lang.Math;
/**
* Driver class for the calculator, runs the application and also can print the test cases
*
* @version 3
* @author Sabrina Kim, Martial Pastor, Keven Presseau-St-Laurent, Marco Tropiano, Diana Zitting-Rioux
*
*/
public class Driver {
public static void main(String[] args) {
//printTestCases();
ConsoleApplication.run();
}
/**
* Free functions to print test cases
*/
public static void printTestCases() {
System.out.println("*** e^x ***" );
System.out.println("e^1.44 = " + Calculator.calculateExponent(10, (float) 1.44) );
System.out.println("\n*** 10^x ***");
System.out.println("Test 10^0 = " + Test.CheckTenPower(0f) );
System.out.println("Test 10^5 = " + Test.CheckTenPower(5f) );
System.out.println("Test 10^-5 = " + Test.CheckTenPower(-5f) );
System.out.println("Test 10^0.5 = " + Test.CheckTenPower(0.5f) );
System.out.println("Test 10^-999.99 = " + Test.CheckTenPower(-999.99f) );
System.out.println("Test 10^999.99 = " + Test.CheckTenPower(999.99f) );
System.out.println("Test 10^-25.3 = " + Test.CheckTenPower(-25.3f) );
System.out.println("Test 10^1.51 = " + Test.CheckTenPower(1.51f) );
System.out.println("Test 10^1.1111 = " + Test.CheckTenPower(1.1111f) );
Boolean coshtest = true;
int testCount = 10000;
if(Calculator.calculateCosh(0) != 1)
coshtest = false;
for(int i = 0; i < testCount; i++){
double x = 10000 - 20000*Math.random();
double hcosh = Calculator.calculateCosh(x);
double fcosh = Math.cosh(x);
if(checkPrecision(hcosh, fcosh)){
coshtest = false;
System.out.println("Cosh Fail: " + x + " / "
+ Double.toString(hcosh) + " != " + Double.toString(fcosh));
}
}
System.out.println("Cosh function with a precision of 10^-10 has passed the test: " + coshtest);
//System.out.println(calculator.Power(2, 3));
//System.out.println(calculator.Fact(4));
System.out.println("Test sin(-15) = " + Calculator.calculateSine(-15));
System.out.println("Test sin(0) = " + Calculator.calculateSine(0));
System.out.println("Test sin(-17300) = " + Calculator.calculateSine(-17300));
System.out.println("Test sin(38000) = " + Calculator.calculateSine(38000));
System.out.println("Test sin(12) = " + Calculator.calculateSine(12));
//System.out.println(calculator.getPi());
//System.out.println(calculator.PICONST);
System.out.println("Test Degree to Radian DegToRad(720) = " + Calculator.DegToRad(720));
System.out.println("Test Degree to Radian DegToRad(180) = " + Calculator.DegToRad(180));
System.out.println("Test Degree to Radian DegToRad(-18000) = " + Calculator.DegToRad(-18000));
System.out.println("Test Degree to Radian DegToRad(0) = " + Calculator.DegToRad(0));
System.out.println("\n4^(1/2) = " + checkSqrt(4));
System.out.println("1005^(1/2) = " + checkSqrt(10053));
System.out.println("(5)^(1/2) = " + checkSqrt(0.00001));
System.out.println("0.01^(1/2) = " + checkSqrt(29980983));
//System.out.println("(-2)^(1/2) = " + checkSqrt(calculator, -4)); // Negative value not accepted, causes an error
}
/**
* Check precision on hcosh
* @param hcosh
* @param fcosh
* @return dif>prec
*/
public static Boolean checkPrecision(double hcosh, double fcosh){
double prec = 10E-10;
double dif = hcosh - fcosh;
if(dif < 0)
dif = -dif;
return (dif > prec);
}
/**
* Checks square root compared to inbuilt square-root
* @param c
* @param sqrtval
* @return boolean
*/
public static boolean checkSqrt(double sqrtval){
double x = Calculator.calculateSquareRoot(sqrtval);
double y = Math.sqrt(sqrtval);
System.out.println("Result for Calculator.sqrt: " + x);
System.out.println("Result for Math.sqrt: " + y);
if (x == y)
return true;
return false;
}
}