Jacqueline Joson пре 6 година
родитељ
комит
e8f7711c17
3 измењених фајлова са 152 додато и 77 уклоњено
  1. 71
    69
      .idea/workspace.xml
  2. 19
    5
      src/main/java/MyArrayList.java
  3. 62
    3
      src/test/java/MyArrayListTest.java

+ 71
- 69
.idea/workspace.xml Прегледај датотеку

@@ -2,8 +2,8 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="ada34df4-dfd8-4fb3-8f80-b9a79b2fcc05" name="Default Changelist" comment="">
5
-      <change beforePath="$PROJECT_DIR$/src/main/java/.deleteme" beforeDir="false" />
6
-      <change beforePath="$PROJECT_DIR$/src/test/java/.deleteme" beforeDir="false" />
5
+      <change beforePath="$PROJECT_DIR$/src/main/java/MyArrayList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/MyArrayList.java" afterDir="false" />
6
+      <change beforePath="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" afterDir="false" />
7 7
     </list>
8 8
     <ignored path="$PROJECT_DIR$/target/" />
9 9
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -42,13 +42,13 @@
42 42
       </usages-collector>
43 43
       <usages-collector id="statistics.file.extensions.edit">
44 44
         <counts>
45
-          <entry key="java" value="2864" />
45
+          <entry key="java" value="3930" />
46 46
           <entry key="txt" value="59" />
47 47
         </counts>
48 48
       </usages-collector>
49 49
       <usages-collector id="statistics.file.types.edit">
50 50
         <counts>
51
-          <entry key="JAVA" value="2864" />
51
+          <entry key="JAVA" value="3930" />
52 52
           <entry key="PLAIN_TEXT" value="59" />
53 53
         </counts>
54 54
       </usages-collector>
@@ -66,32 +66,28 @@
66 66
           </provider>
67 67
         </entry>
68 68
       </file>
69
-      <file pinned="false" current-in-tab="true">
69
+      <file pinned="false" current-in-tab="false">
70 70
         <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
71 71
           <provider selected="true" editor-type-id="text-editor">
72
-            <state relative-caret-position="345">
73
-              <caret line="48" column="9" lean-forward="true" selection-start-line="48" selection-start-column="9" selection-end-line="48" selection-end-column="9" />
72
+            <state relative-caret-position="217">
73
+              <caret line="78" column="13" lean-forward="true" selection-start-line="78" selection-start-column="13" selection-end-line="78" selection-end-column="13" />
74 74
               <folding>
75 75
                 <element signature="e#67#68#0" expanded="true" />
76 76
                 <element signature="e#107#108#0" expanded="true" />
77 77
                 <element signature="e#216#217#0" expanded="true" />
78 78
                 <element signature="e#250#251#0" expanded="true" />
79
-                <element signature="e#1330#1331#0" expanded="true" />
80
-                <element signature="e#1366#1367#0" expanded="true" />
81
-                <element signature="e#1419#1420#0" expanded="true" />
82
-                <element signature="e#1455#1456#0" expanded="true" />
83
-                <element signature="e#1484#1485#0" expanded="true" />
84
-                <element signature="e#1529#1530#0" expanded="true" />
79
+                <element signature="e#1551#1552#0" expanded="true" />
80
+                <element signature="e#1596#1597#0" expanded="true" />
85 81
               </folding>
86 82
             </state>
87 83
           </provider>
88 84
         </entry>
89 85
       </file>
90
-      <file pinned="false" current-in-tab="false">
86
+      <file pinned="false" current-in-tab="true">
91 87
         <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
92 88
           <provider selected="true" editor-type-id="text-editor">
93
-            <state relative-caret-position="704">
94
-              <caret line="49" column="20" lean-forward="true" selection-start-line="49" selection-start-column="20" selection-end-line="49" selection-end-column="20" />
89
+            <state relative-caret-position="254">
90
+              <caret line="134" column="40" lean-forward="true" selection-start-line="134" selection-start-column="40" selection-end-line="134" selection-end-column="40" />
95 91
               <folding>
