jpsp91 8 lat temu
rodzic
commit
db985dd046
9 zmienionych plików z 353 dodań i 102 usunięć
  1. 54
    0
      AccountTest.java
  2. 27
    0
      DateTest.java
  3. 32
    32
      Scrabble.java
  4. 50
    0
      ScrabbleTest.java
  5. 13
    12
      Squares.java
  6. 28
    0
      SquaresTest.java
  7. 4
    3
      TriangleOne.java
  8. 29
    0
      TriangleOneTest.java
  9. 116
    55
      package.bluej

+ 54
- 0
AccountTest.java Wyświetl plik

@@ -0,0 +1,54 @@
1
+import org.junit.Assert;
2
+import org.junit.After;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+public class AccountTest
7
+{
8
+    Account act = new Account();
9
+
10
+    @Test
11
+    public void transferTest(){
12
+        //when
13
+        //act.Account = 500;
14
+        //expected
15
+        //boolean expected;
16
+        //actual
17
+        //boolean actual = act.transfer(500, 50);
18
+
19
+        //Assert.assertEquals(expected, actual);
20
+    }
21
+
22
+    @Test
23
+    public void openTest(){
24
+        // //expected
25
+
26
+        // //actual
27
+
28
+        // Assert.assertEquals(expected, actual);
29
+    }
30
+
31
+    @Test
32
+    public void balanceTest(){
33
+        //expected
34
+        int expected = 500;
35
+        //actual
36
+        int actual = act.balance();
37
+        Assert.assertEquals(expected, actual);
38
+    }
39
+
40
+    @Test
41
+    public void withdrawTest(){
42
+        // //when
43
+        // int sum = 50;
44
+        // int amount = 500;
45
+
46
+        // //expected
47
+        // int expected = 450;
48
+        // //actual
49
+        // int actual = act.withdraw(sum);
50
+
51
+        // Assert.assertEquals(expected, actual);
52
+    }
53
+
54
+}

+ 27
- 0
DateTest.java Wyświetl plik

@@ -0,0 +1,27 @@
1
+import org.junit.Assert;
2
+import org.junit.After;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+import org.junit.Assert;
6
+
7
+public class DateTest
8
+{
9
+    @Test
10
+    public void toStringTest(){
11
+        //when
12
+        int day = 27;
13
+        int month = 6;
14
+        int year = 2018;
15
+        
16
+        //expected
17
+        String expected = "27/6/2018";
18
+        
19
+        //actual
20
+        // Date date = new Date(int day, int month, int year);
21
+        
22
+        // String actual = date.toString();
23
+        
24
+        //Assert.assertEquals(expected, actual);
25
+        
26
+    }
27
+}

+ 32
- 32
Scrabble.java Wyświetl plik

@@ -2,39 +2,39 @@ import java.io.*;
2 2
 
3 3
 class Scrabble
4 4
 {
5
-// A class to give you the scrabble score of a word
5
+    // A class to give you the scrabble score of a word
6 6
 
7
- public static void main(String[] args) throws IOException
8
- {
9
-  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
10
-  System.out.print("Enter a word: ");
11
-  String word=in.readLine();
12
-  System.out.println("Scrabble score is: "+score(word));
13
- }
7
+    public static void main(String[] args) throws IOException
8
+    {
9
+        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
10
+        System.out.print("Enter a word: ");
11
+        String word=in.readLine();
12
+        System.out.println("Scrabble score is: "+score(word));
13
+    }
14 14
 
15
- public static int score(String word)
16
- {
17
-  String uword=word.toUpperCase();
18
-  int score=0;
19
-  for(int i=0;i<uword.length();i++)
20
-     switch(uword.charAt(i))
21
-       {
22
-        case 'Q': case 'Z':
23
-          score+=10; break;
24
-        case 'J': case 'X':
25
-          score+=8; break;
26
-        case 'K':
27
-          score+=5; break;
28
-        case 'F': case 'H': case 'V': case 'W': case 'Y':
29
-          score+=4; break;
30
-        case 'B': case 'C': case 'M': case 'P':
31
-          score+=3; break;
32
-        case 'D': case 'G':
33
-          score+=2;break;
34
-        default:
35
-          score+=1;break;
36
-      } 
37
-  return score;
38
- }
15
+    public static int score(String word)
16
+    {
17
+        String uword=word.toUpperCase();
18
+        int score=0;
19
+        for(int i=0;i<uword.length();i++)
20
+            switch(uword.charAt(i))
21
+            {
22
+                case 'Q': case 'Z':
23
+                score+=10; break;
24
+                case 'J': case 'X':
25
+                score+=8; break;
26
+                case 'K':
27
+                score+=5; break;
28
+                case 'F': case 'H': case 'V': case 'W': case 'Y':
29
+                score+=4; break;
30
+                case 'B': case 'C': case 'M': case 'P':
31
+                score+=3; break;
32
+                case 'D': case 'G':
33
+                score+=2;break;
34
+                default:
35
+                score+=1;break;
36
+            } 
37
+        return score;
38
+    }
39 39
 
40 40
 }

