Bläddra i källkod

updating arrays

Whitney Martinez 6 år sedan
förälder
incheckning
0aa64e1ef8

+ 42
- 45
arraz/.idea/workspace.xml Visa fil

3
   <component name="ChangeListManager">
3
   <component name="ChangeListManager">
4
     <list default="true" id="88ea8df4-5dbc-49b8-b3df-2eb51cffc0b3" name="Default Changelist" comment="">
4
     <list default="true" id="88ea8df4-5dbc-49b8-b3df-2eb51cffc0b3" name="Default Changelist" comment="">
5
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
5
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6
-      <change beforePath="$PROJECT_DIR$/src/main/java/Arraz.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Arraz.java" afterDir="false" />
7
-      <change beforePath="$PROJECT_DIR$/src/main/java/MinMax1.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/MinMax1.java" afterDir="false" />
8
-      <change beforePath="$PROJECT_DIR$/src/main/java/MoreArrayc.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/MoreArrayc.java" afterDir="false" />
9
       <change beforePath="$PROJECT_DIR$/src/test/java/MoreArraysTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/MoreArraysTest.java" afterDir="false" />
6
       <change beforePath="$PROJECT_DIR$/src/test/java/MoreArraysTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/MoreArraysTest.java" afterDir="false" />
10
     </list>
7
     </list>
11
     <ignored path="$PROJECT_DIR$/target/" />
8
     <ignored path="$PROJECT_DIR$/target/" />
39
       </usages-collector>
36
       </usages-collector>
40
       <usages-collector id="statistics.file.extensions.edit">
37
       <usages-collector id="statistics.file.extensions.edit">
41
         <counts>
38
         <counts>
42
-          <entry key="java" value="12122" />
39
+          <entry key="java" value="12335" />
43
         </counts>
40
         </counts>
44
       </usages-collector>
41
       </usages-collector>
45
       <usages-collector id="statistics.file.types.edit">
42
       <usages-collector id="statistics.file.types.edit">
46
         <counts>
43
         <counts>
47
-          <entry key="JAVA" value="12122" />
44
+          <entry key="JAVA" value="12335" />
48
         </counts>
45
         </counts>
49
       </usages-collector>
46
       </usages-collector>
50
     </session>
47
     </session>
54
       <file pinned="false" current-in-tab="false">
51
       <file pinned="false" current-in-tab="false">
55
         <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
52
         <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
56
           <provider selected="true" editor-type-id="text-editor">
53
           <provider selected="true" editor-type-id="text-editor">
57
-            <state relative-caret-position="248">
58
-              <caret line="115" selection-start-line="115" selection-end-line="115" />
54
+            <state relative-caret-position="172">
55
+              <caret line="113" column="5" lean-forward="true" selection-start-line="113" selection-start-column="5" selection-end-line="113" selection-end-column="5" />
59
             </state>
56
             </state>
60
           </provider>
57
           </provider>
61
         </entry>
58
         </entry>
63
       <file pinned="false" current-in-tab="true">
60
       <file pinned="false" current-in-tab="true">
64
         <entry file="file://$PROJECT_DIR$/src/test/java/MoreArraysTest.java">
61
         <entry file="file://$PROJECT_DIR$/src/test/java/MoreArraysTest.java">
65
           <provider selected="true" editor-type-id="text-editor">
62
           <provider selected="true" editor-type-id="text-editor">
66
-            <state relative-caret-position="259">
67
-              <caret line="302" lean-forward="true" selection-start-line="299" selection-start-column="8" selection-end-line="302" />
63
+            <state relative-caret-position="463">
64
+              <caret line="310" column="5" selection-start-line="310" selection-start-column="5" selection-end-line="310" selection-end-column="5" />
68
               <folding>
65
               <folding>
69
                 <element signature="imports" expanded="true" />
66
                 <element signature="imports" expanded="true" />
70
               </folding>
67
               </folding>
75
       <file pinned="false" current-in-tab="false">
72
       <file pinned="false" current-in-tab="false">
76
         <entry file="file://$PROJECT_DIR$/src/main/java/MoreArrayc.java">
73
         <entry file="file://$PROJECT_DIR$/src/main/java/MoreArrayc.java">
77
           <provider selected="true" editor-type-id="text-editor">
74
           <provider selected="true" editor-type-id="text-editor">
78
-            <state relative-caret-position="185">
75
+            <state relative-caret-position="-36">
79
               <caret line="194" column="20" selection-start-line="194" selection-start-column="20" selection-end-line="194" selection-end-column="20" />
