Bladeren bron

added some test cases and started fortune method

Margaret Pierse 6 jaren geleden
bovenliggende
commit
897a7e2243
3 gewijzigde bestanden met toevoegingen van 108 en 30 verwijderingen
  1. 8
    1
      MathMethods.java
  2. 70
    0
      MathMethodsTest.java
  3. 30
    29
      package.bluej

+ 8
- 1
MathMethods.java Bestand weergeven

@@ -52,6 +52,8 @@ public class MathMethods
52 52
 
53 53
     }
54 54
 
55
+    //**********************************************************
56
+    //Errors in iSin, returns NaN
55 57
     public static double iSin(double n1){
56 58
         return (Math.asin(n1));
57 59
 
@@ -67,7 +69,12 @@ public class MathMethods
67 69
 
68 70
     }
69 71
 
70
-    
72
+    public static String fortuneCookie() {
73
+     String[] wiseWords = new String[] {"You're a hard worker and you will do great on all the labs!", 
74
+         "Look how much java you learned this week! That's awesome!", "Keep up the good Work" ,
75
+        "Don't forget to talk to our visitors, they give us jobs!"};  
76
+        return "";
77
+    }
71 78
     
72 79
     public static void printAns(String printAnswer){
73 80
         System.out.println("ANSWER: " + printAnswer);

+ 70
- 0
MathMethodsTest.java Bestand weergeven

@@ -0,0 +1,70 @@
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 MathMethodsTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class MathMethodsTest
15
+{
16
+    /**
17
+     * Default constructor for test class MathMethodsTest
18
+     */
19
+    public MathMethodsTest()
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 testSquareRoot()
45
+    {
46
+        assertEquals(16.0, MathMethods.squareRoot(256), 0.1);
47
+    }
48
+
49
+    @Test
50
+    public void testInvertPositive()
51
+    {
52
+        assertEquals(-5.0, MathMethods.invert(5), 0.1);
53
+    }
54
+
55
+    @Test
56
+    public void testInvertNegative()
57
+    {
58
+        assertEquals(11.0, MathMethods.invert(-11), 0.1);
59
+    }
60
+
61
+    @Test
62
+    public void testSin()
63
+    {
64
+        assertEquals(-0.26237485370392877, MathMethods.sin(50), 0.1);
65
+    }
66
+}
67
+
68
+
69
+
70
+

+ 30
- 29
package.bluej Bestand weergeven

@@ -1,24 +1,24 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
3
-dependency1.to=Console
2
+dependency1.from=Calculator
3
+dependency1.to=MathMethods
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=Console
6
-dependency2.to=Calculator
5
+dependency2.from=MathMethodsTest
6
+dependency2.to=MathMethods
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=1020
9
-editor.fx.0.width=1247
10
-editor.fx.0.x=1891
11
-editor.fx.0.y=66
8
+editor.fx.0.height=0
9
+editor.fx.0.width=0
10
+editor.fx.0.x=0
11
+editor.fx.0.y=0
12 12
 objectbench.height=80
13
-objectbench.width=352
14
-package.divider.horizontal=0.5993322203672788
15
-package.divider.vertical=0.8465608465608465
16
-package.editor.height=473
17
-package.editor.width=493
18
-package.editor.x=1446
19
-package.editor.y=445
20
-package.frame.height=625
21
-package.frame.width=619
13
+objectbench.width=480
14
+package.divider.horizontal=0.5997536945812808
15
+package.divider.vertical=0.8838451268357811
16
+package.editor.height=655
17
+package.editor.width=706
18
+package.editor.x=10
19
+package.editor.y=23
20
+package.frame.height=807
21
+package.frame.width=832
22 22
 package.numDependencies=2
23 23
 package.numTargets=3
24 24
 package.showExtends=true
@@ -33,20 +33,21 @@ target1.height=50
33 33
 target1.name=Calculator
34 34
 target1.showInterface=false
35 35
 target1.type=ClassTarget
36
-target1.width=90
37
-target1.x=200
38
-target1.y=310
36
+target1.width=140
37
+target1.x=80
38
+target1.y=200
39 39
 target2.height=50
40
-target2.name=Console
40
+target2.name=MathMethodsTest
41 41
 target2.showInterface=false
42
-target2.type=ClassTarget
43
-target2.width=80
44
-target2.x=80
45
-target2.y=200
42
+target2.type=UnitTestTargetJunit4
43
+target2.width=110
44
+target2.x=230
45
+target2.y=280
46
+target3.association=MathMethodsTest
46 47
 target3.height=50
47
-target3.name=MainApplication
48
+target3.name=MathMethods
48 49
 target3.showInterface=false
49 50
 target3.type=ClassTarget
50
-target3.width=120
51
-target3.x=70
52
-target3.y=70
51
+target3.width=110
52
+target3.x=200
53
+target3.y=310