Просмотр исходного кода

both remove methods work, 100% coverage

jasamuels 6 лет назад
Родитель
Сommit
4b45032265
3 измененных файлов: 169 добавлений и 48 удалений
  1. 115
    48
      .idea/workspace.xml
  2. 30
    0
      src/main/java/MyArrayList.java
  3. 24
    0
      src/test/java/MyArrayListTest.java

+ 115
- 48
.idea/workspace.xml Просмотреть файл

@@ -15,6 +15,15 @@
15 15
   <component name="CoverageDataManager">
16 16
     <SUITE FILE_PATH="coverage/generics$MyArrayListTest_addTest.ic" NAME="MyArrayListTest.addTest Coverage Results" MODIFIED="1542750815105" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
17 17
     <SUITE FILE_PATH="coverage/generics$MyArrayListTest_getTest.ic" NAME="MyArrayListTest.getTest Coverage Results" MODIFIED="1542751525168" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
18
+    <SUITE FILE_PATH="coverage/generics$MyArrayListTest_removeTestp2.ic" NAME="MyArrayListTest.removeTestp2 Coverage Results" MODIFIED="1542819197388" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
19
+    <SUITE FILE_PATH="coverage/generics$MyArrayListTest_removeTest.ic" NAME="MyArrayListTest.removeTest Coverage Results" MODIFIED="1542818910444" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
20
+    <SUITE FILE_PATH="coverage/generics$MyArrayListTest.ic" NAME="MyArrayListTest Coverage Results" MODIFIED="1542819245765" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
21
+  </component>
22
+  <component name="CoverageOptionsProvider">
23
+    <option name="myAddOrReplace" value="1" />
24
+  </component>
25
+  <component name="CoverageViewManager">
26
+    <option name="myElementSize" value="187" />
18 27
   </component>
19 28
   <component name="DockManager">
20 29
     <window id="1">
@@ -24,13 +33,16 @@
24 33
             <file pinned="false" current-in-tab="true">
25 34
               <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
26 35
                 <provider selected="true" editor-type-id="text-editor">
27
-                  <state relative-caret-position="299">
28
-                    <caret line="20" column="32" selection-start-line="20" selection-start-column="32" selection-end-line="20" selection-end-column="32" />
36
+                  <state relative-caret-position="1320">
37
+                    <caret line="88" column="11" selection-start-line="88" selection-start-column="11" selection-end-line="88" selection-end-column="11" />
29 38
                     <folding>
39
+                      <element signature="imports" expanded="true" />
30 40
                       <element signature="e#120#121#0" expanded="true" />
31 41
                       <element signature="e#162#163#0" expanded="true" />
32
-                      <element signature="e#784#785#0" expanded="true" />
33
-                      <element signature="e#816#817#0" expanded="true" />
42
+                      <element signature="e#461#491#0" expanded="true" />
43
+                      <element signature="e#682#712#0" expanded="true" />
44
+                      <element signature="e#1525#1526#0" expanded="true" />
45
+                      <element signature="e#1557#1558#0" expanded="true" />
34 46
                     </folding>
35 47
                   </state>
36 48
                 </provider>
@@ -54,23 +66,23 @@
54 66
       <usages-collector id="statistics.file.extensions.open">
55 67
         <counts>
56 68
           <entry key="class" value="1" />
57
-          <entry key="java" value="8" />
69
+          <entry key="java" value="9" />
58 70
         </counts>
59 71
       </usages-collector>
60 72
       <usages-collector id="statistics.file.types.open">
61 73
         <counts>
62 74
           <entry key="CLASS" value="1" />
63
-          <entry key="JAVA" value="8" />
75
+          <entry key="JAVA" value="9" />
64 76
         </counts>
65 77
       </usages-collector>
66 78
       <usages-collector id="statistics.file.extensions.edit">
67 79
         <counts>
68
-          <entry key="java" value="1984" />
80
+          <entry key="java" value="3113" />
69 81
         </counts>
70 82
       </usages-collector>
71 83
       <usages-collector id="statistics.file.types.edit">
72 84
         <counts>
73
-          <entry key="JAVA" value="1984" />
85
+          <entry key="JAVA" value="3113" />
74 86
         </counts>
75 87
       </usages-collector>
76 88
     </session>