76
               <caret line="194" column="20" selection-start-line="194" selection-start-column="20" selection-end-line="194" selection-end-column="20" />
80
               <folding>
77
               <folding>
81
                 <element signature="imports" expanded="true" />
78
                 <element signature="imports" expanded="true" />
135
     <sorting>DEFINITION_ORDER</sorting>
132
     <sorting>DEFINITION_ORDER</sorting>
136
   </component>
133
   </component>
137
   <component name="ProjectFrameBounds">
134
   <component name="ProjectFrameBounds">
138
-    <option name="x" value="370" />
139
-    <option name="y" value="23" />
135
+    <option name="x" value="156" />
136
+    <option name="y" value="42" />
140
     <option name="width" value="991" />
137
     <option name="width" value="991" />
141
     <option name="height" value="709" />
138
     <option name="height" value="709" />
142
   </component>
139
   </component>
200
   <component name="PropertiesComponent">
197
   <component name="PropertiesComponent">
201
     <property name="WebServerToolWindowFactoryState" value="false" />
198
     <property name="WebServerToolWindowFactoryState" value="false" />
202
     <property name="aspect.path.notification.shown" value="true" />
199
     <property name="aspect.path.notification.shown" value="true" />
203
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544354306691" />
200
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544365477796" />
204
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
201
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
205
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
202
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
206
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
203
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
217
       </list>
214
       </list>
218
     </option>
215
     </option>
219
   </component>
216
   </component>
220
-  <component name="RunManager" selected="JUnit.MoreArraysTest.insertFirstThenCopyTEST">
217
+  <component name="RunManager" selected="JUnit.MoreArraysTest.insertLastThenCopyTEST">
221
     <configuration name="MoreArraysTest.insertFirstThenCopyTEST" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
218
     <configuration name="MoreArraysTest.insertFirstThenCopyTEST" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
222
       <module name="arraz" />
219
       <module name="arraz" />
223
       <option name="PACKAGE_NAME" value="" />
220
       <option name="PACKAGE_NAME" value="" />
228
         <option name="Make" enabled="true" />
225
         <option name="Make" enabled="true" />
229
       </method>
226
       </method>
230
     </configuration>
227
     </configuration>
231
-    <configuration name="MoreArraysTest.makeMeACopyPleaseTEST" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
228
+    <configuration name="MoreArraysTest.insertLastThenCopyTEST" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
232
       <module name="arraz" />
229
       <module name="arraz" />
233
       <option name="PACKAGE_NAME" value="" />
230
       <option name="PACKAGE_NAME" value="" />
234
       <option name="MAIN_CLASS_NAME" value="MoreArraysTest" />
231
       <option name="MAIN_CLASS_NAME" value="MoreArraysTest" />
235
-      <option name="METHOD_NAME" value="makeMeACopyPleaseTEST" />
232
+      <option name="METHOD_NAME" value="insertLastThenCopyTEST" />
236
       <option name="TEST_OBJECT" value="method" />
233
       <option name="TEST_OBJECT" value="method" />
237
       <method v="2">
234
       <method v="2">
238
         <option name="Make" enabled="true" />
235
         <option name="Make" enabled="true" />
239
       </method>
236
       </method>
240
     </configuration>
237
     </configuration>
241
-    <configuration name="MoreArraysTest.removeFirstThenCopy" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
238
+    <configuration name="MoreArraysTest.insertfirstThenCopyTEST" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
242
       <module name="arraz" />
239
       <module name="arraz" />
243
       <option name="PACKAGE_NAME" value="" />
240
       <option name="PACKAGE_NAME" value="" />
244
       <option name="MAIN_CLASS_NAME" value="MoreArraysTest" />
241
       <option name="MAIN_CLASS_NAME" value="MoreArraysTest" />
245
-      <option name="METHOD_NAME" value="removeFirstThenCopy" />
242
+      <option name="METHOD_NAME" value="insertfirstThenCopyTEST" />
246
       <option name="TEST_OBJECT" value="method" />
243
       <option name="TEST_OBJECT" value="method" />
247
       <method v="2">
244
       <method v="2">
248
         <option name="Make" enabled="true" />
245
         <option name="Make" enabled="true" />
249
       </method>
246
       </method>
250
     </configuration>
247
     </configuration>
251
-    <configuration name="MoreArraysTest.removeLastThenCopy" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
248
+    <configuration name="MoreArraysTest.removeFirstThenCopy" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
252
       <module name="arraz" />
249
       <module name="arraz" />
253
       <option name="PACKAGE_NAME" value="" />
250
       <option name="PACKAGE_NAME" value="" />
254
       <option name="MAIN_CLASS_NAME" value="MoreArraysTest" />
