Sfoglia il codice sorgente

ADDED TRIGFUNCTIONS CLASS#

shakila 6 anni fa
parent
commit
7d1ea52de1
3 ha cambiato i file con 199 aggiunte e 20 eliminazioni
  1. 65
    0
      TrigFunctions.java
  2. 79
    0
      TrigFunctionsTest.java
  3. 55
    20
      package.bluej

+ 65
- 0
TrigFunctions.java Vedi File

@@ -0,0 +1,65 @@
1
+
2
+/**
3
+ * Write a description of class TrigFunctions here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+import java.lang.Math;
9
+import java.util.Scanner;
10
+
11
+public class TrigFunctions
12
+{
13
+    // instance variables - replace the example below with your own
14
+   
15
+
16
+    /**
17
+     * Constructor for objects of class TrigFunctions
18
+     */
19
+    public TrigFunctions()
20
+    {
21
+        ;// initialise instance variables
22
+        ;
23
+    }
24
+
25
+    public double sin(int number){
26
+     double value = Math.sin(number);
27
+     return value;
28
+    }
29
+    
30
+    
31
+    public double cos(int number){
32
+        double value = Math.cos(number);
33
+        return value;
34
+    }
35
+    
36
+    public double tan(int number){
37
+        double value = Math.tan(number);
38
+        return value;   
39
+    }
40
+    
41
+    public double invsin(int number){
42
+        double value = Math.asin(number);
43
+        return value;
44
+    }
45
+    
46
+    public double invcos(int number){
47
+        double value = Math.acos(number);
48
+        return value;
49
+    }
50
+    
51
+    public double invtan(int number){
52
+        double value = Math.atan(number);
53
+        return value;   
54
+    }
55
+    
56
+    public double deg(int number){
57
+        double value = Math.toDegrees(number);
58
+        return value;
59
+    }
60
+    
61
+    public double rad(int number){
62
+        double value = Math.toRadians(number);
63
+        return value;   
64
+    }
65
+} //end Class TrigFunctions

+ 79
- 0
TrigFunctionsTest.java Vedi File

@@ -0,0 +1,79 @@
1
+
2
+import static org.junit.Assert.*;
3
+import org.junit.After;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+/**
8
+ * The test class TrigFunctionsTest.
9
+ *
10
+ * @author  (your name)
11
+ * @version (a version number or a date)
12
+ */
13
+public class TrigFunctionsTest
14
+{
15
+   @Test
16
+   public void sinTest(){
17
+       TrigFunctions trigFunctions = new TrigFunctions();
18
+       double expected = -0.95;
19
+       double actual = trigFunctions.sin(5);
20
+       assertEquals(expected,actual,0.01);
21
+       
22
+    }
23
+    
24
+   @Test
25
+   public void cosTest(){
26
+       TrigFunctions trigFunctions = new TrigFunctions();
27
+       double expected = 0.28;
28
+       double actual = trigFunctions.cos(5);
29
+       assertEquals(expected,actual, 0.01);
30
+    }
31
+    
32
+    @Test
33
+    public void tanTest(){
34
+      TrigFunctions trigFunctions = new TrigFunctions();
35
+      double expected = -3.38;
36
+      double actual = trigFunctions.tan(5);
37
+      assertEquals(expected,actual, 0.01);
38
+    }
39
+    
40
+   @Test
41
+   public void invsinTest(){
42
+     TrigFunctions trigFunctions = new TrigFunctions();
43
+     double expected = 1.57;
44
+     double actual = trigFunctions.invsin(1);
45
+     assertEquals(expected,actual, 0.01);
46
+    }
47
+    
48
+    @Test
49
+    public void invcosTest(){
50
+     TrigFunctions trigFunctions = new TrigFunctions();
51
+     double expected = 0;
52
+     double actual = trigFunctions.invcos(1);
53
+     assertEquals(expected,actual, 0.01);
54
+    }
55
+    
56
+    @Test
57
+    public void invtanTest(){
58
+     TrigFunctions trigFunctions = new TrigFunctions();
59
+     double expected = 0.79;
60
+     double actual = trigFunctions.invtan(1);
61
+     assertEquals(expected,actual, 0.01);
62
+    }
63
+    
64
+    @Test
65
+    public void degTest(){
66
+    TrigFunctions trigFunctions = new TrigFunctions();
67
+    double expected = 286.48;
68
+    double actual = trigFunctions.deg(5);
69
+    assertEquals(expected,actual, 0.01);
70
+    }
71
+    
72
+    @Test
73
+    public void radTest(){
74
+     TrigFunctions trigFunctions = new TrigFunctions();
75
+     double expected = 0.87;
76
+     double actual = trigFunctions.rad(50);
77
+     assertEquals(expected,actual, 0.01);
78
+    }
79
+}