96 92
                 <element signature="imports" expanded="true" />
97 93
                 <element signature="e#282#291#0" expanded="true" />
@@ -216,7 +212,7 @@
216 212
   <component name="PropertiesComponent">
217 213
     <property name="WebServerToolWindowFactoryState" value="false" />
218 214
     <property name="aspect.path.notification.shown" value="true" />
219
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542324893948" />
215
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542340110766" />
220 216
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="JUnit4" />
221 217
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrarySuperClass.JUnit4" value="" />
222 218
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
@@ -247,59 +243,69 @@
247 243
       </list>
248 244
     </option>
249 245
   </component>
250
-  <component name="RunManager" selected="JUnit.MyArrayListTest.clearTest">
251
-    <configuration name="MyArrayListTest.addIntTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
246
+  <component name="RunManager" selected="JUnit.MyArrayListTest.addOverrideTest">
247
+    <configuration name="MyArrayListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
248
+      <module name="generics" />
249
+      <option name="PACKAGE_NAME" value="" />
250
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
251
+      <method v="2">
252
+        <option name="Make" enabled="true" />
253
+      </method>
254
+    </configuration>
255
+    <configuration name="MyArrayListTest.addOverrideTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
252 256
       <module name="generics" />
253 257
       <option name="PACKAGE_NAME" value="" />
254 258
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
255
-      <option name="METHOD_NAME" value="addIntTest" />
259
+      <option name="METHOD_NAME" value="addOverrideTest" />
256 260
       <option name="TEST_OBJECT" value="method" />
257 261
       <method v="2">
258 262
         <option name="Make" enabled="true" />
259 263
       </method>
260 264
     </configuration>
261
-    <configuration name="MyArrayListTest.clearTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
265
+    <configuration name="MyArrayListTest.containsFalseTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
262 266
       <module name="generics" />
263 267
       <option name="PACKAGE_NAME" value="" />
264 268
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
265
-      <option name="METHOD_NAME" value="clearTest" />
269
+      <option name="METHOD_NAME" value="containsFalseTest" />
266 270
       <option name="TEST_OBJECT" value="method" />
267 271
       <method v="2">
268 272
         <option name="Make" enabled="true" />
269 273
       </method>
270 274
     </configuration>
271
-    <configuration name="MyArrayListTest.getTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
275
+    <configuration name="MyArrayListTest.containsTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
272 276
       <module name="generics" />
273 277
       <option name="PACKAGE_NAME" value="" />
274 278
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
275
-      <option name="METHOD_NAME" value="getTest" />
279
+      <option name="METHOD_NAME" value="containsTest" />
276 280
       <option name="TEST_OBJECT" value="method" />
277 281
       <method v="2">
278 282
         <option name="Make" enabled="true" />
279 283
       </method>
280 284
     </configuration>
281
-    <configuration name="MyArrayListTest.setTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
285
+    <configuration name="MyArrayListTest.isEmptyTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
282 286
       <module name="generics" />
283 287
       <option name="PACKAGE_NAME" value="" />
284 288
       <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
285
-      <option name="METHOD_NAME" value="setTest" />
289
+      <option name="METHOD_NAME" value="isEmptyTest" />
286 290
       <option name="TEST_OBJECT" value="method" />
287 291
       <method v="2">
288 292
         <option name="Make" enabled="true" />
289 293
       </method>
290 294
     </configuration>
291 295
     <list>
292
-      <item itemvalue="JUnit.MyArrayListTest.addIntTest" />
293
-      <item itemvalue="JUnit.MyArrayListTest.getTest" />
294
-      <item itemvalue="JUnit.MyArrayListTest.setTest" />
295
-      <item itemvalue="JUnit.MyArrayListTest.clearTest" />
296
+      <item itemvalue="JUnit.MyArrayListTest" />
297
+      <item itemvalue="JUnit.MyArrayListTest.isEmptyTest" />
298
+      <item itemvalue="JUnit.MyArrayListTest.containsTest" />
299
+      <item itemvalue="JUnit.MyArrayListTest.containsFalseTest" />
300
+      <item itemvalue="JUnit.MyArrayListTest.addOverrideTest" />
296 301
     </list>