251
       <option name="MAIN_CLASS_NAME" value="MoreArraysTest" />
255
-      <option name="METHOD_NAME" value="removeLastThenCopy" />
252
+      <option name="METHOD_NAME" value="removeFirstThenCopy" />
256
       <option name="TEST_OBJECT" value="method" />
253
       <option name="TEST_OBJECT" value="method" />
257
       <method v="2">
254
       <method v="2">
258
         <option name="Make" enabled="true" />
255
         <option name="Make" enabled="true" />
259
       </method>
256
       </method>
260
     </configuration>
257
     </configuration>
261
-    <configuration name="MoreArraysTest.sumOfTensLookingFor30FAIL" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
258
+    <configuration name="MoreArraysTest.removeLastThenCopy" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
262
       <module name="arraz" />
259
       <module name="arraz" />
263
       <option name="PACKAGE_NAME" value="" />
260
       <option name="PACKAGE_NAME" value="" />
264
       <option name="MAIN_CLASS_NAME" value="MoreArraysTest" />
261
       <option name="MAIN_CLASS_NAME" value="MoreArraysTest" />
265
-      <option name="METHOD_NAME" value="sumOfTensLookingFor30FAIL" />
262
+      <option name="METHOD_NAME" value="removeLastThenCopy" />
266
       <option name="TEST_OBJECT" value="method" />
263
       <option name="TEST_OBJECT" value="method" />
267
       <method v="2">
264
       <method v="2">
268
         <option name="Make" enabled="true" />
265
         <option name="Make" enabled="true" />
269
       </method>
266
       </method>
270
     </configuration>
267
     </configuration>
271
     <list>
268
     <list>
272
-      <item itemvalue="JUnit.MoreArraysTest.sumOfTensLookingFor30FAIL" />
273
-      <item itemvalue="JUnit.MoreArraysTest.makeMeACopyPleaseTEST" />
274
       <item itemvalue="JUnit.MoreArraysTest.removeFirstThenCopy" />
269
       <item itemvalue="JUnit.MoreArraysTest.removeFirstThenCopy" />
275
       <item itemvalue="JUnit.MoreArraysTest.removeLastThenCopy" />
270
       <item itemvalue="JUnit.MoreArraysTest.removeLastThenCopy" />
276
       <item itemvalue="JUnit.MoreArraysTest.insertFirstThenCopyTEST" />
271
       <item itemvalue="JUnit.MoreArraysTest.insertFirstThenCopyTEST" />
272
+      <item itemvalue="JUnit.MoreArraysTest.insertfirstThenCopyTEST" />
273
+      <item itemvalue="JUnit.MoreArraysTest.insertLastThenCopyTEST" />
277
     </list>
274
     </list>
278
     <recent_temporary>
275
     <recent_temporary>
279
       <list>
276
       <list>
277
+        <item itemvalue="JUnit.MoreArraysTest.insertLastThenCopyTEST" />
278
+        <item itemvalue="JUnit.MoreArraysTest.insertfirstThenCopyTEST" />
280
         <item itemvalue="JUnit.MoreArraysTest.insertFirstThenCopyTEST" />
279
         <item itemvalue="JUnit.MoreArraysTest.insertFirstThenCopyTEST" />
281
         <item itemvalue="JUnit.MoreArraysTest.removeLastThenCopy" />
280
         <item itemvalue="JUnit.MoreArraysTest.removeLastThenCopy" />
282
         <item itemvalue="JUnit.MoreArraysTest.removeFirstThenCopy" />
281
         <item itemvalue="JUnit.MoreArraysTest.removeFirstThenCopy" />
283
-        <item itemvalue="JUnit.MoreArraysTest.makeMeACopyPleaseTEST" />
284
-        <item itemvalue="JUnit.MoreArraysTest.sumOfTensLookingFor30FAIL" />
285
       </list>
282
       </list>
286
     </recent_temporary>
283
     </recent_temporary>
287
   </component>
284
   </component>
295
       <option name="number" value="Default" />
292
       <option name="number" value="Default" />
296
       <option name="presentableId" value="Default" />
293
       <option name="presentableId" value="Default" />
297
       <updated>1544063273407</updated>
294
       <updated>1544063273407</updated>
298
-      <workItem from="1544063277559" duration="63264000" />
295
+      <workItem from="1544063277559" duration="64818000" />
299
     </task>
296
     </task>
300
     <servers />
297
     <servers />
301
   </component>
298
   </component>
302
   <component name="TestHistory">
299
   <component name="TestHistory">
