ソースを参照

updating arrays

Whitney Martinez 6 年 前
コミット
0aa64e1ef8
共有3 個のファイルを変更した92 個の追加57 個の削除を含む
  1. 42
    45
      arraz/.idea/workspace.xml
  2. 19
    5
      arraz/src/main/java/MoreArrayc.java
  3. 31
    7
      arraz/src/test/java/MoreArraysTest.java

+ 42
- 45
arraz/.idea/workspace.xml ファイルの表示

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

+ 19
- 5
arraz/src/main/java/MoreArrayc.java ファイルの表示

@@ -1,6 +1,7 @@
1 1
 import java.util.ArrayList;
2 2
 import java.util.Arrays;
3 3
 import java.util.Iterator;
4
+import java.util.List;
4 5
 import java.util.regex.Pattern;
5 6
 
6 7
 public class MoreArrayc {
@@ -192,7 +193,24 @@ public class MoreArrayc {
192 193
 
193 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,7 +225,3 @@ public class MoreArrayc {
207 225
 
208 226
 //   averageArrayWithoutMaxMin
209 227
 
210
-
211
-//    insertAtStartAndCopy
212
-//    insertAtEndAndCopy
213
-//    sortArrayIntoEvensThenOdds

+ 31
- 7
arraz/src/test/java/MoreArraysTest.java ファイルの表示

@@ -6,6 +6,7 @@ import java.security.PublicKey;
6 6
 import java.util.ArrayList;
7 7
 import java.util.Arrays;
8 8
 import java.util.Iterator;
9
+import java.util.List;
9 10
 
10 11
 public class MoreArraysTest {
11 12
 
@@ -285,25 +286,48 @@ public class MoreArraysTest {
285 286
     }
286 287
 
287 288
     @Test
288
-    public void insertFirstThenCopyTEST(){
289
+    public void insertfirstThenCopyTEST() {
289 290
 
290 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 294
         int value = 6;
295
+        Integer[] arr2 = {6, 5, 1, 7, 8, 9, 4, 3};
296
+
294 297
 
295 298
         //When
296 299
 
297
-        
298
-        arr[0] = value;
300
+       Integer[] actual = more.insertAtStartAndCopy(arr,value);
301
+
299 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