Selaa lähdekoodia

bank-account: add ignore hint and improve HINTS.md

Frida Tveit 9 vuotta sitten
vanhempi
commit
86faec5d9b

+ 5
- 1
exercises/bank-account/HINTS.md Näytä tiedosto

4
 
4
 
5
 Problems arising from running code concurrently are often intermittent because they depend on the order the code is
5
 Problems arising from running code concurrently are often intermittent because they depend on the order the code is
6
 executed. Therefore the last test runs many [threads](https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html) 
6
 executed. Therefore the last test runs many [threads](https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html) 
7
-several times to increase the chances of catching a bug.
7
+several times to increase the chances of catching a bug. That means this test should fail if your implementation is not
8
+[thread safe](https://en.wikipedia.org/wiki/Thread_safety), but there is a chance it will pass just because there was 
9
+no concurrent modification attempt. It is unlikely that this will occur several times 
10
+in a row since the order the code is executed should vary every time you run the test. So if you run the last test a 
11
+couple of times and it passes every time then you can be reasonably sure that your implementation is correct.

+ 13
- 13
exercises/bank-account/src/test/java/BankAccountTest.java Näytä tiedosto

26
         assertEquals(0, bankAccount.getBalance());
26
         assertEquals(0, bankAccount.getBalance());
27
     }
27
     }
28
 
28
 
29
-    @Ignore
29
+    @Ignore("Remove to run test")
30
     @Test
30
     @Test
31
     public void canDepositMoney() throws BankAccountActionInvalidException {
31
     public void canDepositMoney() throws BankAccountActionInvalidException {
32
         bankAccount.open();
32
         bankAccount.open();
36
         assertEquals(10, bankAccount.getBalance());
36
         assertEquals(10, bankAccount.getBalance());
37
     }
37
     }
38
 
38
 
39
-    @Ignore
39
+    @Ignore("Remove to run test")
40
     @Test
40
     @Test
41
     public void canDepositMoneySequentially() throws BankAccountActionInvalidException {
41
     public void canDepositMoneySequentially() throws BankAccountActionInvalidException {
42
         bankAccount.open();
42
         bankAccount.open();
47
         assertEquals(28, bankAccount.getBalance());
47
         assertEquals(28, bankAccount.getBalance());
48
     }
48
     }
49
 
49
 
50
-    @Ignore
50
+    @Ignore("Remove to run test")
51
     @Test
51
     @Test
52
     public void canWithdrawMoney() throws BankAccountActionInvalidException {
52
     public void canWithdrawMoney() throws BankAccountActionInvalidException {
53
         bankAccount.open();
53
         bankAccount.open();
58
         assertEquals(5, bankAccount.getBalance());
58
         assertEquals(5, bankAccount.getBalance());
59
     }
59
     }
60
 
60
 
61
-    @Ignore
61
+    @Ignore("Remove to run test")
62
     @Test
62
     @Test
63
     public void canWithdrawMoneySequentially() throws BankAccountActionInvalidException {
63
     public void canWithdrawMoneySequentially() throws BankAccountActionInvalidException {
64
         bankAccount.open();
64
         bankAccount.open();
70
         assertEquals(0, bankAccount.getBalance());
70
         assertEquals(0, bankAccount.getBalance());
71
     }
71
     }
72
 
72
 
73
-    @Ignore
73
+    @Ignore("Remove to run test")
74
     @Test
74
     @Test
75
     public void cannotWithdrawMoneyFromEmptyAccount() throws BankAccountActionInvalidException {
75
     public void cannotWithdrawMoneyFromEmptyAccount() throws BankAccountActionInvalidException {
76
         bankAccount.open();
76
         bankAccount.open();
81
         bankAccount.withdraw(5);
81
         bankAccount.withdraw(5);
82
     }
82
     }
83
 
83
 
84
-    @Ignore
84
+    @Ignore("Remove to run test")
85
     @Test
85
     @Test
86
     public void cannotWithdrawMoreMoneyThanYouHave() throws BankAccountActionInvalidException {
86
     public void cannotWithdrawMoreMoneyThanYouHave() throws BankAccountActionInvalidException {
87
         bankAccount.open();
87
         bankAccount.open();
93
         bankAccount.withdraw(7);
93
         bankAccount.withdraw(7);
94
     }
94
     }
95
 
95
 
96
-    @Ignore
96
+    @Ignore("Remove to run test")
97
     @Test
97
     @Test
98
     public void cannotDepositNegativeAmount() throws BankAccountActionInvalidException {
98
     public void cannotDepositNegativeAmount() throws BankAccountActionInvalidException {
99
         bankAccount.open();
99
         bankAccount.open();
104
         bankAccount.deposit(-1);
104
         bankAccount.deposit(-1);
105
     }
105
     }
106
 
106
 
107
-    @Ignore
107
+    @Ignore("Remove to run test")
108
     @Test
108
     @Test
109
     public void cannotWithdrawNegativeAmount() throws BankAccountActionInvalidException {
109
     public void cannotWithdrawNegativeAmount() throws BankAccountActionInvalidException {
110
         bankAccount.open();
110
         bankAccount.open();
116
         bankAccount.withdraw(-5);
116
         bankAccount.withdraw(-5);
117
     }
117
     }
118
 
118
 
119
-    @Ignore
119
+    @Ignore("Remove to run test")
120
     @Test
120
     @Test
121
     public void cannotGetBalanceOfClosedAccount() throws BankAccountActionInvalidException {
121
     public void cannotGetBalanceOfClosedAccount() throws BankAccountActionInvalidException {
122
         bankAccount.open();
122
         bankAccount.open();
129
         bankAccount.getBalance();
129
         bankAccount.getBalance();
130
     }
130
     }
131
 
131
 
132
-    @Ignore
132
+    @Ignore("Remove to run test")
133
     @Test
133
     @Test
134
     public void cannotDepositMoneyIntoClosedAccount() throws BankAccountActionInvalidException {
134
     public void cannotDepositMoneyIntoClosedAccount() throws BankAccountActionInvalidException {
135
         bankAccount.open();
135
         bankAccount.open();
141
         bankAccount.deposit(5);
141
         bankAccount.deposit(5);
142
     }
142
     }
143
 
143
 
144
-    @Ignore
144
+    @Ignore("Remove to run test")
145
     @Test
145
     @Test
146
     public void cannotWithdrawMoneyFromClosedAccount() throws BankAccountActionInvalidException {
146
     public void cannotWithdrawMoneyFromClosedAccount() throws BankAccountActionInvalidException {
147
         bankAccount.open();
147
         bankAccount.open();
154
         bankAccount.withdraw(5);
154
         bankAccount.withdraw(5);
155
     }
155
     }
156
 
156
 
157
-    @Ignore
157
+    @Ignore("Remove to run test")
158
     @Test
158
     @Test
159
     public void bankAccountIsClosedBeforeItIsOpened() throws BankAccountActionInvalidException {
159
     public void bankAccountIsClosedBeforeItIsOpened() throws BankAccountActionInvalidException {
160
         expectedException.expect(BankAccountActionInvalidException.class);
160
         expectedException.expect(BankAccountActionInvalidException.class);
163
         bankAccount.getBalance();
163
         bankAccount.getBalance();
164
     }
164
     }
165
 
165
 
166
-    @Ignore
166
+    @Ignore("Remove to run test")
167
     @Test
167
     @Test
168
     public void canAdjustBalanceConcurrently() throws BankAccountActionInvalidException, InterruptedException {
168
     public void canAdjustBalanceConcurrently() throws BankAccountActionInvalidException, InterruptedException {
169
         bankAccount.open();
169
         bankAccount.open();