+ 55
- 20
package.bluej Vedi File

@@ -1,10 +1,16 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
3
-dependency1.to=Console
2
+dependency1.from=BasicMathTest
3
+dependency1.to=BasicMath
4 4
 dependency1.type=UsesDependency
5
+dependency2.from=MainApplication
6
+dependency2.to=Console
7
+dependency2.type=UsesDependency
8
+dependency3.from=TrigFunctionsTest
9
+dependency3.to=TrigFunctions
10
+dependency3.type=UsesDependency
5 11
 editor.fx.0.height=722
6 12
 editor.fx.0.width=800
7
-editor.fx.0.x=480
13
+editor.fx.0.x=155
8 14
 editor.fx.0.y=23
9 15
 objectbench.height=202
10 16
 objectbench.width=352
@@ -16,8 +22,8 @@ package.editor.x=35
16 22
 package.editor.y=23
17 23
 package.frame.height=722
18 24
 package.frame.width=619
19
-package.numDependencies=1
20
-package.numTargets=3
25
+package.numDependencies=3
26
+package.numTargets=7
21 27
 package.showExtends=true
22 28
 package.showUses=true
23 29
 project.charset=UTF-8
@@ -27,24 +33,53 @@ readme.width=47
27 33
 readme.x=10
28 34
 readme.y=10
29 35
 target1.height=50
30
-target1.name=MainApplicationTest
36
+target1.name=BasicMath
31 37
 target1.showInterface=false
32
-target1.type=UnitTestTargetJunit4
33
-target1.width=120
34
-target1.x=100
35
-target1.y=40
38
+target1.type=ClassTarget
39
+target1.width=90
40
+target1.x=220
41
+target1.y=160
36 42
 target2.height=50
37
-target2.name=Console
43
+target2.name=MainApplicationTest
38 44
 target2.showInterface=false
39
-target2.type=ClassTarget
40
-target2.width=80
41
-target2.x=80
42
-target2.y=200
43
-target3.association=MainApplicationTest
45
+target2.type=UnitTestTargetJunit4
46
+target2.width=120
47
+target2.x=100
48
+target2.y=40
44 49
 target3.height=50
45
-target3.name=MainApplication
50
+target3.name=Console
46 51
 target3.showInterface=false
47 52
 target3.type=ClassTarget
48
-target3.width=120
49
-target3.x=70
50
-target3.y=70
53
+target3.width=80
54
+target3.x=80
55
+target3.y=200
56
+target4.association=TrigFunctionsTest
57
+target4.height=50
58
+target4.name=TrigFunctions
59
+target4.showInterface=false
60
+target4.type=ClassTarget
61
+target4.width=110
62
+target4.x=40
63
+target4.y=300
64
+target5.height=50
65
+target5.name=BasicMathTest
66
+target5.showInterface=false
67
+target5.type=UnitTestTargetJunit4
68
+target5.width=120
69
+target5.x=330
70
+target5.y=170
71
+target6.height=50
72
+target6.name=TrigFunctionsTest
73
+target6.showInterface=false
74
+target6.type=UnitTestTargetJunit4
75
+target6.width=110
76
+target6.x=70
77
+target6.y=270
78
+target7.association=MainApplicationTest
79
+target7.height=50
80
+target7.name=MainApplication
81
+target7.showInterface=false
82
+target7.type=ClassTarget
83
+target7.width=120
84
+target7.x=70
85
+target7.y=70