@@ -80,8 +92,8 @@
80 92
       <file pinned="false" current-in-tab="true">
81 93
         <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
82 94
           <provider selected="true" editor-type-id="text-editor">
83
-            <state relative-caret-position="540">
84
-              <caret line="36" column="5" lean-forward="true" selection-start-line="36" selection-start-column="5" selection-end-line="36" selection-end-column="5" />
95
+            <state relative-caret-position="855">
96
+              <caret line="57" column="38" lean-forward="true" selection-start-line="57" selection-start-column="38" selection-end-line="57" selection-end-column="38" />
85 97
               <folding>
86 98
                 <element signature="imports" expanded="true" />
87 99
               </folding>
@@ -89,6 +101,19 @@
89 101
           </provider>
90 102
         </entry>
91 103
       </file>
104
+      <file pinned="false" current-in-tab="false">
105
+        <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/src.zip!/java/util/AbstractList.java">
106
+          <provider selected="true" editor-type-id="text-editor">
107
+            <state relative-caret-position="286">
108
+              <caret line="170" column="71" selection-start-line="170" selection-start-column="71" selection-end-line="170" selection-end-column="71" />
109
+              <folding>
110
+                <element signature="e#5343#5344#0" expanded="true" />
111
+                <element signature="e#5400#5401#0" expanded="true" />
112
+              </folding>
113
+            </state>
114
+          </provider>
115
+        </entry>
116
+      </file>
92 117
     </leaf>
93 118
   </component>
94 119
   <component name="FileTemplateManagerImpl">
@@ -106,8 +131,8 @@
106 131
       <list>
107 132
         <option value="$PROJECT_DIR$/src/main/java/Program.java" />
108 133
         <option value="$PROJECT_DIR$/src/test/java/ProgramTest.java" />
109
-        <option value="$PROJECT_DIR$/src/main/java/MyArrayList.java" />
110 134
         <option value="$PROJECT_DIR$/src/test/java/MyArrayListTest.java" />
135
+        <option value="$PROJECT_DIR$/src/main/java/MyArrayList.java" />
111 136
       </list>
112 137
     </option>
113 138
   </component>
@@ -187,7 +212,7 @@
187 212
   <component name="PropertiesComponent">
188 213
     <property name="WebServerToolWindowFactoryState" value="false" />
189 214
     <property name="aspect.path.notification.shown" value="true" />
190
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542751523139" />
215
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542819245571" />
191 216
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
192 217
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
193 218
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
@@ -204,7 +229,15 @@
204 229
       </list>
205 230
     </option>
206 231
   </component>
207
-  <component name="RunManager" selected="JUnit.MyArrayListTest.getTest">
232
+  <component name="RunManager" selected="JUnit.MyArrayListTest">
233
+    <configuration name="MyArrayListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
234
+      <module name="generics" />
235
+      <option name="PACKAGE_NAME" value="" />
236
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
237
+      <method v="2">
238
+        <option name="Make" enabled="true" />
239
+      </method>
240
+    </configuration>
208 241
     <configuration name="MyArrayListTest.addTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
209 242
       <module name="generics" />
210 243
       <option name="PACKAGE_NAME" value="" />
@@ -225,26 +258,40 @@
225 258
         <option name="Make" enabled="true" />
226 259
       </method>
227 260
     </configuration>
228
-    <configuration name="ProgramTest.TestCase4" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
261
+    <configuration name="MyArrayListTest.removeTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
262
+      <module name="generics" />
263
+      <option name="PACKAGE_NAME" value="" />
264
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
265
+      <option name="METHOD_NAME" value="removeTest" />
266
+      <option name="TEST_OBJECT" value="method" />
267
+      <method v="2">
268
+        <option name="Make" enabled="true" />
269
+      </method>
270
+    </configuration>
271
+    <configuration name="MyArrayListTest.removeTestp2" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
229 272
       <module name="generics" />
230 273
       <option name="PACKAGE_NAME" value="" />
231
-      <option name="MAIN_CLASS_NAME" value="ProgramTest" />
232
-      <option name="METHOD_NAME" value="TestCase4" />
274
+      <option name="MAIN_CLASS_NAME" value="MyArrayListTest" />
275
+      <option name="METHOD_NAME" value="removeTestp2" />
233 276
       <option name="TEST_OBJECT" value="method" />
