Browse Source

remove element

Seth 6 years ago
parent
commit
aac969f38d

+ 1
- 1
.idea/ArraysGoneWild.iml View File

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <module type="JAVA_MODULE" version="4">
3
-  <component name="NewModuleRootManager" inherit-compiler-output="true">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
4 4
     <exclude-output />
5 5
     <content url="file://$MODULE_DIR$" />
6 6
     <orderEntry type="inheritedJdk" />

+ 1
- 1
.idea/compiler.xml View File

@@ -10,7 +10,7 @@
10 10
       </profile>
11 11
     </annotationProcessing>
12 12
     <bytecodeTargetLevel>
13
-      <module name="arraz" target="1.5" />
13
+      <module name="arraz" target="8" />
14 14
     </bytecodeTargetLevel>
15 15
   </component>
16 16
 </project>

+ 1
- 0
.idea/misc.xml View File

@@ -7,4 +7,5 @@
7 7
       </list>
8 8
     </option>
9 9
   </component>
10
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
10 11
 </project>

+ 52
- 54
.idea/workspace.xml View File

@@ -2,6 +2,9 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="3455511b-a100-4bbd-b07c-68f009bc8dbc" name="Default" comment="">
5
+      <change beforePath="$PROJECT_DIR$/.idea/ArraysGoneWild.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/ArraysGoneWild.iml" afterDir="false" />
6
+      <change beforePath="$PROJECT_DIR$/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
7
+      <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
5 8
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6 9
       <change beforePath="$PROJECT_DIR$/arraz/src/main/java/Arraz.java" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/src/main/java/Arraz.java" afterDir="false" />
7 10
       <change beforePath="$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java" afterDir="false" />
@@ -23,13 +26,13 @@
23 26
       </usages-collector>
24 27
       <usages-collector id="statistics.file.types.edit">
25 28
         <counts>
26
-          <entry key="JAVA" value="4128" />
29
+          <entry key="JAVA" value="5174" />
27 30
           <entry key="XML" value="3" />
28 31
         </counts>
29 32
       </usages-collector>
30 33
       <usages-collector id="statistics.file.types.open">
31 34
         <counts>
32
-          <entry key="JAVA" value="1" />
35
+          <entry key="JAVA" value="2" />
33 36
           <entry key="XML" value="1" />
34 37
         </counts>
35 38
       </usages-collector>
@@ -38,26 +41,24 @@
38 41
   <component name="FileEditorManager">
39 42
     <leaf SIDE_TABS_SIZE_LIMIT_KEY="375">
40 43
       <file pinned="false" current-in-tab="false">
41
-        <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
44
+        <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
42 45
           <provider selected="true" editor-type-id="text-editor">
43
-            <state relative-caret-position="285">
44
-              <caret line="79" column="24" selection-start-line="79" selection-start-column="24" selection-end-line="79" selection-end-column="24" />
46
+            <state relative-caret-position="-902">
47
+              <caret line="109" column="50" selection-start-line="109" selection-start-column="50" selection-end-line="109" selection-end-column="50" />
45 48
               <folding>
46 49
                 <element signature="imports" expanded="true" />
47
-                <element signature="e#399#400#0" expanded="true" />
48
-                <element signature="e#451#452#0" expanded="true" />
49
-                <element signature="e#515#516#0" expanded="true" />
50
-                <element signature="e#556#557#0" expanded="true" />
50
+                <element signature="e#4388#4389#0" expanded="true" />
51
+                <element signature="e#4411#4412#0" expanded="true" />
51 52
               </folding>
52 53
             </state>
53 54
           </provider>
54 55
         </entry>
55 56
       </file>
56 57
       <file pinned="false" current-in-tab="true">
57
-        <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
58
+        <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
58 59
           <provider selected="true" editor-type-id="text-editor">
59
-            <state relative-caret-position="313">
60
-              <caret line="161" column="49" selection-start-line="161" selection-start-column="49" selection-end-line="161" selection-end-column="49" />
60
+            <state relative-caret-position="343">
61
+              <caret line="103" lean-forward="true" selection-start-line="103" selection-end-line="103" />
61 62
               <folding>
62 63
                 <element signature="imports" expanded="true" />
63 64
               </folding>
@@ -81,7 +82,7 @@
81 82
         <entry file="file://$PROJECT_DIR$/arraz/src/main/java/OddEven.java">
82 83
           <provider selected="true" editor-type-id="text-editor">
83 84
             <state>
