David Thornley 8 лет назад
Родитель
Сommit
30fa0b9471
7 измененных файлов: 325 добавлений и 95 удалений
  1. 34
    0
      AccountTest.java
  2. 77
    0
      CalendarTest.java
  3. 39
    0
      DateTest.java
  4. 38
    0
      DepositAccountTest.java
  5. 25
    0
      UseIO.java
  6. 0
    31
      UsesTextIO.java
  7. 112
    64
      package.bluej

+ 34
- 0
AccountTest.java Просмотреть файл

@@ -36,4 +36,38 @@ public class AccountTest
36 36
      //Assert:
37 37
      assertEquals(expected, actual);
38 38
     }
39
+    
40
+    @Test
41
+    public void depositTest(){
42
+    //Given:
43
+    Account test = new Account(100);
44
+    test.deposit(100);
45
+    //Then:
46
+    int expected = 200;
47
+    int actual = test.balance();
48
+    //Assert
49
+    assertEquals(expected,actual);
50
+    
51
+    }
52
+    
53
+    @Test
54
+    public void openTest() {
55
+    //Given
56
+    Account test = new Account(100);
57
+    //Then:
58
+    Account answer = test.open(90);
59
+    //Assert
60
+    assertTrue(answer.balance() == 90);
61
+    
62
+    }
63
+    
64
+    @Test
65
+    public void withdrawTest(){
66
+    test.deposit(1000);
67
+    try{test.withdraw(800);}
68
+    catch(AccountException ae){};
69
+    int expected = 200;
70
+    int actual = test.balance();
71
+    assertEquals(expected,actual);
72
+    }
39 73
 }

+ 77
- 0
CalendarTest.java Просмотреть файл

@@ -0,0 +1,77 @@
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 CalendarTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class CalendarTest
15
+{
16
+    Calendar test;
17
+    
18
+    @Test
19
+    public void addDayTest() {
20
+    try{test = new Calendar(8,2,1985);}
21
+    catch(DateException de){};
22
+    
23
+    test.addDay();
24
+    assertTrue(test.day == 9);
25
+    
26
+    }
27
+    
28
+     @Test
29
+    public void subDayTest() {
30
+    try{test = new Calendar(8,2,1985);}
31
+    catch(DateException de){};
32
+    
33
+    test.subDay();
34
+    assertTrue(test.day == 7);
35
+    
36
+    }
37
+    
38
+    @Test
39
+    public void addMonthTest() {
40
+    try{test = new Calendar(8,2,1985);}
41
+    catch(DateException de){};
42
+    
43
+    test.addMonth();
44
+    assertTrue(test.month == 3);
45
+    
46
+    }
47
+    
48
+     @Test
49
+    public void subMonthTest() {
50
+    try{test = new Calendar(8,2,1985);}
51
+    catch(DateException de){};
52
+    
53
+    test.subMonth();
54
+    assertTrue(test.month == 1);
55
+    
56
+    }
57
+    
58
+     @Test
59
+    public void addyearTest() {
60
+    try{test = new Calendar(8,2,1985);}
61
+    catch(DateException de){};
62
+    
63
+    test.addYear();
64
+    assertTrue(test.year == 1986);
65
+    
66
+    }
67
+    
68
+      @Test
69
+    public void subyearTest() {
70
+    try{test = new Calendar(8,2,1985);}
71
+    catch(DateException de){};
72
+    
73
+    test.subYear();
74
+    assertTrue(test.year == 1984);
75
+    
76
+    }
77
+}

+ 39
- 0
DateTest.java Просмотреть файл

@@ -0,0 +1,39 @@
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 DateTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class DateTest
15
+{
16
+    Date test;
17
+    Date d;
18
+    @Test
19
+    public void toStringTest() {
20
+    try{test = new Date(8,2,1985);}
21
+    catch(DateException de){};
22
+    
23
+    
24
+    String expected = "8/2/1985";
25
+    String actual = test.toString();
26
+    assertEquals(expected,actual);
27
+}
28
+
29
+@Test
30
+public void lessThanTest(){
31
+    try{test = new Date(8,2,1985);}
32
+    catch(DateException de){};
33
+    
34
+    try{d = new Date(9,2,1985);}
35
+    catch(DateException de){};
36
+    
37
+    assertTrue(test.lessThan(d));
38
+}
39
+}

+ 38
- 0
DepositAccountTest.java Просмотреть файл

@@ -0,0 +1,38 @@
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 DepositAccountTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class DepositAccountTest
15
+{
16
+   @Test
17
+   public void withdrawTest(){
18
+    DepositAccount test = new DepositAccount(1000, 0.1D);
19
+    try{test.withdraw(100);}
20
+    catch(AccountException ae){};
21
+    assertTrue(test.balance() == 900);
22
+    }
23
+    
24
+    @Test
25
+    public void updateTest(){
26
+    DepositAccount test = new DepositAccount(1000, 0.1D);
27
+    test.update();
28
+    assertTrue(test.balance() == 1100);
29
+    }
30
+    
31
+    @Test
32
+    public void setIntrestTest(){
33
+    DepositAccount test = new DepositAccount(1000, 0.1D);
34
+    test.setInterest(0.05D);
35
+    test.update();
36
+    assertTrue(test.balance() == 1050);
37
+    }
38
+}

+ 25
- 0
UseIO.java Просмотреть файл

@@ -0,0 +1,25 @@
1
+
2
+/**
3
+ * Write a description of class UseIO here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class UseIO
9
+{
10
+    // instance variables - replace the example below with your own
11
+    TextIO test = new TextIO();
12
+
13
+    public UseIO(){};
14
+    
15
+    public String lazyWriteDouble(double number, int align, int frac){
16
+    return test.writeDouble(number,align,frac);
17
+    }
18
+    
19
+    public String lazyWriteInt(int number, int align){
20
+    return test.writeInt(number,align);
21
+    }
22
+    
23
+    
24
+    
25
+}

+ 0
- 31
UsesTextIO.java Просмотреть файл

@@ -1,31 +0,0 @@
1
-
2
-/**
3
- * Write a description of class UsesTextIO here.
4
- *
5
- * @author (your name)
6
- * @version (a version number or a date)
7
- */
8
-public class UsesTextIO
9
-{
10
-    TextIO text = new TextIO();
11
-    
12
-    /**
13
-     * Constructor for objects of class UsesTextIO
14
-     */
15
-    public UsesTextIO(TextIO t)
16
-    {
17
-        // initialise instance variables
18
-        text = t;
19
-    }
20
-    
21
-    
22
-    
23
-    
24
-    
25
-    public double readDouble(double d){
26
-    return text.readDouble(text.open(("d")));
27
-    }
28
-    
29
-
30
-   
31
-}

+ 112
- 64
package.bluej Просмотреть файл

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