+ 50
- 0
ScrabbleTest.java Wyświetl plik

@@ -0,0 +1,50 @@
1
+import static org.junit.Assert.*;
2
+import org.junit.After;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+
6
+
7
+public class ScrabbleTest
8
+{
9
+    private Scrabble game;
10
+    
11
+    @Before
12
+    public void setUp(){
13
+        game = new Scrabble();
14
+    }
15
+    
16
+    @Test
17
+    public void ScrabbleTestFizz()
18
+    {
19
+        //Given
20
+        int expected = 25;
21
+
22
+        //When
23
+        int actual = game.score("fizz");
24
+        
25
+
26
+        //Then
27
+        assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void ScrabbleTestBuzz()
32
+    {
33
+        //Given
34
+        int expected = 24;
35
+
36
+        //When
37
+        int actual = game.score("buzz");
38
+        
39
+
40
+        //Then
41
+        assertEquals(expected, actual);
42
+    }
43
+    
44
+
45
+    
46
+    @After
47
+    public void tearDown()
48
+    {
49
+    }
50
+}

+ 13
- 12
Squares.java Wyświetl plik

@@ -1,16 +1,17 @@
1 1
 class Squares
2 2
 {
3
-// Print all square numbers up to a fixed limit
3
+    // Print all square numbers up to a fixed limit
4 4
 
5
- static final int LIMIT=150;
5
+    static final int LIMIT=150;
6
+
7
+    public void display(int limit)
8
+    {
9
+        int i;
10
+        for(i=1;i*i<limit;i++)
11
+        {
12
+            System.out.print("The square of "+i);
13
+            System.out.println(" is "+i*i);
14
+        }
15
+    }
16
+}
6 17
 
7
- public void display(int limit)
8
- {
9
-  int i;
10
-  for(i=1;i*i<limit;i++)
11
-     {
12
-      System.out.print("The square of "+i);
13
-      System.out.println(" is "+i*i);
14
-     }
15
- }
16
-}

+ 28
- 0
SquaresTest.java Wyświetl plik

@@ -0,0 +1,28 @@
1
+import org.junit.Assert;
2
+import org.junit.After;
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+import org.junit.Assert;
6
+
7
+public class SquaresTest
8
+{
9
+    @Before
10
+    public void setUp(){
11
+        Squares sq = new Squares();
12
+    }
13
+    
14
+    @Test
15
+    public void squareTest(){
16
+        Squares sq = new Squares();
17
+        
18
+        //expected
19
+        int expected = 25;
20
+        
21
+        //actual
22
+         //int actual = sq.display(5);
23
+        
24
+         //Assert.assertEquals(expected, actual);
25
+        
26
+    }
27
+    
28
+}

+ 4
- 3
TriangleOne.java Wyświetl plik

@@ -1,9 +1,9 @@
1 1
 class TriangleOne
2 2
 {
3 3
     //   Print a bottom-left right-angled triangle of stars, of size SIZE
4
-
4
+    
5 5
     static final int SIZE=5;
6
-
6
+    
7 7
     public void display() 
8 8
     {
9 9
         this.display(SIZE);
@@ -17,6 +17,7 @@ class TriangleOne
17 17
                 System.out.print("*");
18 18
             System.out.println();
19 19
         }
20
+        
20 21
     }