84
-              <caret column="22" lean-forward="true" selection-start-column="22" selection-end-column="22" />
85
+              <caret column="22" selection-start-column="22" selection-end-column="22" />
85 86
               <folding>
86 87
                 <element signature="e#189#190#0" expanded="true" />
87 88
                 <element signature="e#215#216#0" expanded="true" />
@@ -208,15 +209,15 @@
208 209
     <property name="GO_FMT" value="false" />
209 210
     <property name="WebServerToolWindowFactoryState" value="false" />
210 211
     <property name="aspect.path.notification.shown" value="true" />
211
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544103261992" />
212
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544126310211" />
212 213
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="JUnit4" />
213 214
     <property name="jdk.selected.JAVA_MODULE" value="1.8" />
214 215
     <property name="last_opened_file_path" value="$PROJECT_DIR$" />
215 216
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
216
-    <property name="project.structure.last.edited" value="Modules" />
217
-    <property name="project.structure.proportion" value="0.0" />
218
-    <property name="project.structure.side.proportion" value="0.0" />
219
-    <property name="settings.editor.selected.configurable" value="configurable.group.appearance" />
217
+    <property name="project.structure.last.edited" value="Project" />
218
+    <property name="project.structure.proportion" value="0.15" />
219
+    <property name="project.structure.side.proportion" value="0.2" />
220
+    <property name="settings.editor.selected.configurable" value="reference.projectsettings.compiler.javacompiler" />
220 221
   </component>
221 222
   <component name="RecentsManager">
222 223
     <key name="CreateTestDialog.RecentsKey">
@@ -238,7 +239,7 @@
238 239
       </list>
239 240
     </option>
240 241
   </component>
241
-  <component name="RunManager" selected="JUnit.ArrazTest.testCopyArrayByIterator2">
242
+  <component name="RunManager" selected="JUnit.ArrazTest.testRemoveElementFromArray1">
242 243
     <configuration default="true" type="Applet" factoryName="Applet">
243 244
       <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
244 245
       <method v="2">
@@ -282,11 +283,11 @@
282 283
         <option name="Make" enabled="true" />
283 284
       </method>
284 285
     </configuration>
285
-    <configuration name="ArrazTest.testOddEvens2" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
286
+    <configuration name="ArrazTest.testRemoveElementFromArray1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
286 287
       <module name="arraz" />
287 288
       <option name="PACKAGE_NAME" value="" />
288 289
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
289
-      <option name="METHOD_NAME" value="testOddEvens2" />
290
+      <option name="METHOD_NAME" value="testRemoveElementFromArray1" />
290 291
       <option name="TEST_OBJECT" value="method" />
291 292
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
292 293
       <method v="2">
@@ -330,17 +331,17 @@
330 331
     <list>
331 332
       <item itemvalue="JUnit.ArrazTest" />
332 333
       <item itemvalue="JUnit.ArrazTest.testReverseArray1" />
333
-      <item itemvalue="JUnit.ArrazTest.testOddEvens2" />
334 334
       <item itemvalue="JUnit.ArrazTest.testCopyArrayByIterator1" />
335 335
       <item itemvalue="JUnit.ArrazTest.testCopyArrayByIterator2" />
336
+      <item itemvalue="JUnit.ArrazTest.testRemoveElementFromArray1" />
336 337
     </list>
337 338
     <recent_temporary>
338 339
       <list>
339
-        <item itemvalue="JUnit.ArrazTest.testCopyArrayByIterator2" />
340
-        <item itemvalue="JUnit.ArrazTest.testCopyArrayByIterator1" />
340
+        <item itemvalue="JUnit.ArrazTest.testRemoveElementFromArray1" />
341 341
         <item itemvalue="JUnit.ArrazTest" />
342 342
         <item itemvalue="JUnit.ArrazTest.testReverseArray1" />
343
-        <item itemvalue="JUnit.ArrazTest.testOddEvens2" />
343
+        <item itemvalue="JUnit.ArrazTest.testCopyArrayByIterator2" />
344
+        <item itemvalue="JUnit.ArrazTest.testCopyArrayByIterator1" />
344 345
       </list>
345 346
     </recent_temporary>
346 347
   </component>
@@ -357,7 +358,7 @@
357 358
       <workItem from="1543955862749" duration="2347000" />
358 359
       <workItem from="1543958998826" duration="113000" />
359 360
       <workItem from="1544020724645" duration="762000" />
360
-      <workItem from="1544046933389" duration="9103000" />
361
+      <workItem from="1544046933389" duration="12355000" />
361 362
     </task>