303
-    <history-entry file="MoreArraysTest_removeFirstThenCopy - 2018.12.08 at 18h 59m 21s.xml">
304
-      <configuration name="MoreArraysTest.removeFirstThenCopy" configurationId="JUnit" />
305
-    </history-entry>
306
-    <history-entry file="MoreArraysTest_removeFirstThenCopy - 2018.12.08 at 18h 59m 51s.xml">
307
-      <configuration name="MoreArraysTest.removeFirstThenCopy" configurationId="JUnit" />
308
-    </history-entry>
309
     <history-entry file="MoreArraysTest_removeFirstThenCopy - 2018.12.08 at 19h 00m 03s.xml">
300
     <history-entry file="MoreArraysTest_removeFirstThenCopy - 2018.12.08 at 19h 00m 03s.xml">
310
       <configuration name="MoreArraysTest.removeFirstThenCopy" configurationId="JUnit" />
301
       <configuration name="MoreArraysTest.removeFirstThenCopy" configurationId="JUnit" />
311
     </history-entry>
302
     </history-entry>
330
     <history-entry file="MoreArraysTest_insertFirstThenCopyTEST - 2018.12.09 at 06h 09m 22s.xml">
321
     <history-entry file="MoreArraysTest_insertFirstThenCopyTEST - 2018.12.09 at 06h 09m 22s.xml">
331
       <configuration name="MoreArraysTest.insertFirstThenCopyTEST" configurationId="JUnit" />
322
       <configuration name="MoreArraysTest.insertFirstThenCopyTEST" configurationId="JUnit" />
332
     </history-entry>
323
     </history-entry>
324
+    <history-entry file="MoreArraysTest_insertFirstThenCopyTEST - 2018.12.09 at 09h 18m 26s.xml">
325
+      <configuration name="MoreArraysTest.insertFirstThenCopyTEST" configurationId="JUnit" />
326
+    </history-entry>
327
+    <history-entry file="MoreArraysTest_insertFirstThenCopyTEST - 2018.12.09 at 09h 18m 36s.xml">
328
+      <configuration name="MoreArraysTest.insertFirstThenCopyTEST" configurationId="JUnit" />
329
+    </history-entry>
333
   </component>
330
   </component>
334
   <component name="TimeTrackingManager">
331
   <component name="TimeTrackingManager">
335
-    <option name="totallyTimeSpent" value="63264000" />
332
+    <option name="totallyTimeSpent" value="64818000" />
336
   </component>
333
   </component>
337
   <component name="ToolWindowManager">
334
   <component name="ToolWindowManager">
338
-    <frame x="227" y="23" width="991" height="709" extended-state="0" />
335
+    <frame x="202" y="172" width="991" height="709" extended-state="0" />
339
     <editor active="true" />
336
     <editor active="true" />
340
     <layout>
337
     <layout>
341
       <window_info id="Image Layers" />
338
       <window_info id="Image Layers" />
479
         </state>
476
         </state>
480
       </provider>
477
       </provider>
481
     </entry>
478
     </entry>
482
-    <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
483
-      <provider selected="true" editor-type-id="text-editor">
484
-        <state relative-caret-position="248">
485
-          <caret line="115" selection-start-line="115" selection-end-line="115" />
486
-        </state>
487
-      </provider>
488
-    </entry>
489
     <entry file="file://$PROJECT_DIR$/src/main/java/MoreArrayc.java">
479
     <entry file="file://$PROJECT_DIR$/src/main/java/MoreArrayc.java">
490
       <provider selected="true" editor-type-id="text-editor">
480
       <provider selected="true" editor-type-id="text-editor">
491
-        <state relative-caret-position="185">
481
+        <state relative-caret-position="-36">
492
           <caret line="194" column="20" selection-start-line="194" selection-start-column="20" selection-end-line="194" selection-end-column="20" />
482
           <caret line="194" column="20" selection-start-line="194" selection-start-column="20" selection-end-line="194" selection-end-column="20" />
493
           <folding>
483
           <folding>
494
             <element signature="imports" expanded="true" />
484
             <element signature="imports" expanded="true" />
499
         </state>
489
         </state>
500
       </provider>
490
       </provider>
501
     </entry>
491
     </entry>
492
+    <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
493
+      <provider selected="true" editor-type-id="text-editor">
494
+        <state relative-caret-position="172">
495
+          <caret line="113" column="5" lean-forward="true" selection-start-line="113" selection-start-column="5" selection-end-line="113" selection-end-column="5" />
496
+        </state>
497
+      </provider>
498
+    </entry>
502
     <entry file="file://$PROJECT_DIR$/src/test/java/MoreArraysTest.java">