297 302
     <recent_temporary>
298 303
       <list>
299
-        <item itemvalue="JUnit.MyArrayListTest.clearTest" />
300
-        <item itemvalue="JUnit.MyArrayListTest.setTest" />
301
-        <item itemvalue="JUnit.MyArrayListTest.addIntTest" />
302
-        <item itemvalue="JUnit.MyArrayListTest.getTest" />
304
+        <item itemvalue="JUnit.MyArrayListTest.addOverrideTest" />
305
+        <item itemvalue="JUnit.MyArrayListTest.containsFalseTest" />
306
+        <item itemvalue="JUnit.MyArrayListTest.containsTest" />
307
+        <item itemvalue="JUnit.MyArrayListTest" />
308
+        <item itemvalue="JUnit.MyArrayListTest.isEmptyTest" />
303 309
       </list>
304 310
     </recent_temporary>
305 311
   </component>
@@ -313,26 +319,11 @@
313 319
       <option name="number" value="Default" />
314 320
       <option name="presentableId" value="Default" />
315 321
       <updated>1542236797011</updated>
316
-      <workItem from="1542236798436" duration="14202000" />
322
+      <workItem from="1542236798436" duration="16476000" />
317 323
     </task>
318 324
     <servers />
319 325
   </component>
320 326
   <component name="TestHistory">
321
-    <history-entry file="MyArrayListTest_setTest - 2018.11.15 at 18h 04m 25s.xml">
322
-      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
323
-    </history-entry>
324
-    <history-entry file="MyArrayListTest_setTest - 2018.11.15 at 18h 04m 54s.xml">
325
-      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
326
-    </history-entry>
327
-    <history-entry file="MyArrayListTest_setTest - 2018.11.15 at 18h 06m 07s.xml">
328
-      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
329
-    </history-entry>
330
-    <history-entry file="MyArrayListTest_setTest - 2018.11.15 at 18h 07m 57s.xml">
331
-      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
332
-    </history-entry>
333
-    <history-entry file="MyArrayListTest_setTest - 2018.11.15 at 18h 08m 04s.xml">
334
-      <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
335
-    </history-entry>
336 327
     <history-entry file="MyArrayListTest_setTest - 2018.11.15 at 18h 18m 10s.xml">
337 328
       <configuration name="MyArrayListTest.setTest" configurationId="JUnit" />
338 329
     </history-entry>
@@ -348,9 +339,24 @@
348 339
     <history-entry file="MyArrayListTest_clearTest - 2018.11.15 at 18h 34m 39s.xml">
349 340
       <configuration name="MyArrayListTest.clearTest" configurationId="JUnit" />
350 341
     </history-entry>
342
+    <history-entry file="MyArrayListTest - 2018.11.15 at 22h 13m 39s.xml">
343
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
344
+    </history-entry>
345
+    <history-entry file="MyArrayListTest_isEmptyTest - 2018.11.15 at 22h 21m 29s.xml">
346
+      <configuration name="MyArrayListTest.isEmptyTest" configurationId="JUnit" />
347
+    </history-entry>
348
+    <history-entry file="MyArrayListTest - 2018.11.15 at 22h 23m 27s.xml">
349
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
350
+    </history-entry>
351
+    <history-entry file="MyArrayListTest_containsTest - 2018.11.15 at 22h 31m 02s.xml">
352
+      <configuration name="MyArrayListTest.containsTest" configurationId="JUnit" />
353
+    </history-entry>
354
+    <history-entry file="MyArrayListTest_containsFalseTest - 2018.11.15 at 22h 31m 53s.xml">
355
+      <configuration name="MyArrayListTest.containsFalseTest" configurationId="JUnit" />
356
+    </history-entry>
351 357
   </component>
352 358
   <component name="TimeTrackingManager">
353
-    <option name="totallyTimeSpent" value="14202000" />
359
+    <option name="totallyTimeSpent" value="16476000" />
354 360
   </component>