234 277
       <method v="2">
235 278
         <option name="Make" enabled="true" />
236 279
       </method>
237 280
     </configuration>
238 281
     <list>
239
-      <item itemvalue="JUnit.ProgramTest.TestCase4" />
240 282
       <item itemvalue="JUnit.MyArrayListTest.addTest" />
241 283
       <item itemvalue="JUnit.MyArrayListTest.getTest" />
284
+      <item itemvalue="JUnit.MyArrayListTest.removeTest" />
285
+      <item itemvalue="JUnit.MyArrayListTest.removeTestp2" />
286
+      <item itemvalue="JUnit.MyArrayListTest" />
242 287
     </list>
243 288
     <recent_temporary>
244 289
       <list>
290
+        <item itemvalue="JUnit.MyArrayListTest" />
291
+        <item itemvalue="JUnit.MyArrayListTest.removeTestp2" />
292
+        <item itemvalue="JUnit.MyArrayListTest.removeTest" />
245 293
         <item itemvalue="JUnit.MyArrayListTest.getTest" />
246 294
         <item itemvalue="JUnit.MyArrayListTest.addTest" />
247
-        <item itemvalue="JUnit.ProgramTest.TestCase4" />
248 295
       </list>
249 296
     </recent_temporary>
250 297
   </component>
@@ -259,51 +306,57 @@
259 306
       <option name="presentableId" value="Default" />
260 307
       <updated>1542726854451</updated>
261 308
       <workItem from="1542726855981" duration="2759000" />
262
-      <workItem from="1542732517986" duration="5710000" />
309
+      <workItem from="1542732517986" duration="11755000" />
263 310
     </task>
264 311
     <servers />
265 312
   </component>
266 313
   <component name="TestHistory">
267
-    <history-entry file="ProgramTest_TestCase4 - 2018.11.20 at 12h 02m 04s.xml">
268
-      <configuration name="ProgramTest.TestCase4" configurationId="JUnit" />
314
+    <history-entry file="MyArrayListTest_removeTest - 2018.11.21 at 11h 45m 42s.xml">
315
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
269 316
     </history-entry>
270
-    <history-entry file="ProgramTest_TestCase4 - 2018.11.20 at 12h 03m 00s.xml">
271
-      <configuration name="ProgramTest.TestCase4" configurationId="JUnit" />
317
+    <history-entry file="MyArrayListTest_removeTest - 2018.11.21 at 11h 46m 35s.xml">
318
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
272 319
     </history-entry>
273
-    <history-entry file="ProgramTest_TestCase4 - 2018.11.20 at 12h 03m 16s.xml">
274
-      <configuration name="ProgramTest.TestCase4" configurationId="JUnit" />
320
+    <history-entry file="MyArrayListTest_removeTest - 2018.11.21 at 11h 48m 26s.xml">
321
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
275 322
     </history-entry>
276
-    <history-entry file="ProgramTest_TestCase4 - 2018.11.20 at 12h 03m 44s.xml">
277
-      <configuration name="ProgramTest.TestCase4" configurationId="JUnit" />
323
+    <history-entry file="MyArrayListTest_removeTest - 2018.11.21 at 11h 48m 34s.xml">
324
+      <configuration name="MyArrayListTest.removeTest" configurationId="JUnit" />
278 325
     </history-entry>
279
-    <history-entry file="MyArrayListTest_addTest - 2018.11.20 at 16h 28m 00s.xml">
280
-      <configuration name="MyArrayListTest.addTest" configurationId="JUnit" />
326
+    <history-entry file="MyArrayListTest_removeTestp2 - 2018.11.21 at 11h 49m 14s.xml">
327
+      <configuration name="MyArrayListTest.removeTestp2" configurationId="JUnit" />
281 328
     </history-entry>
282
-    <history-entry file="MyArrayListTest_addTest - 2018.11.20 at 16h 46m 30s.xml">
283
-      <configuration name="MyArrayListTest.addTest" configurationId="JUnit" />
329
+    <history-entry file="MyArrayListTest_removeTestp2 - 2018.11.21 at 11h 49m 55s.xml">
330
+      <configuration name="MyArrayListTest.removeTestp2" configurationId="JUnit" />
284 331
     </history-entry>
