Pārlūkot izejas kodu

calculator test revisions

Leon Hunter 5 gadus atpakaļ
vecāks
revīzija
cf947379ac

+ 6
- 9
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/AddTest.java Parādīt failu

@@ -11,37 +11,34 @@ public class AddTest {
11 11
     @Test
12 12
     public void test1() {
13 13
         // given
14
-        test(32.70, 49.04);
14
+        test(81.74, 32.70, 49.04);
15 15
     }
16 16
 
17 17
     @Test
18 18
     public void test2() {
19 19
         // given
20
-        test(689.93, 746.00);
20
+        test(1435.93, 689.93, 746.00);
21 21
     }
22 22
 
23 23
     @Test
24 24
     public void test3() {
25 25
         // given
26
-        test(35354.0, 74542.0);
26
+        test(109896.0, 35354.0, 74542.0);
27 27
     }
28 28
 
29 29
     @Test
30 30
     public void test4() {
31 31
         // given
32
-        test(746.93774653, 889409027.3737773635554244);
32
+        test(12.0, 4.0, 8.0);
33 33
     }
34 34
 
35 35
     @Test
36 36
     public void test5() {
37 37
         // given
38
-        test(99873636.94874, 839.03);
38
+        test(22.10, 7.06, 15.04);
39 39
     }
40 40
 
41
-    private void test(Double input1, Double input2) {
42
-        // given
43
-        Double expected = input1 + input2;
44
-
41
+    private void test(Double expected, Double input1, Double input2) {
45 42
         // when
46 43
         Calculator calculator = new Calculator();
47 44
         Double actual = calculator.add(input1, input2);

+ 6
- 9
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/DivideTest.java Parādīt failu

@@ -11,37 +11,34 @@ public class DivideTest {
11 11
     @Test
12 12
     public void test1() {
13 13
         // given
14
-        test(64.0, 8.0);
14
+        test(12.0, 144.0, 12.0);
15 15
     }
16 16
 
17 17
     @Test
18 18
     public void test2() {
19 19
         // given
20
-        test(19640.0, 8.00);
20
+        test(5.0, 60.0, 12.0);
21 21
     }
22 22
 
23 23
     @Test
24 24
     public void test3() {
25 25
         // given
26
-        test(363.0, 3.0);
26
+        test(6.0, 36.0, 6.0);
27 27
     }
28 28
 
29 29
     @Test
30 30
     public void test4() {
31 31
         // given
32
-        test(746.93774653, 889409027.3737773635554244);
32
+        test(9.0, 63.0, 5.0);
33 33
     }
34 34
 
35 35
     @Test
36 36
     public void test5() {
37 37
         // given
38
-        test(720.0, 9.0);
38
+        test(8.0, 72.0, 9.0);
39 39
     }
40 40
 
41
-    private void test(Double input1, Double input2) {
42
-        // given
43
-        Double expected = input1 / input2;
44
-
41
+    private void test(Double expected, Double input1, Double input2) {
45 42
         // when
46 43
         Calculator calculator = new Calculator();
47 44
         Double actual = calculator.divide(input1, input2);

+ 6
- 9
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/SquareRootTest.java Parādīt failu

@@ -7,37 +7,34 @@ public class SquareRootTest {
7 7
     @Test
8 8
     public void test1() {
9 9
         // given
10
-        test(64.0);
10
+        test(8.0, 64.0);
11 11
     }
12 12
 
13 13
     @Test
14 14
     public void test2() {
15 15
         // given
16
-        test(44100.0);
16
+        test(438.0, 191844.0);
17 17
     }
18 18
 
19 19
     @Test
20 20
     public void test3() {
21 21
         // given
22
-        test(144.0);
22
+        test(12.0, 144.0);
23 23
     }
24 24
 
25 25
     @Test
26 26
     public void test4() {
27 27
         // given
28
-        test(390625.0);
28
+        test(864.0, 746496.0);
29 29
     }
30 30
 
31 31
     @Test
32 32
     public void test5() {
33 33
         // given
34
-        test(36.0);
34
+        test(6.0, 36.0);
35 35
     }
36 36
 
37
-    private void test(Double input) {
38
-        // given
39
-        Double expected = Math.sqrt(input);
40
-
37
+    private void test(Double expected, Double input) {
41 38
         // when
42 39
         Calculator calculator = new Calculator();
43 40
         Double actual = calculator.squareRoot(input);

+ 6
- 14
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/SquareRootsTest.java Parādīt failu

@@ -12,42 +12,34 @@ public class SquareRootsTest {
12 12
     @Test
13 13
     public void test1() {
14 14
         // given
15
-        test(64.0, 81.0, 96.0, 9.0);
15
+        test(new Double[]{8.0, 9.0, 10.0, 3.0}, 64.0, 81.0, 100.0, 9.0);
16 16
     }
17 17
 
18 18
     @Test
19 19
     public void test2() {
20 20
         // given
21
-        test(44100.0, 86943.0, 9.0, 16.0);
21
+        test(new Double[]{864.0, 3.0, 4.0}, 746496.0, 9.0, 16.0);
22 22
     }
23 23
 
24 24
     @Test
25 25
     public void test3() {
26 26
         // given
27
-        test(144.0, 72.98, 81.0);
27
+        test(new Double[]{12.0, 438.0, }, 144.0, 191844.0, 81.0);
28 28
     }
29 29
 
30 30
     @Test
31 31
     public void test4() {
32 32
         // given
33
-        test(390625.0, 36.0, 64.0, 144.0);
33
+        test(new Double[]{6.0, 8.0, 12.0}, 36.0, 64.0, 144.0);
34 34
     }
35 35
 
36 36
     @Test
37 37
     public void test5() {
38 38
         // given
39
-        test(36.0, 255.0, 144.0, 81.0);
39
+        test(new Double[]{6.0, 12.0, 9.0}, 36.0, 144.0, 81.0);
40 40
     }
41 41
 
42
-    private void test(Double... inputArray) {
43
-        // given
44
-        Double sqRootInput;
45
-        Double[] expected = new Double[inputArray.length];
46
-        for(int i = 0; i < inputArray.length; i++) {
47
-            sqRootInput = Math.sqrt(inputArray[i]);
48
-            expected[i] = sqRootInput;
49
-        }
50
-
42
+    private void test(Double[] expected, Double... inputArray) {
51 43
         // when
52 44
         Calculator calculator = new Calculator();
53 45
         Double[] actual = calculator.squareRoots(inputArray);

+ 6
- 9
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/SquareTest.java Parādīt failu

@@ -11,37 +11,34 @@ public class SquareTest {
11 11
     @Test
12 12
     public void test1() {
13 13
         // given
14
-        test(32.70);
14
+        test(1069.29, 32.70);
15 15
     }
16 16
 
17 17
     @Test
18 18
     public void test2() {
19 19
         // given
20
-        test(689.93);
20
+        test(476003.4049, 689.93);
21 21
     }
22 22
 
23 23
     @Test
24 24
     public void test3() {
25 25
         // given
26
-        test(35354.0);
26
+        test(36.0, 6.0);
27 27
     }
28 28
 
29 29
     @Test
30 30
     public void test4() {
31 31
         // given
32
-        test(746.93774653);
32
+        test(64.0, 8.0);
33 33
     }
34 34
 
35 35
     @Test
36 36
     public void test5() {
37 37
         // given
38
-        test(99873636.94874);
38
+        test(321489.0, 567.0);
39 39
     }
40 40
 
41
-    private void test(Double input) {
42
-        // given
43
-        Double expected = input * input;
44
-
41
+    private void test(Double expected, Double input) {
45 42
         // when
46 43
         Calculator calculator = new Calculator();
47 44
         Double actual = calculator.square(input);

+ 6
- 14
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/SquaresTest.java Parādīt failu

@@ -11,42 +11,34 @@ public class SquaresTest {
11 11
     @Test
12 12
     public void test1() {
13 13
         // given
14
-        test(32.70, 738.08, 523.735, 837.90);
14
+        test(new Double[]{4.0,16.0, 144.0}, 2.0,4.0,12.0);
15 15
     }
16 16
 
17 17
     @Test
18 18
     public void test2() {
19 19
         // given
20
-        test(689.93, 847.95, 3736.0, 8.0, 3.0);
20
+        test(new Double[]{100.00, 49.0, 64.0, 36.0},10.0, 7.0, 8.0, 6.0);
21 21
     }
22 22
 
23 23
     @Test
24 24
     public void test3() {
25 25
         // given
26
-        test(35354.0, 3.5, 7.8, 6354495875.00, 725.0);
26
+        test(new Double[]{9.0, 25.0, 121.0, 169.0}, 3.0, 5.0, 11.0, 13.0);
27 27
     }
28 28
 
29 29
     @Test
30 30
     public void test4() {
31 31
         // given
32
-        test(746.93774653, 2.0, 6.0, 47.0, 74.0, 838.0);
32
+        test(new Double[]{16.0, 9.0, 64.0, 81.0}, 4.0, 3.0, 8.0, 9.0);
33 33
     }
34 34
 
35 35
     @Test
36 36
     public void test5() {
37 37
         // given
38
-        test(99873636.94874);
38
+        test(new Double[]{4.0, 25.0, 81.0}, 2.0, 5.0, 9.0);
39 39
     }
40 40
 
41
-    private void test(Double... inputArray) {
42
-        // given
43
-        Double squaredInput;
44
-        Double[] expected = new Double[inputArray.length];
45
-        for(int i = 0; i < inputArray.length; i++) {
46
-            squaredInput = inputArray[i] * inputArray[i];
47
-            expected[i] = squaredInput;
48
-        }
49
-
41
+    private void test(Double[] expected, Double... inputArray) {
50 42
         // when
51 43
         Calculator calculator = new Calculator();
52 44
         Double[] actual = calculator.squares(inputArray);