355 361
   <component name="ToolWindowManager">
356 362
     <frame x="0" y="23" width="1280" height="712" extended-state="0" />
@@ -491,32 +497,28 @@
491 497
         </state>
492 498
       </provider>
493 499
     </entry>
494
-    <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
500
+    <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
495 501
       <provider selected="true" editor-type-id="text-editor">
496
-        <state relative-caret-position="704">
497
-          <caret line="49" column="20" lean-forward="true" selection-start-line="49" selection-start-column="20" selection-end-line="49" selection-end-column="20" />
502
+        <state relative-caret-position="217">
503
+          <caret line="78" column="13" lean-forward="true" selection-start-line="78" selection-start-column="13" selection-end-line="78" selection-end-column="13" />
498 504
           <folding>
499
-            <element signature="imports" expanded="true" />
500
-            <element signature="e#282#291#0" expanded="true" />
505
+            <element signature="e#67#68#0" expanded="true" />
506
+            <element signature="e#107#108#0" expanded="true" />
507
+            <element signature="e#216#217#0" expanded="true" />
508
+            <element signature="e#250#251#0" expanded="true" />
509
+            <element signature="e#1551#1552#0" expanded="true" />
510
+            <element signature="e#1596#1597#0" expanded="true" />
501 511
           </folding>
502 512
         </state>
503 513
       </provider>
504 514
     </entry>
505
-    <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
515
+    <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
506 516
       <provider selected="true" editor-type-id="text-editor">
507
-        <state relative-caret-position="345">
508
-          <caret line="48" column="9" lean-forward="true" selection-start-line="48" selection-start-column="9" selection-end-line="48" selection-end-column="9" />
517
+        <state relative-caret-position="254">
518
+          <caret line="134" column="40" lean-forward="true" selection-start-line="134" selection-start-column="40" selection-end-line="134" selection-end-column="40" />
509 519
           <folding>
510
-            <element signature="e#67#68#0" expanded="true" />
511
-            <element signature="e#107#108#0" expanded="true" />
512
-            <element signature="e#216#217#0" expanded="true" />
513
-            <element signature="e#250#251#0" expanded="true" />
514
-            <element signature="e#1330#1331#0" expanded="true" />
515
-            <element signature="e#1366#1367#0" expanded="true" />
516
-            <element signature="e#1419#1420#0" expanded="true" />
517
-            <element signature="e#1455#1456#0" expanded="true" />
518
-            <element signature="e#1484#1485#0" expanded="true" />
519
-            <element signature="e#1529#1530#0" expanded="true" />
520
+            <element signature="imports" expanded="true" />
521
+            <element signature="e#282#291#0" expanded="true" />
520 522
           </folding>
521 523
         </state>
522 524
       </provider>

+ 19
- 5
src/main/java/MyArrayList.java Прегледај датотеку

@@ -49,20 +49,34 @@ public class MyArrayList<T> {
49 49
         }
50 50
 
51 51
         public boolean isEmpty () {
52
-            return false;
52
+            if (size() > 0) {
53
+                 return false;
54
+            } else
55
+                return true;
53 56
         }
54 57
 
55 58
         public boolean contains (T elementToCheck){
59
+            for (int i = 0; i < theArray.length; i++) {
60
+                if (theArray[i].equals(elementToCheck)) {
61
+                     return true;
62
+                }
63
+            }
56 64
             return false;
57 65
         }
58 66
 
59 67
         public int size() {
60 68
            return theArray.length;
61 69
         }
62
-//
70
+
63 71
 //        @Override
64
-//        public void add( int index, T elementToAdd){
65
-//
66
-//        }
72
+//        public void add(int index, T elementToAdd) {
73
+//            T [] newArray = (T[]) new Object[theArray.length + 1];
74
+//            for (int i = 0; i < theArray.length; i++) {
75
+//                newArray[i] = theArray[i];
76
+//                if (i == theArray.length-1) {
77
+//                  newArray[i] = elementToAdd;
78
+//                }
79
+//            }
80
+//        } Make a super or abstract class of AbstractList??
67 81
 