285
-    <history-entry file="MyArrayListTest_addTest - 2018.11.20 at 16h 53m 18s.xml">
286
-      <configuration name="MyArrayListTest.addTest" configurationId="JUnit" />
332
+    <history-entry file="MyArrayListTest_removeTestp2 - 2018.11.21 at 11h 50m 15s.xml">
333
+      <configuration name="MyArrayListTest.removeTestp2" configurationId="JUnit" />
287 334
     </history-entry>
288
-    <history-entry file="MyArrayListTest_addTest - 2018.11.20 at 16h 53m 39s.xml">
289
-      <configuration name="MyArrayListTest.addTest" configurationId="JUnit" />
335
+    <history-entry file="MyArrayListTest_removeTestp2 - 2018.11.21 at 11h 51m 05s.xml">
336
+      <configuration name="MyArrayListTest.removeTestp2" configurationId="JUnit" />
337
+    </history-entry>
338
+    <history-entry file="MyArrayListTest_removeTestp2 - 2018.11.21 at 11h 53m 20s.xml">
339
+      <configuration name="MyArrayListTest.removeTestp2" configurationId="JUnit" />
340
+    </history-entry>
341
+    <history-entry file="MyArrayListTest - 2018.11.21 at 11h 54m 08s.xml">
342
+      <configuration name="MyArrayListTest" configurationId="JUnit" />
290 343
     </history-entry>
291 344
   </component>
292 345
   <component name="TimeTrackingManager">
293
-    <option name="totallyTimeSpent" value="8469000" />
346
+    <option name="totallyTimeSpent" value="14514000" />
294 347
   </component>
295 348
   <component name="ToolWindowManager">
296 349
     <frame x="654" y="-1057" width="960" height="1057" extended-state="0" />
297 350
     <editor active="true" />
298 351
     <layout>
299
-      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25381264" />
352
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.0" />
300 353
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
301 354
       <window_info id="Image Layers" order="2" />
302 355
       <window_info id="Designer" order="3" />
303 356
       <window_info id="UI Designer" order="4" />
304 357
       <window_info id="Capture Tool" order="5" />
305 358
       <window_info id="Favorites" order="6" side_tool="true" />
306
-      <window_info anchor="bottom" id="Messages" />
359
+      <window_info anchor="bottom" id="Messages" weight="0.32938856" />
307 360
       <window_info anchor="bottom" id="Message" order="0" />
308 361
       <window_info anchor="bottom" id="Find" order="1" visible="true" weight="0.4660767" />
309 362
       <window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.22287968" />
@@ -315,7 +368,7 @@
315 368
       <window_info anchor="bottom" id="Terminal" order="8" />
316 369
       <window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
317 370
       <window_info anchor="bottom" id="Version Control" order="10" show_stripe_button="false" />
318
-      <window_info anchor="right" id="Coverage" side_tool="true" weight="0.2211329" />
371
+      <window_info active="true" anchor="right" id="Coverage" side_tool="true" visible="true" weight="0.56971675" />
319 372
       <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
320 373
       <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
321 374
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@@ -362,29 +415,43 @@
362 415
         </state>
363 416
       </provider>
364 417
     </entry>
365
-    <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
418
+    <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/src.zip!/java/util/AbstractList.java">
366 419
       <provider selected="true" editor-type-id="text-editor">
367
-        <state relative-caret-position="299">
368
-          <caret line="20" column="32" selection-start-line="20" selection-start-column="32" selection-end-line="20" selection-end-column="32" />
420
+        <state relative-caret-position="286">
421
+          <caret line="170" column="71" selection-start-line="170" selection-start-column="71" selection-end-line="170" selection-end-column="71" />
369 422
           <folding>
370
-            <element signature="e#120#121#0" expanded="true" />
371
-            <element signature="e#162#163#0" expanded="true" />
372
-            <element signature="e#784#785#0" expanded="true" />
373
-            <element signature="e#816#817#0" expanded="true" />
423
+            <element signature="e#5343#5344#0" expanded="true" />
424
+            <element signature="e#5400#5401#0" expanded="true" />
374 425
           </folding>
375 426
         </state>
376 427
       </provider>
377 428
     </entry>
378 429
     <entry file="file://$PROJECT_DIR$/src/test/java/MyArrayListTest.java">