499
     <entry file="file://$PROJECT_DIR$/src/test/java/MoreArraysTest.java">
503
       <provider selected="true" editor-type-id="text-editor">
500
       <provider selected="true" editor-type-id="text-editor">
504
-        <state relative-caret-position="259">
505
-          <caret line="302" lean-forward="true" selection-start-line="299" selection-start-column="8" selection-end-line="302" />
501
+        <state relative-caret-position="463">
502
+          <caret line="310" column="5" selection-start-line="310" selection-start-column="5" selection-end-line="310" selection-end-column="5" />
506
           <folding>
503
           <folding>
507
             <element signature="imports" expanded="true" />
504
             <element signature="imports" expanded="true" />
508
           </folding>
505
           </folding>

+ 19
- 5
arraz/src/main/java/MoreArrayc.java Visa fil

1
 import java.util.ArrayList;
1
 import java.util.ArrayList;
2
 import java.util.Arrays;
2
 import java.util.Arrays;
3
 import java.util.Iterator;
3
 import java.util.Iterator;
4
+import java.util.List;
4
 import java.util.regex.Pattern;
5
 import java.util.regex.Pattern;
5
 
6
 
6
 public class MoreArrayc {
7
 public class MoreArrayc {
192
 
193
 
193
     public Integer[] insertAtStartAndCopy(Integer[] arr,int value){
194
     public Integer[] insertAtStartAndCopy(Integer[] arr,int value){
194
 
195
 
195
-        return null;
196
+        List<Integer> list = new ArrayList<>();
197
+        list.addAll(Arrays.asList(arr));
198
+        list.add(0, value);
199
+
200
+        //Then
201
+
202
+        return arr = list.toArray(new Integer[list.size()]);
203
+
204
+    }
205
+
206
+    public Integer[] insertAtLastAndCopy(Integer[] arr,int value){
207
+
208
+        arr = Arrays.copyOf(arr,arr.length +1);
209
+        arr[arr.length-1] = value;
210
+
211
+        //Then
212
+
213
+        return arr;
196
 
214
 
197
     }
215
     }
198
 
216
 
207
 
225
 
208
 //   averageArrayWithoutMaxMin
226
 //   averageArrayWithoutMaxMin
209
 
227
 
210
-
211
-//    insertAtStartAndCopy
212
-//    insertAtEndAndCopy
213
-//    sortArrayIntoEvensThenOdds

+ 31
- 7
arraz/src/test/java/MoreArraysTest.java Visa fil

6
 import java.util.ArrayList;
6
 import java.util.ArrayList;
7
 import java.util.Arrays;
7
 import java.util.Arrays;
8
 import java.util.Iterator;
8
 import java.util.Iterator;
9
+import java.util.List;
9
 
10
 
10
 public class MoreArraysTest {
11
 public class MoreArraysTest {
11
 
12
 
285
     }
286
     }
286
 
287
 
287
     @Test
288
     @Test
288
-    public void insertFirstThenCopyTEST(){
289
+    public void insertfirstThenCopyTEST() {
289
 
290
 
290
         //Given
291
         //Given
291
 
292
 
292
-        Integer [] arr = {5,1,7,8,9,4,3};
293
+        Integer[] arr = {5, 1, 7, 8, 9, 4, 3};
293
         int value = 6;
294
         int value = 6;
295
+        Integer[] arr2 = {6, 5, 1, 7, 8, 9, 4, 3};
296
+
294
 
297
 
295
         //When
298
         //When
296
 
299
 
297
-        
298
-        arr[0] = value;
300
+       Integer[] actual = more.insertAtStartAndCopy(arr,value);
301
+
299
         //Then
302
         //Then
300
-        for (int i = 0; i < arr.length-1 ; i++) {
301
-            System.out.println(arr);
302
-        }
303
 
303
 
304
 
304
 
305
 
305
 
306
 
306
 
307
+        Assert.assertEquals(arr2, actual);
308
+
309
+    }
310
+    @Test
311
+    public void insertLastThenCopyTEST(){
312
+
313
+        //Given
314
+
315
+        Integer [] arr = {5,1,7,8,9,4,3};
316
+        int value = 6;
317
+
318
+        Integer[] arr2 = {5,1,7,8,9,4,3,6};
319
+
320
+
321
+
322
+        //When
323
+
324
+        Integer[] actual = more.insertAtLastAndCopy(arr,value);
325
+
326
+        //Then
327
+
328
+
329
+        Assert.assertEquals(arr2,actual);
330
+
307
     }
331
     }
308
 
332
 
309
 
333