Pārlūkot izejas kodu

added test classes and absolute value

Michelle DiMarino 6 gadus atpakaļ
vecāks
revīzija
c23491b360
3 mainītis faili ar 150 papildinājumiem un 58 dzēšanām
  1. 5
    6
      RealAdvanced.java
  2. 82
    0
      RealAdvancedTest.java
  3. 63
    52
      package.bluej

+ 5
- 6
RealAdvanced.java Parādīt failu

@@ -18,30 +18,29 @@ public class RealAdvanced
18 18
             "2: x^y" + "\n"+
19 19
             "3: 1/x" + "\n"+
20 20
             "4: Switch Sign of x" + "\n"+
21
-            "5: Return to Main Menu");
21
+            "5: Absolute Value of x" + "\n"+
22
+            "6: Return to Main Menu");
22 23
 
23 24
     }
24 25
     // method to find x^2
25 26
     public double squared(double x){
26
-
27 27
         return Math.pow(x,2);
28 28
     }
29 29
     // method to find x^y
30 30
     public double exponent(double x, double y){
31
-
32 31
         return Math.pow(x,y);
33 32
     }
34 33
     // method to find the inverse of x
35 34
     public double inverse(double x){
36
-
37 35
         return 1/x;
38 36
     }
39 37
     // method to switch sign of x
40 38
     public double opposite(double x){
41
-
42 39
         double opposite1 = -1 * x;
43
-
44 40
         return opposite1;
45 41
     }
42
+    public double absoluteValue(double x){
43
+        return Math.abs(x);
44
+    }
46 45
 
47 46
 }

+ 82
- 0
RealAdvancedTest.java Parādīt failu

@@ -0,0 +1,82 @@
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 RealAdvancedTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class RealAdvancedTest
15
+{
16
+    /**
17
+     * Default constructor for test class RealAdvancedTest
18
+     */
19
+    public RealAdvancedTest()
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 squaredTest()
45
+    {
46
+        RealAdvanced realAdva1 = new RealAdvanced();
47
+        assertEquals(9.0, realAdva1.squared(3), 0.1);
48
+    }
49
+
50
+    @Test
51
+    public void exponentTest()
52
+    {
53
+        RealAdvanced realAdva1 = new RealAdvanced();
54
+        assertEquals(8.0, realAdva1.exponent(2, 3), 0.1);
55
+    }
56
+
57
+    @Test
58
+    public void oppositeTest()
59
+    {
60
+        RealAdvanced realAdva1 = new RealAdvanced();
61
+        assertEquals(2.0, realAdva1.opposite(-2), 0.1);
62
+    }
63
+
64
+    @Test
65
+    public void inverseTest()
66
+    {
67
+        RealAdvanced realAdva1 = new RealAdvanced();
68
+        assertEquals(0.5, realAdva1.inverse(2), 0.1);
69
+    }
70
+
71
+    @Test
72
+    public void absoluteTest()
73
+    {
74
+        RealAdvanced realAdva1 = new RealAdvanced();
75
+        assertEquals(4.0, realAdva1.absoluteValue(-4), 0.1);
76
+    }
77
+}
78
+
79
+
80
+
81
+
82
+

+ 63
- 52
package.bluej Parādīt failu

@@ -1,65 +1,68 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainMenu
2
+dependency1.from=Basic
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5
-dependency10.from=Console
6
-dependency10.to=Basic
5
+dependency10.from=MemoryFunc
6
+dependency10.to=Console
7 7
 dependency10.type=UsesDependency
8
-dependency11.from=Console
9
-dependency11.to=RealAdvanced
8
+dependency11.from=Trig
9
+dependency11.to=Console
10 10
 dependency11.type=UsesDependency
11
-dependency12.from=Console
12
-dependency12.to=SciCalc
11
+dependency12.from=SwitchDisplay
12
+dependency12.to=Console
13 13
 dependency12.type=UsesDependency
14
-dependency13.from=Console
15
-dependency13.to=MemoryFunc
14
+dependency13.from=MainMenu
15
+dependency13.to=Console
16 16
 dependency13.type=UsesDependency
17
-dependency14.from=Console
18
-dependency14.to=SwitchDisplay
17
+dependency14.from=MainApplication
18
+dependency14.to=Console
19 19
 dependency14.type=UsesDependency
20
-dependency15.from=Console
21
-dependency15.to=Trig
20
+dependency15.from=RealAdvanced
21
+dependency15.to=Console
22 22
 dependency15.type=UsesDependency
23
+dependency16.from=RealAdvancedTest
24
+dependency16.to=RealAdvanced
25
+dependency16.type=UsesDependency
23 26
 dependency2.from=SciCalc
24 27
 dependency2.to=Console
25 28
 dependency2.type=UsesDependency
