ソースを参照

Merge branch 'master' of WJB3003/ZCW-MacroLabs-OOP-ScientificCalculator into master

William Brown 6 年 前
コミット
6243ca6318
共有5 個のファイルを変更した232 個の追加14 個の削除を含む
  1. 1
    1
      Console.java
  2. 63
    0
      MemoryTest.java
  3. 4
    12
      opSwitchTest.java
  4. 4
    1
      simpleOp.java
  5. 160
    0
      simpleOpTest.java

+ 1
- 1
Console.java ファイルの表示

@@ -74,7 +74,7 @@ public class Console {
74 74
        if (input.matches(regexNum) || input.charAt(0) == '.' || input.equals("pi") || input.equals("e")) {
75 75
            getNumber(input);
76 76
         } else {
77
-            getOp(input);
77
+           getOp(input);
78 78
         }
79 79
     }
80 80
    

+ 63
- 0
MemoryTest.java ファイルの表示

@@ -0,0 +1,63 @@
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 MemoryTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class MemoryTest
15
+{
16
+    /**
17
+     * Default constructor for test class MemoryTest
18
+     */
19
+    public MemoryTest()
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 memoryTest1()
45
+    {
46
+        Memory.addMemory(100);
47
+    }
48
+
49
+    @Test
50
+    public void memoryTest2()
51
+    {
52
+        assertEquals(0.0, Memory.resetMemory(), 0.1);
53
+    }
54
+
55
+    @Test
56
+    public void MemoryTest3()
57
+    {
58
+        assertEquals(0.0, Memory.recallMemory(), 0.1);
59
+    }
60
+}
61
+
62
+
63
+

ConsoleTest.java → opSwitchTest.java ファイルの表示

@@ -6,17 +6,17 @@ import org.junit.Before;
6 6
 import org.junit.Test;
7 7
 
8 8
 /**
9
- * The test class ConsoleTest.
9
+ * The test class opSwitchTest.
10 10
  *
11 11
  * @author  (your name)
12 12
  * @version (a version number or a date)
13 13
  */
14
-public class ConsoleTest
14
+public class opSwitchTest
15 15
 {
16 16
     /**
17
-     * Default constructor for test class ConsoleTest
17
+     * Default constructor for test class opSwitchTest
18 18
      */
19
-    public ConsoleTest()
19
+    public opSwitchTest()
20 20
     {
21 21
     }
22 22
 
@@ -40,13 +40,5 @@ public class ConsoleTest
40 40
     {
41 41
     }
42 42
 
43
-
44
-    @Test
45
-    public void getStringInputTest()
46
-    {
47
-        assertEquals("This is a string", Console.getStringInput("Please enter a string"));
48
-    }
49 43
 }
50 44
 
51
-
52
-

+ 4
- 1
simpleOp.java ファイルの表示

@@ -40,7 +40,10 @@ public class simpleOp
40 40
     public static double div(double x, double y){
41 41
         //CALULATES THE QUOTIENT OF TWO NUMBERS
42 42
         Console.currentNumber = x / y;
43
-        //System.out.println(currentNumber);
43
+        if(y == 0){
44
+            System.out.println("Err");
45
+            Console.currentNumber = 0;
46
+        }
44 47
         return Console.currentNumber;
45 48
     }
46 49
     

+ 160
- 0
simpleOpTest.java ファイルの表示

@@ -0,0 +1,160 @@
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 simpleOpTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class simpleOpTest
15
+{
16
+    /**
17
+     * Default constructor for test class simpleOpTest
18
+     */
19
+    public simpleOpTest()
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 firstAddTest()
45
+    {
46
+        assertEquals(4.0, simpleOp.add(2, 2), 0.1);
47
+    }
48
+
49
+    @Test
50
+    public void secondAddTestNegative()
51
+    {
52
+        assertEquals(-8.0, simpleOp.add(-100, 92), 0.1);
53
+    }
54
+
55
+    @Test
56
+    public void firstSubtractTest()
57
+    {
58
+        assertEquals(13.0, simpleOp.sub(25, 12), 0.1);
59
+    }
60
+
61
+    @Test
62
+    public void secondSubtractTestNegative()
63
+    {
64
+        assertEquals(-8.0, simpleOp.sub(-100, -92), 0.1);
65
+    }
66
+
67
+    @Test
68
+    public void firstMultiplyTest()
69
+    {
70
+        assertEquals(0.0, simpleOp.mul(3, 0), 0.1);
71
+    }
72
+
73
+    @Test
74
+    public void secondMultiplyTestNegative()
75
+    {
76
+        assertEquals(125.0, simpleOp.mul(-25, -5), 0.1);
77
+    }
78
+
79
+
80
+    @Test
81
+    public void DivideTest2Negative()
82
+    {
83
+        assertEquals(20.0, simpleOp.div(100, 5), 0.1);
84
+    }
85
+
86
+    @Test
87
+    public void firstSquareTest()
88
+    {
89
+        assertEquals(25.0, simpleOp.squ(5), 0.1);
90
+    }
91
+
92
+    @Test
93
+    public void secondSquareTestNegative()
94
+    {
95
+        assertEquals(49.0, simpleOp.squ(-7), 0.1);
96
+    }
97
+
98
+    @Test
99
+    public void firstExponentTest()
100
+    {
101
+        assertEquals(125.0, simpleOp.exp(5, 3), 0.1);
102
+    }
103
+
104
+    @Test
105
+    public void SecondExponentTestNegative()
106
+    {
107
+        assertEquals(0.008, simpleOp.exp(5, -3), 0.1);
108
+    }
109
+
110
+    @Test
111
+    public void firstInverseTest()
112
+    {
113
+        assertEquals(0.01, simpleOp.inv(100), 0.1);
114
+    }
115
+    
116
+    @Test
117
+    public void secondInverseTest()
118
+    {
119
+        assertEquals(0.0002, simpleOp.inv(5000), 0.1);
120
+    }
121
+
122
+    @Test
123
+    public void divideByZero()
124
+    {
125
+        assertEquals(0.0, simpleOp.div(100, 0), 0.1);
126
+    }
127
+
128
+    @Test
129
+    public void firstInvertTest()
130
+    {
131
+        assertEquals(-237.0, simpleOp.invert(237), 0.1);
132
+    }
133
+
134
+    @Test
135
+    public void secondInvertTest()
136
+    {
137
+        assertEquals(253.0, simpleOp.invert(-253), 0.1);
138
+    }
139
+
140
+}
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+