#10 Kate Moore

Отворени
katelynne заяви обединяване на 1 ревизии от katelynne/Checkbook-OldStyle:master във master
променени са 4 файла, в които са добавени 379 реда и са изтрити 72 реда
  1. 20
    68
      .idea/workspace.xml
  2. 130
    2
      Checkbook/src/main/java/Checkbook.java
  3. 1
    1
      Checkbook/src/main/java/GenericAccount.java
  4. 228
    1
      Checkbook/src/test/java/CheckbookTest.java

+ 20
- 68
.idea/workspace.xml Целия файл

@@ -71,7 +71,7 @@
71 71
     <detection-done>true</detection-done>
72 72
     <sorting>DEFINITION_ORDER</sorting>
73 73
   </component>
74
-  <component name="ProjectFrameBounds">
74
+  <component name="ProjectFrameBounds" extendedState="6" fullScreen="true">
75 75
     <option name="x" value="115" />
76 76
     <option name="y" value="45" />
77 77
     <option name="width" value="1538" />
@@ -136,16 +136,16 @@
136 136
     </panes>
137 137
   </component>
138 138
   <component name="PropertiesComponent">
139
-    <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
140
-    <property name="settings.editor.selected.configurable" value="configurable.group.appearance" />
141 139
     <property name="WebServerToolWindowFactoryState" value="false" />
142 140
     <property name="aspect.path.notification.shown" value="true" />
143
-    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
141
+    <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="JUnit4" />
144 142
     <property name="jdk.selected.JAVA_MODULE" value="1.8" />
143
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
144
+    <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
145 145
     <property name="project.structure.last.edited" value="Modules" />
146 146
     <property name="project.structure.proportion" value="0.0" />
147 147
     <property name="project.structure.side.proportion" value="0.0" />
148
-    <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="JUnit4" />
148
+    <property name="settings.editor.selected.configurable" value="configurable.group.appearance" />
149 149
   </component>
150 150
   <component name="RecentsManager">
151 151
     <key name="CreateTestDialog.RecentsKey">
@@ -169,89 +169,41 @@
169 169
   </component>
170 170
   <component name="RunManager">
171 171
     <configuration default="true" type="Applet" factoryName="Applet">
172
-      <option name="WIDTH" value="400" />
173
-      <option name="HEIGHT" value="300" />
174 172
       <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
175
-      <module />
173
+      <method v="2">
174
+        <option name="Make" enabled="true" />
175
+      </method>
176 176
     </configuration>
177 177
     <configuration default="true" type="Application" factoryName="Application">
178
-      <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
179
-      <option name="MAIN_CLASS_NAME" />
180
-      <option name="VM_PARAMETERS" />
181
-      <option name="PROGRAM_PARAMETERS" />
182 178
       <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
183
-      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
184
-      <option name="ALTERNATIVE_JRE_PATH" />
185
-      <option name="ENABLE_SWING_INSPECTOR" value="false" />
186
-      <option name="ENV_VARIABLES" />
187
-      <option name="PASS_PARENT_ENVS" value="true" />
188
-      <module name="" />
189
-      <envs />
179
+      <method v="2">
180
+        <option name="Make" enabled="true" />
181
+      </method>
190 182
     </configuration>
191 183
     <configuration default="true" type="JUnit" factoryName="JUnit">
192
-      <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
193
-      <module name="" />
194
-      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
195
-      <option name="ALTERNATIVE_JRE_PATH" />
196
-      <option name="PACKAGE_NAME" />
197
-      <option name="MAIN_CLASS_NAME" />
198
-      <option name="METHOD_NAME" />
199
-      <option name="TEST_OBJECT" value="class" />
200
-      <option name="VM_PARAMETERS" value="-ea" />
201
-      <option name="PARAMETERS" />
202 184
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
203
-      <option name="ENV_VARIABLES" />
204
-      <option name="PASS_PARENT_ENVS" value="true" />
205
-      <option name="TEST_SEARCH_SCOPE">
206
-        <value defaultName="singleModule" />
207
-      </option>
208
-      <envs />
209
-      <patterns />
210
-    </configuration>
211
-    <configuration default="true" type="Remote" factoryName="Remote">
212
-      <option name="USE_SOCKET_TRANSPORT" value="true" />
213
-      <option name="SERVER_MODE" value="false" />
214
-      <option name="SHMEM_ADDRESS" value="javadebug" />
215
-      <option name="HOST" value="localhost" />
216
-      <option name="PORT" value="5005" />
185
+      <method v="2">
186
+        <option name="Make" enabled="true" />
187
+      </method>
217 188
     </configuration>