68 82
 }

+ 62
- 3
src/test/java/MyArrayListTest.java Прегледај датотеку

@@ -44,7 +44,7 @@ public class MyArrayListTest {
44 44
     }
45 45
 
46 46
     @Test
47
-    public void clearTest() {
47
+    public void clearStringTest() {
48 48
         //given
49 49
         String [] testStringArr = {"I", "am", "making", "some", "progress"};
50 50
         MyArrayList<String> myArrayList = new MyArrayList<>(testStringArr);
@@ -54,25 +54,84 @@ public class MyArrayListTest {
54 54
         Assert.assertNull(testStringArr[1]);
55 55
     }
56 56
 
57
+
57 58
     @Test
58
-    public void isEmptyTest() {
59
+    public void clearIntTest() {
59 60
         //given
61
+        Integer [] testIntegerArr = {3, 5, 6, 7, 1};
62
+        MyArrayList<Integer> myArrayList = new MyArrayList<>(testIntegerArr);
63
+        //when
64
+        myArrayList.clear();
65
+        //then
66
+        Assert.assertNull(testIntegerArr[1]);
67
+    }
60 68
 
69
+    @Test
70
+    public void isEmptyIntegerTest() {
71
+        //given
72
+        Integer [] testIntegerArray = {1, 3, 4};
73
+        MyArrayList<Integer> myArrayList = new MyArrayList<>(testIntegerArray);
61 74
         //when
75
+        boolean actual = myArrayList.isEmpty();
76
+        //then
77
+        Assert.assertFalse(actual);
78
+    }
62 79
 
80
+    @Test
81
+    public void isEmptyBooleanTest() {
82
+        //given
83
+        Boolean [] testBoolsArray = {true, false, false, true};
84
+        MyArrayList<Boolean> myArrayList = new MyArrayList<>(testBoolsArray);
85
+        //when
86
+        boolean actual = myArrayList.isEmpty();
63 87
         //then
88
+        Assert.assertFalse(actual);
64 89
     }
65 90
 
66 91
     @Test
67
-    public void containsTest() {
92
+    public void isActuallyEmptyTest() {
68 93
         //given
94
+        Integer [] testEmptyArray = {};
95
+        MyArrayList<Integer> myArrayList = new MyArrayList<>(testEmptyArray);
96
+        //when
97
+        boolean actual = myArrayList.isEmpty();
98
+        //then
99
+        Assert.assertTrue(actual);
100
+    }
69 101
 
102
+
103
+    @Test
104
+    public void containsTrueTest() {
105
+        //given
106
+        Object [] testObjArray = {5, "Pushing", "on", "through", "them", "labs", "BOII", 10};
107
+        MyArrayList<Object> myArrayList = new MyArrayList<>(testObjArray);
70 108
         //when
109
+        boolean actual = myArrayList.contains("through");
110
+        //then
111
+        Assert.assertTrue(actual);
112
+    }
71 113
 
114
+    @Test
115
+    public void containsFalseTest() {
116
+        //given
117
+        Object [] testObjArray = {5, "Pushing", "on", "through", "them", "labs", "BOII", 10};
118
+        MyArrayList<Object> myArrayList = new MyArrayList<>(testObjArray);
119
+        //when
120
+        boolean actual = myArrayList.contains(true);
72 121
         //then
122
+        Assert.assertFalse(actual);
73 123
     }
74 124
 
125
+
75 126
     @Test
76 127
     public void addOverrideTest() {
128
+        //given
129
+        Integer [] testOverrideAddInts = {1, 3, 4, 5};
130
+        MyArrayList<Integer> myArrayList = new MyArrayList<>(testOverrideAddInts);
131
+        //when
132
+        myArrayList.add(1, 2);
133
+        boolean hasBeenAdded = myArrayList.contains(2);
134
+        //then
135
+        Assert.assertTrue(hasBeenAdded);
77 136
     }
78 137
 }