26
-dependency3.from=MainApplication
27
-dependency3.to=Console
29
+dependency3.from=Console
30
+dependency3.to=MainMenu
28 31
 dependency3.type=UsesDependency
29
-dependency4.from=MemoryFunc
30
-dependency4.to=Console
32
+dependency4.from=Console
33
+dependency4.to=Basic
31 34
 dependency4.type=UsesDependency
32
-dependency5.from=SwitchDisplay
33
-dependency5.to=Console
35
+dependency5.from=Console
36
+dependency5.to=RealAdvanced
34 37
 dependency5.type=UsesDependency
35
-dependency6.from=Trig
36
-dependency6.to=Console
38
+dependency6.from=Console
39
+dependency6.to=SciCalc
37 40
 dependency6.type=UsesDependency
38
-dependency7.from=Basic
39
-dependency7.to=Console
41
+dependency7.from=Console
42
+dependency7.to=MemoryFunc
40 43
 dependency7.type=UsesDependency
41
-dependency8.from=RealAdvanced
42
-dependency8.to=Console
44
+dependency8.from=Console
45
+dependency8.to=SwitchDisplay
43 46
 dependency8.type=UsesDependency
44 47
 dependency9.from=Console
45
-dependency9.to=MainMenu
48
+dependency9.to=Trig
46 49
 dependency9.type=UsesDependency
47
-editor.fx.0.height=749
50
+editor.fx.0.height=709
48 51
 editor.fx.0.width=1215
49
-editor.fx.0.x=145
50
-editor.fx.0.y=74
51
-objectbench.height=214
52
+editor.fx.0.x=65
53
+editor.fx.0.y=23
54
+objectbench.height=198
52 55
 objectbench.width=595
53 56
 package.divider.horizontal=0.6
54
-package.divider.vertical=0.6847360912981455
55
-package.editor.height=473
57
+package.divider.vertical=0.685099846390169
58
+package.editor.height=439
56 59
 package.editor.width=493
57 60
 package.editor.x=35
58
-package.editor.y=59
59
-package.frame.height=759
61
+package.editor.y=23
62
+package.frame.height=709
60 63
 package.frame.width=619
61
-package.numDependencies=15
62
-package.numTargets=9
64
+package.numDependencies=16
65
+package.numTargets=10
63 66
 package.showExtends=true
64 67
 package.showUses=true
65 68
 project.charset=UTF-8
@@ -75,6 +78,13 @@ target1.type=ClassTarget
75 78
 target1.width=80
76 79
 target1.x=320
77 80
 target1.y=180
81
+target10.height=50
82
+target10.name=MainApplication
83
+target10.showInterface=false
84
+target10.type=ClassTarget
85
+target10.width=120
86
+target10.x=70
87
+target10.y=70
78 88
 target2.height=50
79 89
 target2.name=SciCalc
80 90
 target2.showInterface=false
@@ -82,6 +92,7 @@ target2.type=ClassTarget
82 92
 target2.width=80
83 93
 target2.x=10
84 94
 target2.y=280
95
+target3.association=RealAdvancedTest
85 96
 target3.height=50
86 97
 target3.name=RealAdvanced
87 98
 target3.showInterface=false
@@ -90,19 +101,19 @@ target3.width=110
90 101
 target3.x=170
91 102
 target3.y=10
92 103
 target4.height=50
93
-target4.name=MemoryFunc
104
+target4.name=Console
94 105
 target4.showInterface=false
95 106
 target4.type=ClassTarget
96
-target4.width=110
97
-target4.x=210
98
-target4.y=350
107
+target4.width=80
108
+target4.x=70
109
+target4.y=170
99 110
 target5.height=50
100
-target5.name=Console
111
+target5.name=MemoryFunc
101 112
 target5.showInterface=false
102 113
 target5.type=ClassTarget
103
-target5.width=80
104
-target5.x=70
105
-target5.y=170
114
+target5.width=110
115
+target5.x=210
116
+target5.y=350
106 117
 target6.height=50
107 118
 target6.name=Trig
108 119
 target6.showInterface=false
@@ -118,16 +129,16 @@ target7.width=110
118 129
 target7.x=80
119 130
 target7.y=350
120 131
 target8.height=50
121
-target8.name=MainMenu
132
+target8.name=RealAdvancedTest
122 133
 target8.showInterface=false
123
-target8.type=ClassTarget
124
-target8.width=90
125
-target8.x=70
126
-target8.y=10
134
+target8.type=UnitTestTargetJunit4
135
+target8.width=110
136
+target8.x=200
137
+target8.y=-20
127 138
 target9.height=50
128
-target9.name=MainApplication
139
+target9.name=MainMenu
129 140
 target9.showInterface=false
130 141
 target9.type=ClassTarget
131
-target9.width=120
142
+target9.width=90
132 143
 target9.x=70
133
-target9.y=70
144
+target9.y=10