362 363
     <task id="LOCAL-00001" summary="readme and docs">
363 364
       <created>1544021313039</created>
@@ -370,21 +371,6 @@
370 371
     <servers />
371 372
   </component>
372 373
   <component name="TestHistory">
373
-    <history-entry file="ArrazTest_testReverseArray1 - 2018.12.05 at 19h 49m 37s.xml">
374
-      <configuration name="ArrazTest.testReverseArray1" configurationId="JUnit" />
375
-    </history-entry>
376
-    <history-entry file="ArrazTest_testReverseArray1 - 2018.12.05 at 19h 51m 09s.xml">
377
-      <configuration name="ArrazTest.testReverseArray1" configurationId="JUnit" />
378
-    </history-entry>
379
-    <history-entry file="ArrazTest - 2018.12.05 at 20h 13m 00s.xml">
380
-      <configuration name="ArrazTest" configurationId="JUnit" />
381
-    </history-entry>
382
-    <history-entry file="ArrazTest_testOddEvens1 - 2018.12.05 at 20h 13m 40s.xml">
383
-      <configuration name="ArrazTest.testOddEvens1" configurationId="JUnit" />
384
-    </history-entry>
385
-    <history-entry file="ArrazTest_testOddEvens2 - 2018.12.05 at 20h 14m 01s.xml">
386
-      <configuration name="ArrazTest.testOddEvens2" configurationId="JUnit" />
387
-    </history-entry>
388 374
     <history-entry file="ArrazTest - 2018.12.05 at 20h 14m 10s.xml">
389 375
       <configuration name="ArrazTest" configurationId="JUnit" />
390 376
     </history-entry>
@@ -400,13 +386,27 @@
400 386
     <history-entry file="ArrazTest - 2018.12.06 at 08h 17m 38s.xml">
401 387
       <configuration name="ArrazTest" configurationId="JUnit" />
402 388
     </history-entry>
389
+    <history-entry file="ArrazTest_testCopyArrayByIterator1 - 2018.12.06 at 08h 34m 19s.xml">
390
+      <configuration name="ArrazTest.testCopyArrayByIterator1" configurationId="JUnit" />
391
+    </history-entry>
392
+    <history-entry file="ArrazTest_testCopyArrayByIterator2 - 2018.12.06 at 08h 34m 23s.xml">
393
+      <configuration name="ArrazTest.testCopyArrayByIterator2" configurationId="JUnit" />
394
+    </history-entry>
395
+    <history-entry file="ArrazTest - 2018.12.06 at 13h 17m 56s.xml">
396
+      <configuration name="ArrazTest" configurationId="JUnit" />
397
+    </history-entry>
398
+    <history-entry file="ArrazTest_testReverseArray1 - 2018.12.06 at 14h 52m 25s.xml">
399
+      <configuration name="ArrazTest.testReverseArray1" configurationId="JUnit" />
400
+    </history-entry>
401
+    <history-entry file="ArrazTest - 2018.12.06 at 14h 53m 48s.xml">
402
+      <configuration name="ArrazTest" configurationId="JUnit" />
403
+    </history-entry>
403 404
   </component>
404 405
   <component name="TimeTrackingManager">
405
-    <option name="totallyTimeSpent" value="12325000" />
406
+    <option name="totallyTimeSpent" value="15577000" />
406 407
   </component>
407 408
   <component name="ToolWindowManager">
408 409
     <frame x="0" y="23" width="1440" height="807" extended-state="6" />
409
-    <editor active="true" />
410 410
     <layout>
411 411
       <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.26108727" />
412 412
       <window_info id="Structure" order="1" weight="0.25" />
@@ -459,7 +459,7 @@
459 459
     <entry file="file://$PROJECT_DIR$/arraz/src/main/java/OddEven.java">
460 460
       <provider selected="true" editor-type-id="text-editor">
461 461
         <state>
462
-          <caret column="22" lean-forward="true" selection-start-column="22" selection-end-column="22" />
462
+          <caret column="22" selection-start-column="22" selection-end-column="22" />
463 463
           <folding>
464 464
             <element signature="e#189#190#0" expanded="true" />
465 465
             <element signature="e#215#216#0" expanded="true" />
@@ -479,24 +479,22 @@
479 479
         </state>
480 480
       </provider>
481 481
     </entry>
482
-    <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
482
+    <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
483 483
       <provider selected="true" editor-type-id="text-editor">
