Browse Source

calculator tests

Leon 5 years ago
parent
commit
5082d9a204

+ 1
- 1
src/main/java/rocks/zipcode/quiz3a/fundamentals/Calculator.java View File

@@ -16,7 +16,7 @@ public class Calculator {
16 16
         return null;
17 17
     }
18 18
 
19
-    public static Double[] squares(Double values) {
19
+    public static Double[] squares(Double... values) {
20 20
         return null;
21 21
     }
22 22
 

+ 52
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/AddTest.java View File

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.quiz3a.fundamentals.calculator;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.Calculator;
6
+
7
+/**
8
+ * @author leon on 01/01/2019.
9
+ */
10
+public class AddTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        test(32.70, 49.04);
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        // given
20
+        test(689.93, 746.00);
21
+    }
22
+
23
+    @Test
24
+    public void test3() {
25
+        // given
26
+        test(35354.0, 74542.0);
27
+    }
28
+
29
+    @Test
30
+    public void test4() {
31
+        // given
32
+        test(746.93774653, 889409027.3737773635554244);
33
+    }
34
+
35
+    @Test
36
+    public void test5() {
37
+        // given
38
+        test(99873636.94874, 839.03);
39
+    }
40
+
41
+    private void test(Double input1, Double input2) {
42
+        // given
43
+        Double expected = input1 + input2;
44
+
45
+        // when
46
+        Calculator calculator = new Calculator();
47
+        Double actual = calculator.add(input1, input2);
48
+
49
+        // then
50
+        Assert.assertEquals(expected, actual, 0);
51
+    }
52
+}

+ 52
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/DivideTest.java View File

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.quiz3a.fundamentals.calculator;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.Calculator;
6
+
7
+/**
8
+ * @author leon on 01/01/2019.
9
+ */
10
+public class DivideTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        test(64.0, 8.0);
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        // given
20
+        test(19640.0, 8.00);
21
+    }
22
+
23
+    @Test
24
+    public void test3() {
25
+        // given
26
+        test(363.0, 3.0);
27
+    }
28
+
29
+    @Test
30
+    public void test4() {
31
+        // given
32
+        test(746.93774653, 889409027.3737773635554244);
33
+    }
34
+
35
+    @Test
36
+    public void test5() {
37
+        // given
38
+        test(720.0, 9.0);
39
+    }
40
+
41
+    private void test(Double input1, Double input2) {
42
+        // given
43
+        Double expected = input1 / input2;
44
+
45
+        // when
46
+        Calculator calculator = new Calculator();
47
+        Double actual = calculator.divide(input1, input2);
48
+
49
+        // then
50
+        Assert.assertEquals(expected, actual, 0);
51
+    }
52
+}

+ 44
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/SquareRootTest.java View File

@@ -1,4 +1,48 @@
1 1
 package rocks.zipcode.quiz3a.fundamentals.calculator;
2
+import org.junit.*;
3
+import rocks.zipcode.quiz3a.fundamentals.Calculator;
2 4
 
3 5
 public class SquareRootTest {
6
+
7
+    @Test
8
+    public void test1() {
9
+        // given
10
+        test(64.0);
11
+    }
12
+
13
+    @Test
14
+    public void test2() {
15
+        // given
16
+        test(44100.0);
17
+    }
18
+
19
+    @Test
20
+    public void test3() {
21
+        // given
22
+        test(144.0);
23
+    }
24
+
25
+    @Test
26
+    public void test4() {
27
+        // given
28
+        test(390625.0);
29
+    }
30
+
31
+    @Test
32
+    public void test5() {
33
+        // given
34
+        test(36.0);
35
+    }
36
+
37
+    private void test(Double input) {
38
+        // given
39
+        Double expected = Math.sqrt(input);
40
+
41
+        // when
42
+        Calculator calculator = new Calculator();
43
+        Double actual = calculator.squareRoot(input);
44
+
45
+        // then
46
+        Assert.assertEquals(expected, actual, 0);
47
+    }
4 48
 }

+ 58
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/SquareRootsTest.java View File

