浏览代码

Test Classes added as well as making it so answer is not printed when dividing by 0

Lauren Green 6 年前
父节点
当前提交
598f39de3c
共有 3 个文件被更改,包括 239 次插入1 次删除
  1. 139
    0
      BasicTest.java
  2. 2
    1
      Console.java
  3. 98
    0
      TrigTest.java

+ 139
- 0
BasicTest.java 查看文件

@@ -0,0 +1,139 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class BasicTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class BasicTest
15
+{
16
+    /**
17
+     * Default constructor for test class BasicTest
18
+     */
19
+    public BasicTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+
43
+    @Test
44
+    public void testAdd()
45
+    {
46
+        Basic basic1 = new Basic();
47
+        assertEquals(14, basic1.getSum(4, 10), 0.1);
48
+    }
49
+
50
+    @Test
51
+    public void testAddDec()
52
+    {
53
+        Basic basic1 = new Basic();
54
+        assertEquals(13.27, basic1.getSum(13.2, 0.07), 0.1);
55
+    }
56
+
57
+    @Test
58
+    public void testAddNeg()
59
+    {
60
+        Basic basic1 = new Basic();
61
+        basic1.Basic();
62
+        assertEquals(6, basic1.getSum(-3, 9), 0.1);
63
+    }
64
+
65
+    @Test
66
+    public void testSub()
67
+    {
68
+        Basic basic1 = new Basic();
69
+        assertEquals(5, basic1.getDiff(10, 5), 0.1);
70
+    }
71
+
72
+    @Test
73
+    public void testSubDec()
74
+    {
75
+        Basic basic1 = new Basic();
76
+        assertEquals(4.65, basic1.getDiff(13.2, 8.55), 0.1);
77
+    }
78
+
79
+    @Test
80
+    public void testSubNeg()
81
+    {
82
+        Basic basic1 = new Basic();
83
+        assertEquals(18, basic1.getDiff(6, -12), 0.1);
84
+    }
85
+
86
+    @Test
87
+    public void testMul()
88
+    {
89
+        Basic basic1 = new Basic();
90
+        assertEquals(15, basic1.getProduct(3, 5), 0.1);
91
+    }
92
+
93
+    @Test
94
+    public void testMulDec()
95
+    {
96
+        Basic basic1 = new Basic();
97
+        assertEquals(6.8, basic1.getProduct(3.4, 2), 0.1);
98
+    }
99
+
100
+    @Test
101
+    public void testMulNeg()
102
+    {
103
+        Basic basic1 = new Basic();
104
+        assertEquals(10, basic1.getProduct(-2, -5), 0.1);
105
+    }
106
+
107
+    @Test
108
+    public void testDiv()
109
+    {
110
+        Basic basic1 = new Basic();
111
+        assertEquals(4, basic1.getQuotient(12, 3), 0.1);
112
+    }
113
+
114
+    @Test
115
+    public void testDivDec()
116
+    {
117
+        Basic basic1 = new Basic();
118
+        assertEquals(7.4, basic1.getQuotient(14.8, 2), 0.1);
119
+    }
120
+
121
+    @Test
122
+    public void testDivNeg()
123
+    {
124
+        Basic basic1 = new Basic();
125
+        assertEquals(-3, basic1.getQuotient(-12, 4), 0.1);
126
+    }
127
+}
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+

+ 2
- 1
Console.java 查看文件

@@ -72,8 +72,9 @@ public class Console {
72 72
                     basicAnswer = Double.NaN;
73 73
                     Console.println("Invalid Input");
74 74
                 }
75
+                if (basicMode.equals("4") && !(basicInput2 == 0)) {
75 76
                 Console.println(Double.toString(basicAnswer));
76
-
77
+            }
77 78
                 break;
78 79
                 case "2":
79 80
                 advCalc.realAdvanced();

+ 98
- 0
TrigTest.java 查看文件

@@ -0,0 +1,98 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class TrigTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class TrigTest
15
+{
16
+    /**
17
+     * Default constructor for test class TrigTest
18
+     */
19
+    public TrigTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+
43
+    @Test
44
+    public void testSIN()
45
+    {
46
+        Trig trig1 = new Trig();
47
+        assertEquals(-0.54402111088, trig1.calcSin(10), 0.1);
48
+    }
49
+
50
+    @Test
51
+    public void testCOS()
52
+    {
53
+        Trig trig1 = new Trig();
54
+        assertEquals(-0.83907152907, trig1.calcCos(10), 0.1);
55
+    }
56
+
57
+    @Test
58
+    public void testTAN()
59
+    {
60
+        Trig trig1 = new Trig();
61
+        assertEquals(0.64836082745, trig1.calcTan(10), 0.1);
62
+    }
63
+
64
+    @Test
65
+    public void testRadtoDeg()
66
+    {
67
+        Trig trig1 = new Trig();
68
+        assertEquals(37.14833901458697, trig1.toDegrees(0.64836082745), 0.1);
69
+    }
70
+
71
+    @Test
72
+    public void testArcSin()
73
+    {
74
+        Trig trig2 = new Trig();
75
+        assertEquals(0.523598776, trig2.calcArcsin(0.5), 0.1);
76
+    }
77
+
78
+    @Test
79
+    public void testArcTan()
80
+    {
81
+        Trig trig1 = new Trig();
82
+        assertEquals(0.463647609, trig1.calcArctan(0.5), 0.1);
83
+    }
84
+
85
+    @Test
86
+    public void testArcCos()
87
+    {
88
+        Trig trig1 = new Trig();
89
+        assertEquals(1.04719755, trig1.calcArccos(0.5), 0.1);
90
+    }
91
+}
92
+
93
+
94
+
95
+
96
+
97
+
98
+