218 189
     <configuration default="true" type="TestNG" factoryName="TestNG">
219
-      <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
220
-      <module name="" />
221
-      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
222
-      <option name="ALTERNATIVE_JRE_PATH" />
223
-      <option name="SUITE_NAME" />
224
-      <option name="PACKAGE_NAME" />
225
-      <option name="MAIN_CLASS_NAME" />
226
-      <option name="METHOD_NAME" />
227
-      <option name="GROUP_NAME" />
228
-      <option name="TEST_OBJECT" value="CLASS" />
229
-      <option name="VM_PARAMETERS" value="-ea" />
230
-      <option name="PARAMETERS" />
231 190
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
232
-      <option name="OUTPUT_DIRECTORY" />
233
-      <option name="ANNOTATION_TYPE" />
234
-      <option name="ENV_VARIABLES" />
235
-      <option name="PASS_PARENT_ENVS" value="true" />
236
-      <option name="TEST_SEARCH_SCOPE">
237
-        <value defaultName="singleModule" />
238
-      </option>
239
-      <option name="USE_DEFAULT_REPORTERS" value="false" />
240
-      <option name="PROPERTIES_FILE" />
241
-      <envs />
242 191
       <properties />
243 192
       <listeners />
193
+      <method v="2">
194
+        <option name="Make" enabled="true" />
195
+      </method>
244 196
     </configuration>
245 197
     <configuration default="true" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType" factoryName="Plugin">
246 198
       <module name="" />
247 199
       <option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -XX:MaxPermSize=250m -ea" />
248 200
       <option name="PROGRAM_PARAMETERS" />
249 201
       <predefined_log_file id="idea.log" enabled="true" />
202
+      <method v="2">
203
+        <option name="Make" enabled="true" />
204
+      </method>
250 205
     </configuration>
251 206
   </component>
252
-  <component name="ShelveChangesManager" show_recycled="false">
253
-    <option name="remove_strategy" value="false" />
254
-  </component>
255 207
   <component name="SvnConfiguration">
256 208
     <configuration />
257 209
   </component>

+ 130
- 2
Checkbook/src/main/java/Checkbook.java Целия файл