21
-
22
+    
22 23
 }

+ 29
- 0
TriangleOneTest.java Wyświetl plik

@@ -0,0 +1,29 @@
1
+
2
+import static org.junit.Assert.*;
3
+import org.junit.After;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+public class TriangleOneTest
8
+{
9
+    
10
+    private TriangleOne star;
11
+    
12
+    @Before
13
+    public void setUp(){
14
+        star = new TriangleOne();
15
+    }
16
+    
17
+    // @Test
18
+    public void triangleTest1(){
19
+        //Given
20
+        //int expected = 25;
21
+
22
+        //When
23
+        //int actual = game.score();
24
+        
25
+        //Then
26
+        //assertEquals(expected, actual);
27
+        
28
+    }
29
+}

+ 116
- 55
package.bluej Wyświetl plik

@@ -1,26 +1,50 @@
1 1
 #BlueJ package file
2
-dependency1.from=Account
3
-dependency1.to=AccountException
2
+dependency1.from=Calendar1
3
+dependency1.to=CalendarGraphic
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=DepositAccount
6
-dependency2.to=AccountException
5
+dependency10.from=AccountTest
6
+dependency10.to=Account
7
+dependency10.type=UsesDependency
8
+dependency2.from=Calendar1
9
+dependency2.to=DateException
7 10
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
11
+dependency3.from=Calendar
12
+dependency3.to=DateException
13
+dependency3.type=UsesDependency
14
+dependency4.from=Date
15
+dependency4.to=DateException
16
+dependency4.type=UsesDependency
17
+dependency5.from=DepositAccount
18
+dependency5.to=AccountException
19
+dependency5.type=UsesDependency
20
+dependency6.from=ScrabbleTest
21
+dependency6.to=Scrabble
22
+dependency6.type=UsesDependency
23
+dependency7.from=Account
24
+dependency7.to=AccountException
25
+dependency7.type=UsesDependency
26
+dependency8.from=SquaresTest
27
+dependency8.to=Squares
28
+dependency8.type=UsesDependency
29
+dependency9.from=TriangleOneTest
30
+dependency9.to=TriangleOne
31
+dependency9.type=UsesDependency
32
+editor.fx.0.height=721
9 33
 editor.fx.0.width=800
10
-editor.fx.0.x=114
11
-editor.fx.0.y=175
12
-objectbench.height=101
34
+editor.fx.0.x=294
35
+editor.fx.0.y=23
36
+objectbench.height=179
13 37
 objectbench.width=461
14 38
 package.divider.horizontal=0.6
15
-package.divider.vertical=0.8007380073800738
16
-package.editor.height=427
39
+package.divider.vertical=0.6990291262135923
40
+package.editor.height=425
17 41
 package.editor.width=674
18
-package.editor.x=1006
19
-package.editor.y=133
20
-package.frame.height=600
42
+package.editor.x=235
43
+package.editor.y=23
44
+package.frame.height=676
21 45
 package.frame.width=800
22
-package.numDependencies=2
23
-package.numTargets=13
46
+package.numDependencies=10
47
+package.numTargets=18
24 48
 package.showExtends=true
25 49
 package.showUses=true
26 50
 project.charset=UTF-8
@@ -37,54 +61,90 @@ target1.width=130
37 61
 target1.x=450
38 62
 target1.y=190
39 63
 target10.height=50
40
-target10.name=Scrabble
64
+target10.name=ScrabbleTest
41 65
 target10.showInterface=false
42
-target10.type=ClassTarget
66
+target10.type=UnitTestTargetJunit4
43 67
 target10.width=80
44
-target10.x=10
45
-target10.y=250
68
+target10.x=40
69
+target10.y=220
70
+target11.association=ScrabbleTest
46 71
 target11.height=50
47
-target11.name=TriangleTwo
72
+target11.name=Scrabble
48 73
 target11.showInterface=false
49 74
 target11.type=ClassTarget
50
-target11.width=100
51
-target11.x=120
52
-target11.y=310
75
+target11.width=80
76
+target11.x=10
77
+target11.y=250
53 78
 target12.height=50
54
-target12.name=AccountException
79
+target12.name=DepositAccount
55 80
 target12.showInterface=false
