-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainSpec.js
184 lines (170 loc) · 4.87 KB
/
mainSpec.js
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
describe("Math functions with 2 positive integers", function () {
let num1;
let num2;
beforeEach(function () {
// arrange
num1 = 195;
num2 = 3;
});
it("should add two positive numbers", () => {
// expect(infoE).toBeDefined();
// expect(infoE.id).toBe('info-E-id')
// });
// it('add two numbers', function() {
// act
const result = add(num1, num2);
// assert
expect(result).toBe(198);
});
it("multiply two positive numbers", function () {
// act
const result = multiply(num1, num2);
// assert
expect(result).toBe(585);
});
it("subtract two positive numbers", function () {
// act
const result = subtract(num1, num2);
// assert
expect(result).toBe(192);
});
it("divide two positive numbers", function () {
// act
const result = divide(num1, num2);
// assert
expect(result).toBe(65);
});
});
describe("Check [+] add function with different values", function () {
let varsToCheck;
varsToCheck = [
//[num1, num2, result, error]
[1, 2, 3, ""],
[30.01, 30.02, 60.03, ""],
[1000.021, 0.02, 1000.041, ""],
[0.1, 0.2, 0.3, ""],
[0.7, 0.1, 0.8, ""],
[203.95555, 0.00009, 203.95564, ""],
[203.95555, 0.000009, 203.95556, ""],
[0.01, 0.02, 0.03, ""],
[0.008, 0.002, 0.01, ""],
[0.0008, 0.0002, 0.001, ""],
[0.01, 0.06, 0.07, ""],
[1, -2, -1, ""],
[1.2, 2.3, 3.5, ""],
[-4, -9, -13, ""],
];
for (let i = 0; i < varsToCheck.length; i++) {
it(`Should add properly: (${varsToCheck[i][0]}) + (${varsToCheck[i][1]}) = ${varsToCheck[i][2]}`, function () {
//arrange
let result;
if (error || memoryError) {
clear();
}
result = add(varsToCheck[i][0], varsToCheck[i][1]);
expect(result).toBe(varsToCheck[i][2]);
expect(error).toBe(varsToCheck[i][3]);
});
}
});
describe("Check [-] subtract function with different values", function () {
let varsToCheck;
varsToCheck = [
//[num1, num2, result, error]
[9, 2, 7, ""],
[194.1193, 159, 35.1193, ""],
[42.5, 42.65, -0.15, ""],
[0.3, 0.2, 0.1, ""],
[0.1, 0.3, -0.2, ""],
[53, -1000, 1053, ""],
[2, 7, -5, ""],
[-10, -6, -4, ""],
];
for (let i = 0; i < varsToCheck.length; i++) {
it(`Should subtract properly: (${varsToCheck[i][0]}) - (${varsToCheck[i][1]}) = ${varsToCheck[i][2]}`, function () {
//arrange
let result;
if (error || memoryError) {
clear();
}
result = subtract(varsToCheck[i][0], varsToCheck[i][1]);
expect(result).toBe(varsToCheck[i][2]);
expect(error).toBe(varsToCheck[i][3]);
});
}
});
describe("Check [*] multiply function with different values", function () {
let varsToCheck;
varsToCheck = [
//[num1, num2, result, error]
[9, 2, 18, ""],
[0.6666666, 2, 1.3333332, ""],
[6666, 3, 19998, ""],
[0.6666666, 3, 1.9999998, ""],
[0.1, 2232.0, 223.2, ""],
[1, 32.09, 32.09, ""],
[200.3, 3, 600.9, ""],
[2232.0, 0.1, 223.2, ""],
[0.003, 1000, 3, ""],
[100, 25, 2500, ""],
[9.99, 5, 49.95, ""],
[0.1, 0.2, 0.02, ""],
[0.3, 0.0003, 0.00009, ""],
[95, 722228.63, 68611720, ""],
[0.6, 3, 1.8, ""],
[2, -7, -14, ""],
[-10, -6, 60, ""],
[99999999, 99999999, 99999998, "Number is too long for display."],
[99999999, 0.1, 9999999.9, ""],
];
for (let i = 0; i < varsToCheck.length; i++) {
it(`Should multiply properly: (${varsToCheck[i][0]}) * (${varsToCheck[i][1]}) = ${varsToCheck[i][2]}`, function () {
//arrange
let result;
if (error || memoryError) {
clear();
}
result = multiply(varsToCheck[i][0], varsToCheck[i][1]);
expect(result).toBe(varsToCheck[i][2]);
expect(error).toBe(varsToCheck[i][3]);
});
}
});
describe("Check [/] divide function with different values", function () {
let varsToCheck;
varsToCheck = [
//[num1, num2, result, error]
[9, 3, 3, ""],
[2, 3, 0.6666667, ""],
[0.6666666, 2, 0.3333333, ""],
[1, 32.09, 0.0311624, ""],
[223.2, 2232.0, 0.1, ""],
[10, 100, 0.1, ""],
[2232.0, 0.1, 22320, ""],
[1, 5000, 0.0002, ""],
[2, 1000, 0.002, ""],
[100, 50, 2, ""],
[0.9, 0.03, 30, ""],
[12, -4, -3, ""],
[-60, -6, 10, ""],
[-10, 0, "Undefined", "Division by 0 is impossible."],
[10, 0, "Undefined", "Division by 0 is impossible."],
];
for (let i = 0; i < varsToCheck.length; i++) {
it(`Should divide properly: (${varsToCheck[i][0]}) / (${
varsToCheck[i][1]
}) = ${varsToCheck[i][2]}; ${
varsToCheck[i][3] ? "ERROR:" + varsToCheck[i][3] : ""
}`, function () {
//arrange
let result;
if (error || memoryError) {
clear();
}
result = divide(varsToCheck[i][0], varsToCheck[i][1]);
expect(result).toBe(varsToCheck[i][2]);
expect(error).toBe(varsToCheck[i][3]);
// }
});
}
});