379 430
       <provider selected="true" editor-type-id="text-editor">
380
-        <state relative-caret-position="540">
381
-          <caret line="36" column="5" lean-forward="true" selection-start-line="36" selection-start-column="5" selection-end-line="36" selection-end-column="5" />
431
+        <state relative-caret-position="855">
432
+          <caret line="57" column="38" lean-forward="true" selection-start-line="57" selection-start-column="38" selection-end-line="57" selection-end-column="38" />
382 433
           <folding>
383 434
             <element signature="imports" expanded="true" />
384 435
           </folding>
385 436
         </state>
386 437
       </provider>
387 438
     </entry>
439
+    <entry file="file://$PROJECT_DIR$/src/main/java/MyArrayList.java">
440
+      <provider selected="true" editor-type-id="text-editor">
441
+        <state relative-caret-position="1320">
442
+          <caret line="88" column="11" selection-start-line="88" selection-start-column="11" selection-end-line="88" selection-end-column="11" />
443
+          <folding>
444
+            <element signature="imports" expanded="true" />
445
+            <element signature="e#120#121#0" expanded="true" />
446
+            <element signature="e#162#163#0" expanded="true" />
447
+            <element signature="e#461#491#0" expanded="true" />
448
+            <element signature="e#682#712#0" expanded="true" />
449
+            <element signature="e#1525#1526#0" expanded="true" />
450
+            <element signature="e#1557#1558#0" expanded="true" />
451
+          </folding>
452
+        </state>
453
+      </provider>
454
+    </entry>
388 455
   </component>
389 456
   <component name="masterDetails">
390 457
     <states>

+ 30
- 0
src/main/java/MyArrayList.java Просмотреть файл

@@ -1,3 +1,4 @@
1
+import java.util.ArrayList;
1 2
 import java.util.Arrays;
2 3
 
3 4
 public class MyArrayList <T> {
@@ -22,19 +23,48 @@ public class MyArrayList <T> {
22 23
 
23 24
     }
24 25
 
26
+    @SuppressWarnings("unchecked")
25 27
     public void remove(int index){
26 28
 
29
+        int counter = 0;
30
+        T[] newArray = Arrays.copyOf(container, container.length - 1);
31
+
32
+        for (T val: container)
33
+        {
34
+            if (!val.equals(container[index])){
35
+            newArray[counter] = val;
36
+            counter++;
37
+        }
38
+
39
+        }
40
+
41
+        container = newArray;
27 42
 
28 43
     }
29 44
 
45
+    @SuppressWarnings("unchecked")
30 46
     public void remove(T val){
31 47
 
48
+        int counter = 0;
49
+        T[] newArray = Arrays.copyOf(container, container.length - 1);
50
+
51
+        for (T value: container)
52
+        {
53
+            if (!value.equals(val)){
54
+                newArray[counter] = value;
55
+                counter++;
56
+            }
57
+        }
58
+
59
+        container = newArray;
32 60
 
33 61
     }
34 62
 
63
+
35 64
     public void set(int index, T val){
36 65
 
37 66
 
67
+
38 68
     }
39 69
 
40 70
     public void clear(){

+ 24
- 0
src/test/java/MyArrayListTest.java Просмотреть файл

@@ -2,6 +2,8 @@ import org.junit.Assert;
2 2
 import org.junit.Before;
3 3
 import org.junit.Test;
4 4
 
5
+import java.util.Arrays;
6
+
5 7
 public class MyArrayListTest {
6 8
 
7 9
     MyArrayList<String> list;
@@ -36,4 +38,26 @@ public class MyArrayListTest {
36 38
 
37 39
     }
38 40
 
41
+    @Test
42
+    public void removeTest(){
43
+
44
+            //Assert
45
+            list.add("world");
46
+            list.remove(0);
47
+            String[] expected = {"world"};
48
+            Assert.assertArrayEquals(expected, list.getter());
49
+
50
+    }
51
+
52
+    @Test
53
+    public void removeTestp2(){
54
+
55
+        //Assert
56
+        list.add("world");
57
+        list.remove("hello");
58
+        String[] expected = {"world"};
59
+        Assert.assertArrayEquals(expected, list.getter());
60
+
61
+    }
62
+
39 63
 }