484
-        <state relative-caret-position="285">
485
-          <caret line="79" column="24" selection-start-line="79" selection-start-column="24" selection-end-line="79" selection-end-column="24" />
484
+        <state relative-caret-position="-902">
485
+          <caret line="109" column="50" selection-start-line="109" selection-start-column="50" selection-end-line="109" selection-end-column="50" />
486 486
           <folding>
487 487
             <element signature="imports" expanded="true" />
488
-            <element signature="e#399#400#0" expanded="true" />
489
-            <element signature="e#451#452#0" expanded="true" />
490
-            <element signature="e#515#516#0" expanded="true" />
491
-            <element signature="e#556#557#0" expanded="true" />
488
+            <element signature="e#4388#4389#0" expanded="true" />
489
+            <element signature="e#4411#4412#0" expanded="true" />
492 490
           </folding>
493 491
         </state>
494 492
       </provider>
495 493
     </entry>
496
-    <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
494
+    <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
497 495
       <provider selected="true" editor-type-id="text-editor">
498
-        <state relative-caret-position="313">
499
-          <caret line="161" column="49" selection-start-line="161" selection-start-column="49" selection-end-line="161" selection-end-column="49" />
496
+        <state relative-caret-position="343">
497
+          <caret line="103" lean-forward="true" selection-start-line="103" selection-end-line="103" />
500 498
           <folding>
501 499
             <element signature="imports" expanded="true" />
502 500
           </folding>

+ 23
- 3
arraz/src/main/java/Arraz.java View File

@@ -72,12 +72,32 @@ public class Arraz {
72 72
     public Integer[] copyArrayByIterator(Integer[] array){
73 73
         Integer[] newArray = new Integer[array.length];
74 74
         int index = 0;
75
-        Iterator<Integer> iterator = Arrays.asList(array).iterator();
76
-        while(iterator.hasNext()){
77
-            newArray[index] = iterator.next();
75
+        for (Integer integer : Arrays.asList(array)) {
76
+            newArray[index] = integer;
78 77
             index++;
79 78
         }
80 79
         return newArray;
81 80
         }
82 81
 
82
+    public int[] copyArrayByLoop(int[] array){
83
+        int[] newArray = new int[array.length];
84
+        int index = 0;
85
+        for(int each:array){
86
+            newArray[index] = each;
87
+            index++;
88
+        }
89
+        return newArray;
90
+    }
91
+
92
+    public int[] removeElementFromArray(int[] array, int value){
93
+        int[] newArray = new int[array.length -1];
94
+        int index = 0;
95
+        for (int each:array) {
96
+            if(each!=value){
97
+                newArray[index] =each;
98
+                index++;
99
+            }
100
+        }
101
+        return newArray;
83 102
     }
103
+}

+ 30
- 1
arraz/src/test/java/ArrazTest.java View File

@@ -107,7 +107,7 @@ public class ArrazTest {
107 107
         int[] expected =new int[]{100, 29, 3, 10, 5};
108 108
         int[] actual = testArraz.reverseArray(arr1);
109 109
 
110
-        Assert.assertTrue(Arrays.equals(expected, actual));
110
+        Assert.assertArrayEquals(expected, actual);
111 111
     }
112 112
 
113 113
     @Test
@@ -161,4 +161,33 @@ public class ArrazTest {
161 161
 
162 162
         Assert.assertArrayEquals(expected, actual);
163 163
     }
164
+
165
+    @Test
166
+    public void testCopyArrayByLoop1(){
167
+        int[] expected = arr1;
168
+        int[] actual = testArraz.copyArrayByLoop(arr1);
169
+
170
+        Assert.assertArrayEquals(expected, actual);
171
+    }
172
+
173
+    @Test
174
+    public void testCopyArrayByLoop2(){
175
+        Assert.assertFalse(Arrays.equals(arr1, testArraz.copyArrayByLoop(arr2)));
176
+    }
177
+
178
+    @Test
179
+    public void testRemoveElementFromArray1(){
180
+        int[] expected = new int[]{5, 10, 29, 100};
181
+        int[] actual = testArraz.removeElementFromArray(arr1, 3);
182
+
183
+        Assert.assertArrayEquals(expected, actual);
184
+    }
185
+
186
+    @Test
187
+    public void testRemoveElementFromArray2(){
188
+        int[] expected = new int[]{2, 7, 89};
189
+        int[] actual = testArraz.removeElementFromArray(arr2, 432);
190
+
191
+        Assert.assertArrayEquals(expected, actual);
192
+    }
164 193
 }