@@ -1,5 +1,133 @@
1
-public class Checkbook {
2 1
 
3
-    //blind us with your Java eloquence....
2
+import java.lang.reflect.Array;
3
+import java.time.LocalDate;
4
+import java.util.Collection;
5
+import java.util.List;
6
+import java.util.ArrayList;
7
+import java.util.Iterator;
8
+
9
+public class Checkbook{
10
+
11
+    private List<Transaction> checkbook;
12
+    private Payee owner;
13
+    private Double cashAmount;
14
+
15
+    public Checkbook() {
16
+        this.checkbook = new ArrayList<>();
17
+    }
18
+
19
+    public Checkbook(Payee owner, Double cashAmount) {
20
+        this.owner = owner;
21
+        this.cashAmount = cashAmount;
22
+        this.checkbook = new ArrayList<>();
23
+    }
24
+
25
+    public Checkbook(Double cashAmount) {
26
+        this.cashAmount = cashAmount;
27
+        this.checkbook = new ArrayList<>();
28
+    }
29
+
30
+    public int size(){
31
+        return checkbook.size();
32
+    }
33
+
34
+    public Boolean isEmpty(){
35
+        return checkbook.isEmpty();
36
+    }
37
+
38
+    public Boolean remove(Transaction transaction){
39
+        return checkbook.remove(transaction);
40
+    }
41
+
42
+    public void add(Transaction newTransaction){
43
+        checkbook.add(newTransaction);
44
+    }
45
+
46
+    public Boolean contains(Transaction newTransaction){
47
+        return checkbook.contains(newTransaction);
48
+    }
49
+
50
+    public Iterator iterator() {
51
+        return checkbook.iterator();
52
+    }
53
+
54
+    public Transaction[] toArray(){
55
+        return checkbook.toArray(new Transaction[0]);
56
+    }
57
+
58
+    public Double checkbookValue(){
59
+        Double credit = 0.0;
60
+        Double debit = 0.0;
61
+        Double total = credit + debit;
62
+        for(Transaction transaction : checkbook){
63
+            if(transaction.getType() == TransactionType.DEBIT) {
64
+                debit += transaction.getAmount();
65
+            } else {
66
+                credit += transaction.getAmount();
67
+            }
68
+        }
69
+        return cashAmount + total;
70
+    }
71
+
72
+    public Transaction[] getTransactionForDate(LocalDate date){
73
+        ArrayList<Transaction> list = new ArrayList<>();
74
+        for(Transaction transaction : checkbook) {
75
+            if(transaction.getDate() == date) {
76
+                list.add(transaction);
77
+            }
78
+        }
79
+        return list.toArray(new Transaction[0]);
80
+    }
81
+
82
+    public Transaction[] getAllTransactionsForPayee(Payee payee){
83
+        ArrayList<Transaction> list = new ArrayList<>();
84
+        for(Transaction transaction : checkbook) {
85
+            if(transaction.getPayee() == (payee)) {
86
+                list.add(transaction);
87
+            }
88
+        }
89
+        return list.toArray(new Transaction[0]);
90
+    }
91
+
92
+    public Transaction[] getAllDebitTransactions(){
93
+        ArrayList<Transaction> list = new ArrayList<>();
94
+        for(Transaction transaction: checkbook) {
95
+            if(transaction.getType() == TransactionType.DEBIT) {
96
+                list.add(transaction);
97
+            }
98
+        }
99
+        return list.toArray(new Transaction[0]);
100
+    }
101
+
102
+    public Transaction[] getAllCreditTransactions(){
103
+        ArrayList<Transaction> list = new ArrayList<>();
104
+        for(Transaction transaction : checkbook) {
105
+            if(transaction.getType() == TransactionType.CREDIT) {
106
+                list.add(transaction);
107
+            }
108
+        }
109
+        return list.toArray(new Transaction[0]);
110
+    }
111
+
112
+    public void clear(){
113
+        checkbook.clear();
114
+    }
115
+
116
+    public Boolean removeAll(Collection collection){
117
+        return this.removeAll(collection);
118
+    }
119
+
120
+    public Boolean addAll(Collection collection){
121
+        return this.addAll(collection);
122
+    }
123
+
124
+    public Boolean containsAll(Collection collection){
125
+        return this.containsAll(collection);
126
+    }
127
+
128
+
129
+
130
+
131
+
4 132
 
5 133
 }

+ 1
- 1
Checkbook/src/main/java/GenericAccount.java Целия файл

@@ -1,3 +1,3 @@
1 1
 
2
-public class GenericAccount {
2
+public class GenericAccount<T extends AccountBook> {
3 3
 }

+ 228
- 1
Checkbook/src/test/java/CheckbookTest.java Целия файл

@@ -1,12 +1,239 @@
1
-import static org.junit.Assert.*;
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
2 4
 
3 5
 public class CheckbookTest {
6
+    private Checkbook checkbook1 = new Checkbook(100.00);
7
+    private Checkbook checkbook2 = new Checkbook(30.00);
8
+    private Payee owner1 = new Payee();
9
+    private Payee owner2 = new Payee();
10
+    private Transaction transactionDebit1 = new Transaction(" ", owner1, TransactionType.DEBIT, 100.00);
11
+    private Transaction transactionCredit1 = new Transaction(" ", owner1, TransactionType.CREDIT, 50.00);
12
+    private Transaction transactionDebit2 = new Transaction(" ", owner2, TransactionType.DEBIT, 100.00);
13
+    private Transaction transactionCredit2 = new Transaction(" ", owner2, TransactionType.CREDIT, 50.00);
4 14
 
5 15
     @org.junit.Before
6 16
     public void setUp() throws Exception {
17
+        checkbook1.add(transactionCredit1);
18
+        checkbook1.add(transactionDebit1);
19
+        checkbook2.add(transactionCredit2);
20
+        checkbook2.add(transactionDebit2);
7 21
     }
8 22
 
9 23
     @org.junit.After
10 24
     public void tearDown() throws Exception {
11 25
     }
26
+
27
+    @Test
28
+    public void test1Add() {
29
+        Assert.assertEquals(2, checkbook1.size());
30
+    }
31
+
32
+    @Test
33
+    public void test2Add() {
34
+        checkbook1.add(new Transaction("", new Payee(), TransactionType.DEBIT, 1.00));
35
+        int expected = 3;
36
+        int actual = checkbook1.size();
37
+        Assert.assertEquals(expected, actual);
38
+    }
39
+
40
+    @Test
41
+    public void test3Add() {
42
+        checkbook2.add(new Transaction("", owner1, TransactionType.DEBIT, 1.00));
43
+        checkbook2.add(new Transaction("", owner1, TransactionType.DEBIT, 1.50));
44
+        int expected = 4;
45
+        int actual = checkbook2.size();
46
+        Assert.assertEquals(expected, actual);
47
+    }
48
+
49
+    @Test
50
+    public void test1Remove() {
51
+        checkbook1.remove(transactionCredit1);
52
+        int expected = 1;
53
+        int actual = checkbook1.size();
54
+        Assert.assertEquals(expected, actual);
55
+
56
+    }
57
+
58
+    @Test
59
+    public void test2Remove() {
60
+        checkbook1.remove(transactionCredit1);
61
+        checkbook1.remove(transactionDebit1);
62
+        int expected = 0;
63
+        int actual = checkbook1.size();
64
+        Assert.assertEquals(expected, actual);
65
+    }
66
+
67
+    @Test
68
+    public void test1contains() {
69
+        Assert.assertTrue(checkbook1.contains(transactionCredit1));
70
+    }
71
+
72
+    @Test
73
+    public void test2contains() {
74
+        Assert.assertTrue(checkbook1.contains(transactionDebit1));
75
+    }
76
+
77
+    @Test
78
+    public void test3contains() {
79
+        Assert.assertTrue(checkbook2.contains(transactionCredit2));
80
+    }
81
+
82
+    @Test
83
+    public void test1isEmpty() {
84
+        Assert.assertFalse(checkbook2.isEmpty());
85
+    }
86
+
87
+    @Test
88
+    public void test2isEmpty() {
89
+        Checkbook check = new Checkbook();
90
+        Assert.assertTrue(check.isEmpty());
91
+    }
92
+
93
+    @Test
94
+    public void test3isEmpty() {
95
+        Assert.assertFalse(checkbook1.isEmpty());
96
+    }
97
+
98
+    @Test
99
+    public void test1Iterator() {
100
+        Assert.assertTrue(checkbook1.iterator().hasNext());
101
+    }
102
+
103
+    @Test
104
+    public void test2Iterator() {
105
+        Checkbook check = new Checkbook();
106
+        Assert.assertFalse(check.iterator().hasNext());
107
+    }
108
+
109
+    @Test
110
+    public void test1CheckbookValue() {
111
+        Assert.assertEquals(100.00, checkbook1.checkbookValue(), .01);
112
+    }
113
+
114
+    @Test
115
+    public void test2CheckbookValue() {
116
+        Double expected = 30.00;
117
+        Double actual = checkbook2.checkbookValue();
118
+        Assert.assertEquals(expected, actual);
119
+    }
120
+
121
+    @Test
122
+    public void test1ToArray() {
123
+        int expected = 2;
124
+        int actual = checkbook1.toArray().length;
125
+        Assert.assertEquals(expected, actual);
126
+    }
127
+
128
+    @Test
129
+    public void test2ToArray() {
130
+        int expected = 2;
131
+        int actual = checkbook2.toArray().length;
132
+        Assert.assertEquals(expected, actual);
133
+    }
134
+
135
+    @Test
136
+    public void test3ToArray() {
137
+        Checkbook check = new Checkbook();
138
+        int expected = 0;
139
+        int actual = check.toArray().length;
140
+        Assert.assertEquals(expected, actual);
141
+    }
142
+
143
+    @Test
144
+    public void test1getTransactionForDate() {
145
+        Transaction[] expected = {transactionCredit1, transactionDebit1};
146
+        Transaction[] actual = checkbook1.getTransactionForDate(transactionCredit1.getDate());
147
+        Assert.assertEquals(expected, actual);
148
+    }
149
+
150
+    @Test
151
+    public void test2getTransactionForDate() {
152
+        Transaction[] expected = {transactionCredit2, transactionDebit2};
153
+        Transaction[] actual = checkbook2.getTransactionForDate(transactionCredit2.getDate());
154
+        Assert.assertEquals(expected, actual);
155
+    }
156
+
157
+    @Test
158
+    public void test1getAllTransactionsForPayee() {
159
+        Transaction[] expected = {transactionDebit1, transactionCredit1};
160
+        Transaction[] actual = checkbook1.getAllTransactionsForPayee(owner1);
161
+        Assert.assertEquals(expected, actual);
162
+    }
163
+
164
+    @Test
165
+    public void test2getAllTransactionsForPayee() {
166
+        Transaction[] expected = {transactionDebit2, transactionCredit2};
167
+        Transaction[] actual = checkbook2.getAllTransactionsForPayee(owner2);
168
+        Assert.assertEquals(expected, actual);
169
+    }
170
+
171
+    @Test
172
+    public void test3getAllTransactionsForPayee() {
173
+        Transaction[] expected = {transactionDebit1, transactionCredit1};
174
+        Transaction[] actual = checkbook1.getAllTransactionsForPayee(owner1);
175
+        Assert.assertEquals(expected, actual);
176
+    }
177
+
178
+    @Test
179
+    public void test1getAllDebitTransactions() {
180
+        Transaction[] expected = {transactionDebit2};
181
+        Transaction[] actual = checkbook2.getAllDebitTransactions();
182
+        Assert.assertEquals(expected, actual);
183
+    }
184
+
185
+    @Test
186
+    public void test2getAllDebitTransactions() {
187
+        Transaction[] expected = {transactionDebit1};
188
+        Transaction[] actual = checkbook1.getAllDebitTransactions();
189
+        Assert.assertEquals(expected, actual);
190
+    }
191
+
192
+    @Test
193
+    public void test3getAllDebitTransactions() {
194
+        Checkbook checkbook = new Checkbook();
195
+        Transaction transactionDebit = new Transaction(" ", owner1, TransactionType.DEBIT, 100.00);
196
+        checkbook.add(transactionDebit);
197
+        Transaction[] expected = {transactionDebit};
198
+        Transaction[] actual = checkbook.getAllDebitTransactions();
199
+        Assert.assertEquals(expected, actual);
200
+    }
201
+
202
+    @Test
203
+    public void test1getAllCreditTransactions() {
204
+        Transaction[] expected = {transactionCredit1};
205
+        Transaction[] actual = checkbook1.getAllCreditTransactions();
206
+        Assert.assertEquals(expected, actual);
207
+    }
208
+
209
+    @Test
210
+    public void test2getAllCreditTransactions() {
211
+        Transaction[] expected = {transactionCredit2};
212
+        Transaction[] actual = checkbook2.getAllCreditTransactions();
213
+        Assert.assertEquals(expected, actual);
214
+    }
215
+
216
+    @Test
217
+    public void test3getAllCreditTransactions() {
218
+        Checkbook checkbook = new Checkbook();
219
+        Transaction transactionCredit = new Transaction(" ", owner1, TransactionType.CREDIT, 100.00);
220
+        checkbook.add(transactionCredit);
221
+        Transaction[] expected = {transactionCredit};
222
+        Transaction[] actual = checkbook.getAllCreditTransactions();
223
+        Assert.assertEquals(expected, actual);
224
+    }
225
+
226
+    @Test
227
+    public void test1Clear() {
228
+        checkbook2.clear();
229
+        Assert.assertEquals(0, checkbook2.size());
230
+    }
231
+
232
+    @Test
233
+    public void test2Clear() {
234
+        checkbook1.clear();
235
+        Assert.assertEquals(0, checkbook1.size());
236
+    }
237
+
238
+
12 239
 }