@@ -0,0 +1,58 @@
1
+package rocks.zipcode.quiz3a.fundamentals.calculator;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.Calculator;
6
+
7
+/**
8
+ * @author leon on 01/01/2019.
9
+ */
10
+public class SquareRootsTest {
11
+
12
+    @Test
13
+    public void test1() {
14
+        // given
15
+        test(64.0, 81.0, 96.0, 9.0);
16
+    }
17
+
18
+    @Test
19
+    public void test2() {
20
+        // given
21
+        test(44100.0, 86943.0, 9.0, 16.0);
22
+    }
23
+
24
+    @Test
25
+    public void test3() {
26
+        // given
27
+        test(144.0, 72.98, 81.0);
28
+    }
29
+
30
+    @Test
31
+    public void test4() {
32
+        // given
33
+        test(390625.0, 36.0, 64.0, 144.0);
34
+    }
35
+
36
+    @Test
37
+    public void test5() {
38
+        // given
39
+        test(36.0, 255.0, 144.0, 81.0);
40
+    }
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
+
51
+        // when
52
+        Calculator calculator = new Calculator();
53
+        Double[] actual = calculator.squareRoots(inputArray);
54
+
55
+        // then
56
+        Assert.assertArrayEquals(expected, actual);
57
+    }
58
+}

+ 52
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/SquareTest.java View File

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.quiz3a.fundamentals.calculator;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.Calculator;
6
+
7
+/**
8
+ * @author leon on 01/01/2019.
9
+ */
10
+public class SquareTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        test(32.70);
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        // given
20
+        test(689.93);
21
+    }
22
+
23
+    @Test
24
+    public void test3() {
25
+        // given
26
+        test(35354.0);
27
+    }
28
+
29
+    @Test
30
+    public void test4() {
31
+        // given
32
+        test(746.93774653);
33
+    }
34
+
35
+    @Test
36
+    public void test5() {
37
+        // given
38
+        test(99873636.94874);
39
+    }
40
+
41
+    private void test(Double input) {
42
+        // given
43
+        Double expected = input * input;
44
+
45
+        // when
46
+        Calculator calculator = new Calculator();
47
+        Double actual = calculator.square(input);
48
+
49
+        // then
50
+        Assert.assertEquals(expected, actual, 0);
51
+    }
52
+}

+ 57
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/SquaresTest.java View File

@@ -0,0 +1,57 @@
1
+package rocks.zipcode.quiz3a.fundamentals.calculator;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.Calculator;
6
+
7
+/**
8
+ * @author leon on 01/01/2019.
9
+ */
10
+public class SquaresTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        test(32.70, 738.08, 523.735, 837.90);
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        // given
20
+        test(689.93, 847.95, 3736.0, 8.0, 3.0);
21
+    }
22
+
23
+    @Test
24
+    public void test3() {
25
+        // given
26
+        test(35354.0, 3.5, 7.8, 6354495875.00, 725.0);
27
+    }
28
+
29
+    @Test
30
+    public void test4() {
31
+        // given
32
+        test(746.93774653, 2.0, 6.0, 47.0, 74.0, 838.0);
33
+    }
34
+
35
+    @Test
36
+    public void test5() {
37
+        // given
38
+        test(99873636.94874);
39
+    }
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
+
50
+        // when
51
+        Calculator calculator = new Calculator();
52
+        Double[] actual = calculator.squares(inputArray);
53
+
54
+        // then
55
+        Assert.assertArrayEquals(expected, actual);
56
+    }
57
+}

+ 52
- 0
src/test/java/rocks/zipcode/quiz3a/fundamentals/calculator/SubtractTest.java View File

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.quiz3a.fundamentals.calculator;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.quiz3a.fundamentals.Calculator;
6
+
7
+/**
8
+ * @author leon on 01/01/2019.
9
+ */
10
+public class SubtractTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        test(32.70, 49.04);
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        // given
20
+        test(689.93, 746.00);
21
+    }
22
+
23
+    @Test
24
+    public void test3() {
25
+        // given
26
+        test(35354.0, 74542.0);
27
+    }
28
+
29
+    @Test
30
+    public void test4() {
31
+        // given
32
+        test(746.93774653, 889409027.3737773635554244);
33
+    }
34
+
35
+    @Test
36
+    public void test5() {
37
+        // given
38
+        test(99873636.94874, 839.03);
39
+    }
40
+
41
+    private void test(Double input1, Double input2) {
42
+        // given
43
+        Double expected = input1 - input2;
44
+
45
+        // when
46
+        Calculator calculator = new Calculator();
47
+        Double actual = calculator.subtract(input1, input2);
48
+
49
+        // then
50
+        Assert.assertEquals(expected, actual, 0);
51
+    }
52
+}