56 81
 target12.type=ClassTarget
57
-target12.width=140
58
-target12.x=190
59
-target12.y=30
82
+target12.width=120
83
+target12.x=170
84
+target12.y=120
60 85
 target13.height=50
61
-target13.name=DateException
86
+target13.name=TriangleTwo
62 87
 target13.showInterface=false
63 88
 target13.type=ClassTarget
64
-target13.width=120
65
-target13.x=470
66
-target13.y=340
89
+target13.width=100
90
+target13.x=220
91
+target13.y=350
92
+target14.height=50
93
+target14.name=AccountException
94
+target14.showInterface=false
95
+target14.type=ClassTarget
96
+target14.width=140
97
+target14.x=190
98
+target14.y=30
99
+target15.height=50
100
+target15.name=DateTest
101
+target15.showInterface=false
102
+target15.type=UnitTestTargetJunit4
103
+target15.width=80
104
+target15.x=360
105
+target15.y=350
106
+target16.height=50
107
+target16.name=AccountTest
108
+target16.showInterface=false
109
+target16.type=UnitTestTargetJunit4
110
+target16.width=100
111
+target16.x=60
112
+target16.y=70
113
+target17.height=50
114
+target17.name=DateException
115
+target17.showInterface=false
116
+target17.type=ClassTarget
117
+target17.width=120
118
+target17.x=470
119
+target17.y=340
120
+target18.height=50
121
+target18.name=TriangleOneTest
122
+target18.showInterface=false
123
+target18.type=UnitTestTargetJunit4
124
+target18.width=100
125
+target18.x=60
126
+target18.y=320
67 127
 target2.height=50
68
-target2.name=Account
128
+target2.name=Calendar1
69 129
 target2.showInterface=false
70 130
 target2.type=ClassTarget
71
-target2.width=80
72
-target2.x=50
73
-target2.y=110
131
+target2.width=90
132
+target2.x=330
133
+target2.y=220
74 134
 target3.height=50
75
-target3.name=Calendar1
135
+target3.name=Account
76 136
 target3.showInterface=false
77 137
 target3.type=ClassTarget
78
-target3.width=90
79
-target3.x=330
80
-target3.y=220
138
+target3.width=80
139
+target3.x=20
140
+target3.y=130
81 141
 target4.height=50
82 142
 target4.name=Squares
83 143
 target4.showInterface=false
84 144
 target4.type=ClassTarget
85 145
 target4.width=80
86
-target4.x=100
87
-target4.y=250
146
+target4.x=170
147
+target4.y=280
88 148
 target5.height=50
89 149
 target5.name=Calendar
90 150
 target5.showInterface=false
@@ -92,31 +152,32 @@ target5.type=ClassTarget
92 152
 target5.width=80
93 153
 target5.x=490
94 154
 target5.y=270
155
+target6.association=TriangleOneTest
95 156
 target6.height=50
96 157
 target6.name=TriangleOne
97 158
 target6.showInterface=false
98 159
 target6.type=ClassTarget
99 160
 target6.width=100
100
-target6.x=10
101
-target6.y=310
161
+target6.x=30
162
+target6.y=350
102 163
 target7.height=50
103
-target7.name=TextIO
164
+target7.name=SquaresTest
104 165
 target7.showInterface=false
105
-target7.type=ClassTarget
106
-target7.width=80
107
-target7.x=490
108
-target7.y=40
166
+target7.type=UnitTestTargetJunit4
167
+target7.width=100
168
+target7.x=190
169
+target7.y=230
109 170
 target8.height=50
110
-target8.name=Date
171
+target8.name=TextIO
111 172
 target8.showInterface=false
112 173
 target8.type=ClassTarget
113 174
 target8.width=80
114
-target8.x=350
115
-target8.y=290
175
+target8.x=580
176
+target8.y=10
116 177
 target9.height=50
117
-target9.name=DepositAccount
178
+target9.name=Date
118 179
 target9.showInterface=false
119 180
 target9.type=ClassTarget
120
-target9.width=120
121
-target9.x=170
122
-target9.y=120
181
+target9.width=80
182
+target9.x=350
183
+target9.y=290