ソースを参照

completed Lab

mpierse 6 年 前
コミット
1a94e4dd84
共有3 個のファイルを変更した418 個の追加68 個の削除を含む
  1. 92
    56
      .idea/workspace.xml
  2. 104
    5
      arraz/src/main/java/Arraz.java
  3. 222
    7
      arraz/src/test/java/ArrazTest.java

+ 92
- 56
.idea/workspace.xml ファイルの表示

@@ -2,7 +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/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
5 6
       <change beforePath="$PROJECT_DIR$/arraz/src/main/java/Arraz.java" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/src/main/java/Arraz.java" afterDir="false" />
7
+      <change beforePath="$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java" afterDir="false" />
6 8
     </list>
7 9
     <ignored path="$PROJECT_DIR$/arraz/target/" />
8 10
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -33,12 +35,12 @@
33 35
       </usages-collector>
34 36
       <usages-collector id="statistics.file.extensions.edit">
35 37
         <counts>
36
-          <entry key="java" value="3614" />
38
+          <entry key="java" value="6017" />
37 39
         </counts>
38 40
       </usages-collector>
39 41
       <usages-collector id="statistics.file.types.edit">
40 42
         <counts>
41
-          <entry key="JAVA" value="3614" />
43
+          <entry key="JAVA" value="6017" />
42 44
         </counts>
43 45
       </usages-collector>
44 46
     </session>
@@ -55,8 +57,8 @@
55 57
           <file pinned="false" current-in-tab="false">
56 58
             <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
57 59
               <provider selected="true" editor-type-id="text-editor">
58
-                <state relative-caret-position="354">
59
-                  <caret line="119" column="22" selection-start-line="119" selection-start-column="22" selection-end-line="119" selection-end-column="22" />
60
+                <state relative-caret-position="308">
61
+                  <caret line="223" column="5" lean-forward="true" selection-start-line="223" selection-start-column="5" selection-end-line="223" selection-end-column="5" />
60 62
                   <folding>
61 63
                     <element signature="imports" expanded="true" />
62 64
                     <element signature="e#414#415#0" expanded="true" />
@@ -64,6 +66,19 @@
64 66
                     <element signature="e#535#536#0" expanded="true" />
65 67
                     <element signature="e#576#577#0" expanded="true" />
66 68
                     <element signature="e#2895#2904#0" expanded="true" />
69
+                    <element signature="e#3350#3359#0" expanded="true" />
70
+                    <element signature="e#4784#4785#0" expanded="true" />
71
+                    <element signature="e#4834#4835#0" expanded="true" />
72
+                    <element signature="e#4883#4884#0" expanded="true" />
73
+                    <element signature="e#4959#4960#0" expanded="true" />
74
+                    <element signature="e#5009#5010#0" expanded="true" />
75
+                    <element signature="e#5074#5075#0" expanded="true" />
76
+                    <element signature="e#5184#5185#0" expanded="true" />
77
+                    <element signature="e#5223#5224#0" expanded="true" />
78
+                    <element signature="e#5377#5378#0" expanded="true" />
79
+                    <element signature="e#5445#5446#0" expanded="true" />
80
+                    <element signature="e#5548#5557#0" expanded="true" />
81
+                    <element signature="e#5608#5617#0" expanded="true" />
67 82
                   </folding>
68 83
                 </state>
69 84
               </provider>
@@ -72,8 +87,8 @@
72 87
           <file pinned="false" current-in-tab="true">
73 88
             <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
74 89
               <provider selected="true" editor-type-id="text-editor">
75
-                <state relative-caret-position="309">
76
-                  <caret line="191" column="43" lean-forward="true" selection-start-line="191" selection-start-column="43" selection-end-line="191" selection-end-column="43" />
90
+                <state relative-caret-position="296">
91
+                  <caret line="406" lean-forward="true" selection-start-line="406" selection-end-line="406" />
77 92
                   <folding>
78 93
                     <element signature="imports" expanded="true" />
79 94
                     <element signature="e#1970#1971#0" expanded="true" />
@@ -86,6 +101,8 @@
86 101
                     <element signature="e#3348#3349#0" expanded="true" />
87 102
                     <element signature="e#5073#5074#0" expanded="true" />
88 103
                     <element signature="e#5149#5150#0" expanded="true" />
104
+                    <element signature="e#6908#6917#0" expanded="true" />
105
+                    <element signature="e#7319#7328#0" expanded="true" />
89 106
                   </folding>
90 107
                 </state>
91 108
               </provider>
@@ -148,6 +165,12 @@
148 165
       </list>
149 166
     </option>
150 167
   </component>
168
+  <component name="FindInProjectRecents">
169
+    <findStrings>
170
+      <find>che</find>
171
+      <find>rever</find>
172
+    </findStrings>
173
+  </component>
151 174
   <component name="Git.Settings">
152 175
     <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
153 176
   </component>
@@ -235,7 +258,7 @@
235 258
     <property name="GO_FMT" value="false" />
236 259
     <property name="WebServerToolWindowFactoryState" value="false" />
237 260
     <property name="aspect.path.notification.shown" value="true" />
238
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544142316149" />
261
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544204129622" />
239 262
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="JUnit4" />
240 263
     <property name="jdk.selected.JAVA_MODULE" value="1.8" />
241 264
     <property name="last_opened_file_path" value="$PROJECT_DIR$" />
@@ -265,7 +288,7 @@
265 288
       </list>
266 289
     </option>
267 290
   </component>
268
-  <component name="RunManager" selected="JUnit.ArrazTest.test2RemoveDupes">
291
+  <component name="RunManager" selected="JUnit.ArrazTest">
269 292
     <configuration default="true" type="Applet" factoryName="Applet">
270 293
       <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
271 294
       <method v="2">
@@ -278,55 +301,53 @@
278 301
         <option name="Make" enabled="true" />
279 302
       </method>
280 303
     </configuration>
281
-    <configuration name="ArrazTest.test1FindMinMax" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
304
+    <configuration name="ArrazTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
282 305
       <module name="arraz" />
283 306
       <option name="PACKAGE_NAME" value="" />
284 307
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
285
-      <option name="METHOD_NAME" value="test1FindMinMax" />
286
-      <option name="TEST_OBJECT" value="method" />
287 308
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
288 309
       <method v="2">
289 310
         <option name="Make" enabled="true" />
290 311
       </method>
291 312
     </configuration>
292
-    <configuration name="ArrazTest.test1RemoveDupes" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
313
+    <configuration name="ArrazTest.test1SortArrayEvenOdd" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
293 314
       <module name="arraz" />
294 315
       <option name="PACKAGE_NAME" value="" />
295 316
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
296
-      <option name="METHOD_NAME" value="test1RemoveDupes" />
317
+      <option name="METHOD_NAME" value="test1SortArrayEvenOdd" />
297 318
       <option name="TEST_OBJECT" value="method" />
298 319
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
299 320
       <method v="2">
300 321
         <option name="Make" enabled="true" />
301 322
       </method>
302 323
     </configuration>
303
-    <configuration name="ArrazTest.test2FindMinMax" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
324
+    <configuration name="ArrazTest.test1insertEndAndCopy" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
304 325
       <module name="arraz" />
305 326
       <option name="PACKAGE_NAME" value="" />
306 327
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
307
-      <option name="METHOD_NAME" value="test2FindMinMax" />
328
+      <option name="METHOD_NAME" value="test1insertEndAndCopy" />
308 329
       <option name="TEST_OBJECT" value="method" />
309 330
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
310 331
       <method v="2">
311 332
         <option name="Make" enabled="true" />
312 333
       </method>
313 334
     </configuration>
314
-    <configuration name="ArrazTest.test2InsertIntoArrayAt" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
335
+    <configuration name="ArrazTest.test2SortArrayEvenOdd" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
315 336
       <module name="arraz" />
316 337
       <option name="PACKAGE_NAME" value="" />
317 338
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
318
-      <option name="METHOD_NAME" value="test2InsertIntoArrayAt" />
339
+      <option name="METHOD_NAME" value="test2SortArrayEvenOdd" />
319 340
       <option name="TEST_OBJECT" value="method" />
320 341
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
321 342
       <method v="2">
322 343
         <option name="Make" enabled="true" />
323 344
       </method>
324 345
     </configuration>
325
-    <configuration name="ArrazTest.test2RemoveDupes" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
346
+    <configuration name="ArrazTest.test2insertEndAndCopy" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
326 347
       <module name="arraz" />
327 348
       <option name="PACKAGE_NAME" value="" />
328 349
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
329
-      <option name="METHOD_NAME" value="test2RemoveDupes" />
350
+      <option name="METHOD_NAME" value="test2insertEndAndCopy" />
330 351
       <option name="TEST_OBJECT" value="method" />
331 352
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
332 353
       <method v="2">
@@ -357,19 +378,19 @@
357 378
       </method>
358 379
     </configuration>
359 380
     <list>
360
-      <item itemvalue="JUnit.ArrazTest.test2InsertIntoArrayAt" />
361
-      <item itemvalue="JUnit.ArrazTest.test1FindMinMax" />
362
-      <item itemvalue="JUnit.ArrazTest.test2FindMinMax" />
363
-      <item itemvalue="JUnit.ArrazTest.test1RemoveDupes" />
364
-      <item itemvalue="JUnit.ArrazTest.test2RemoveDupes" />
381
+      <item itemvalue="JUnit.ArrazTest.test1insertEndAndCopy" />
382
+      <item itemvalue="JUnit.ArrazTest.test2insertEndAndCopy" />
383
+      <item itemvalue="JUnit.ArrazTest.test1SortArrayEvenOdd" />
384
+      <item itemvalue="JUnit.ArrazTest.test2SortArrayEvenOdd" />
385
+      <item itemvalue="JUnit.ArrazTest" />
365 386
     </list>
366 387
     <recent_temporary>
367 388
       <list>
368
-        <item itemvalue="JUnit.ArrazTest.test2RemoveDupes" />
369
-        <item itemvalue="JUnit.ArrazTest.test1RemoveDupes" />
370
-        <item itemvalue="JUnit.ArrazTest.test2FindMinMax" />
371
-        <item itemvalue="JUnit.ArrazTest.test1FindMinMax" />
372
-        <item itemvalue="JUnit.ArrazTest.test2InsertIntoArrayAt" />
389
+        <item itemvalue="JUnit.ArrazTest" />
390
+        <item itemvalue="JUnit.ArrazTest.test2SortArrayEvenOdd" />
391
+        <item itemvalue="JUnit.ArrazTest.test1SortArrayEvenOdd" />
392
+        <item itemvalue="JUnit.ArrazTest.test2insertEndAndCopy" />
393
+        <item itemvalue="JUnit.ArrazTest.test1insertEndAndCopy" />
373 394
       </list>
374 395
     </recent_temporary>
375 396
   </component>
@@ -386,7 +407,7 @@
386 407
       <workItem from="1543955862749" duration="2347000" />
387 408
       <workItem from="1543958998826" duration="113000" />
388 409
       <workItem from="1544020724645" duration="762000" />
389
-      <workItem from="1544046527795" duration="14260000" />
410
+      <workItem from="1544046527795" duration="26482000" />
390 411
     </task>
391 412
     <task id="LOCAL-00001" summary="readme and docs">
392 413
       <created>1544021313039</created>
@@ -399,39 +420,39 @@
399 420
     <servers />
400 421
   </component>
401 422
   <component name="TestHistory">
402
-    <history-entry file="ArrazTest_test1InsertIntoArrayAt - 2018.12.06 at 18h 23m 24s.xml">
403
-      <configuration name="ArrazTest.test1InsertIntoArrayAt" configurationId="JUnit" />
404
-    </history-entry>
405
-    <history-entry file="ArrazTest_test2InsertIntoArrayAt - 2018.12.06 at 18h 23m 30s.xml">
423
+    <history-entry file="ArrazTest_test2InsertIntoArrayAt - 2018.12.07 at 12h 05m 05s.xml">
406 424
       <configuration name="ArrazTest.test2InsertIntoArrayAt" configurationId="JUnit" />
407 425
     </history-entry>
408
-    <history-entry file="ArrazTest_test2InsertIntoArrayAt - 2018.12.06 at 18h 23m 40s.xml">
409
-      <configuration name="ArrazTest.test2InsertIntoArrayAt" configurationId="JUnit" />
426
+    <history-entry file="ArrazTest_test1insertFirstAndCopy - 2018.12.07 at 12h 07m 39s.xml">
427
+      <configuration name="ArrazTest.test1insertFirstAndCopy" configurationId="JUnit" />
410 428
     </history-entry>
411
-    <history-entry file="ArrazTest_test2InsertIntoArrayAt - 2018.12.06 at 18h 23m 47s.xml">
412
-      <configuration name="ArrazTest.test2InsertIntoArrayAt" configurationId="JUnit" />
429
+    <history-entry file="ArrazTest_test1insertFirstAndCopy - 2018.12.07 at 12h 09m 16s.xml">
430
+      <configuration name="ArrazTest.test1insertFirstAndCopy" configurationId="JUnit" />
431
+    </history-entry>
432
+    <history-entry file="ArrazTest_test1insertFirstAndCopy - 2018.12.07 at 12h 10m 08s.xml">
433
+      <configuration name="ArrazTest.test1insertFirstAndCopy" configurationId="JUnit" />
413 434
     </history-entry>
414
-    <history-entry file="ArrazTest_test1FindMinMax - 2018.12.06 at 18h 43m 10s.xml">
415
-      <configuration name="ArrazTest.test1FindMinMax" configurationId="JUnit" />
435
+    <history-entry file="ArrazTest_test2insertFirstAndCopy - 2018.12.07 at 12h 10m 11s.xml">
436
+      <configuration name="ArrazTest.test2insertFirstAndCopy" configurationId="JUnit" />
416 437
     </history-entry>
417
-    <history-entry file="ArrazTest_test1FindMinMax - 2018.12.06 at 18h 43m 43s.xml">
418
-      <configuration name="ArrazTest.test1FindMinMax" configurationId="JUnit" />
438
+    <history-entry file="ArrazTest_test2insertFirstAndCopy - 2018.12.07 at 12h 10m 35s.xml">
439
+      <configuration name="ArrazTest.test2insertFirstAndCopy" configurationId="JUnit" />
419 440
     </history-entry>
420
-    <history-entry file="ArrazTest_test2FindMinMax - 2018.12.06 at 18h 43m 45s.xml">
421
-      <configuration name="ArrazTest.test2FindMinMax" configurationId="JUnit" />
441
+    <history-entry file="ArrazTest_test1insertEndAndCopy - 2018.12.07 at 12h 12m 34s.xml">
442
+      <configuration name="ArrazTest.test1insertEndAndCopy" configurationId="JUnit" />
422 443
     </history-entry>
423
-    <history-entry file="ArrazTest_test1RemoveDupes - 2018.12.06 at 19h 04m 59s.xml">
424
-      <configuration name="ArrazTest.test1RemoveDupes" configurationId="JUnit" />
444
+    <history-entry file="ArrazTest_test1insertEndAndCopy - 2018.12.07 at 12h 12m 38s.xml">
445
+      <configuration name="ArrazTest.test1insertEndAndCopy" configurationId="JUnit" />
425 446
     </history-entry>
426
-    <history-entry file="ArrazTest_test2RemoveDupes - 2018.12.06 at 19h 05m 07s.xml">
427
-      <configuration name="ArrazTest.test2RemoveDupes" configurationId="JUnit" />
447
+    <history-entry file="ArrazTest_test1insertEndAndCopy - 2018.12.07 at 12h 12m 42s.xml">
448
+      <configuration name="ArrazTest.test1insertEndAndCopy" configurationId="JUnit" />
428 449
     </history-entry>
429
-    <history-entry file="ArrazTest_test1RemoveDupes - 2018.12.06 at 19h 06m 41s.xml">
430
-      <configuration name="ArrazTest.test1RemoveDupes" configurationId="JUnit" />
450
+    <history-entry file="ArrazTest_test2insertEndAndCopy - 2018.12.07 at 12h 12m 44s.xml">
451
+      <configuration name="ArrazTest.test2insertEndAndCopy" configurationId="JUnit" />
431 452
     </history-entry>
432 453
   </component>
433 454
   <component name="TimeTrackingManager">
434
-    <option name="totallyTimeSpent" value="17482000" />
455
+    <option name="totallyTimeSpent" value="29704000" />
435 456
   </component>
436 457
   <component name="ToolWindowManager">
437 458
     <frame x="0" y="23" width="1440" height="805" extended-state="6" />
@@ -449,7 +470,7 @@
449 470
       <window_info anchor="bottom" id="Message" order="0" />
450 471
       <window_info anchor="bottom" id="Find" order="1" />
451 472
       <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.33239833" />
452
-      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
473
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.3997195" />
453 474
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
454 475
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
455 476
       <window_info anchor="bottom" id="TODO" order="6" />
@@ -518,8 +539,8 @@
518 539
     </entry>
519 540
     <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
520 541
       <provider selected="true" editor-type-id="text-editor">
521
-        <state relative-caret-position="354">
522
-          <caret line="119" column="22" selection-start-line="119" selection-start-column="22" selection-end-line="119" selection-end-column="22" />
542
+        <state relative-caret-position="308">
543
+          <caret line="223" column="5" lean-forward="true" selection-start-line="223" selection-start-column="5" selection-end-line="223" selection-end-column="5" />
523 544
           <folding>
524 545
             <element signature="imports" expanded="true" />
525 546
             <element signature="e#414#415#0" expanded="true" />
@@ -527,14 +548,27 @@
527 548
             <element signature="e#535#536#0" expanded="true" />
528 549
             <element signature="e#576#577#0" expanded="true" />
529 550
             <element signature="e#2895#2904#0" expanded="true" />
551
+            <element signature="e#3350#3359#0" expanded="true" />
552
+            <element signature="e#4784#4785#0" expanded="true" />
553
+            <element signature="e#4834#4835#0" expanded="true" />
554
+            <element signature="e#4883#4884#0" expanded="true" />
555
+            <element signature="e#4959#4960#0" expanded="true" />
556
+            <element signature="e#5009#5010#0" expanded="true" />
557
+            <element signature="e#5074#5075#0" expanded="true" />
558
+            <element signature="e#5184#5185#0" expanded="true" />
559
+            <element signature="e#5223#5224#0" expanded="true" />
560
+            <element signature="e#5377#5378#0" expanded="true" />
561
+            <element signature="e#5445#5446#0" expanded="true" />
562
+            <element signature="e#5548#5557#0" expanded="true" />
563
+            <element signature="e#5608#5617#0" expanded="true" />
530 564
           </folding>
531 565
         </state>
532 566
       </provider>
533 567
     </entry>
534 568
     <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
535 569
       <provider selected="true" editor-type-id="text-editor">
536
-        <state relative-caret-position="309">
537
-          <caret line="191" column="43" lean-forward="true" selection-start-line="191" selection-start-column="43" selection-end-line="191" selection-end-column="43" />
570
+        <state relative-caret-position="296">
571
+          <caret line="406" lean-forward="true" selection-start-line="406" selection-end-line="406" />
538 572
           <folding>
539 573
             <element signature="imports" expanded="true" />
540 574
             <element signature="e#1970#1971#0" expanded="true" />
@@ -547,6 +581,8 @@
547 581
             <element signature="e#3348#3349#0" expanded="true" />
548 582
             <element signature="e#5073#5074#0" expanded="true" />
549 583
             <element signature="e#5149#5150#0" expanded="true" />
584
+            <element signature="e#6908#6917#0" expanded="true" />
585
+            <element signature="e#7319#7328#0" expanded="true" />
550 586
           </folding>
551 587
         </state>
552 588
       </provider>

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

@@ -37,8 +37,8 @@ public class Arraz {
37 37
     public int[] reverse(int[] arr) {
38 38
         for(int i = 0; i<arr.length/2; i++){
39 39
            int temp = arr[i];
40
-           arr[i]=arr[arr.length-1];
41
-           arr[arr.length-1-i]=temp;
40
+           arr[i]=arr[arr.length-i-1];
41
+           arr[arr.length-i-1]=temp;
42 42
         }
43 43
         return arr;
44 44
     }
@@ -83,15 +83,18 @@ public class Arraz {
83 83
     }
84 84
 
85 85
     public int[] removeElement(int[] arr, int val) {
86
-        int[] result = new int[arr.length];
86
+        int[] result = new int[arr.length-1];
87
+        int count =0;
87 88
         for(int i=0; i<arr.length; i++){
88
-            if(arr[i]!=val)
89
-            result[i]=arr[i];
89
+            if(arr[i]!=val){
90
+            result[count]=arr[i];
91
+            count++;}
90 92
         }
91 93
         return result;
92 94
     }
93 95
 
94 96
     public int[] insertIntoArrayAt(int[] arr, int val, int index) {
97
+       if (index> arr.length+1) throw new ArrayIndexOutOfBoundsException();
95 98
         int[] result = new int[arr.length+1];
96 99
         int counter = 0;
97 100
         for (int i = 0; i <result.length; i++) {
@@ -121,4 +124,100 @@ public class Arraz {
121 124
         }
122 125
         return result;
123 126
     }
127
+
128
+    public int find2ndLargest(int[] arr) {
129
+        Arrays.sort(arr);
130
+        return arr[arr.length-2];
131
+    }
132
+
133
+    public ArrayList<Integer> makeArrayList(int[] arr) {
134
+        ArrayList<Integer> result = new ArrayList<Integer>();
135
+        for (int i : arr) {
136
+            result.add((Integer)i);
137
+        }
138
+        return result;
139
+    }
140
+
141
+    public int[] makeArray(ArrayList<Integer> list) {
142
+        int[] result = new int[list.size()];
143
+        for (int i = 0; i < list.size(); i++) {
144
+            result[i]=(int)list.get(i);
145
+        }
146
+        return result;
147
+    }
148
+
149
+    public boolean check2Arrays(int[] arr1, int[] arr2) {
150
+        if(arr1.length!=arr2.length) return false;
151
+        for (int i = 0; i < arr1.length; i++) {
152
+            if(arr1[i] != arr2[i]) return false;
153
+        }
154
+        return true;
155
+    }
156
+
157
+    public int averageWithoutMinMax(int[] arr) {
158
+        Arrays.sort(arr);
159
+        int result = 0;
160
+        for (int i = 1; i < arr.length-1; i++) {
161
+            result += arr[i];
162
+        }
163
+        return result/(arr.length-2);
164
+    }
165
+
166
+    public boolean has65and77(int[] testArr) {
167
+        boolean contains65 = false;
168
+        boolean contains77 = false;
169
+        for (int i: testArr) {
170
+            if (i ==65) contains65=true;
171
+            if (i==77) contains77=true;
172
+        }
173
+        return (contains65&&contains77);
174
+    }
175
+
176
+    public boolean toalOf10sIs30(int[] arr) {
177
+        int tenCount = 0;
178
+        for (int i : arr) {
179
+            if (i==10) tenCount++;
180
+        }
181
+        return (tenCount==3);
182
+    }
183
+
184
+    public int[] makeCopyReverse(int[] arr) {
185
+      return reverse(copyArrayByLoop(arr));
186
+    }
187
+
188
+    public int[] removeLastAndCopy(int[] arr) {
189
+        return copyArrayByLoop(removeElement(arr,arr[arr.length-1]));
190
+    }
191
+
192
+    public int[] removeFirstAndCopy(int[] arr) {
193
+        return copyArrayByLoop(removeElement(arr,arr[0]));
194
+    }
195
+
196
+    public int[] insertFirstAndCopy(int[] arr, int i) {
197
+        return copyArrayByLoop(insertIntoArrayAt(arr, i, 0));
198
+    }
199
+
200
+    public int[] insertEndAndCopy(int[] arr, int i) {
201
+        return copyArrayByLoop(insertIntoArrayAt(arr, i, arr.length));
202
+    }
203
+
204
+    public int[] sortArrayEvenOdd(int[] arr) {
205
+        ArrayList<Integer> evens = new ArrayList<Integer>();
206
+        ArrayList<Integer> odds = new ArrayList<Integer>();
207
+        int[] result = new int[arr.length];
208
+        int count = 0;
209
+        for (int i: arr) {
210
+            if(i%2==0) evens.add(i);
211
+            else odds.add(i);
212
+        }
213
+        for (Integer j: evens) {
214
+            result[count]=j;
215
+            count++;
216
+        }
217
+        for (Integer k:odds) {
218
+            result[count]=k;
219
+            count++;
220
+        }
221
+        return result;
222
+    }
124 223
 }

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

@@ -1,6 +1,8 @@
1 1
 import org.junit.Assert;
2 2
 import org.junit.Test;
3 3
 
4
+import java.util.ArrayList;
5
+
4 6
 import static org.junit.Assert.*;
5 7
 
6 8
 public class ArrazTest {
@@ -75,14 +77,20 @@ public class ArrazTest {
75 77
 
76 78
     @Test
77 79
     public void test1ReverseArray(){
78
-        int[] arr = new int[] {8,92,-32,12,-7,6,102,5,4};
79
-        Assert.assertEquals(arraz.reverse(spiffyHandyIntArray), spiffyHandyIntArray);
80
+        int[] expected = new int[] {8,92,-32,12,-7,6,102,5,4};
81
+        int[] actual = arraz.reverse(spiffyHandyIntArray);
82
+        for (int i = 0; i <actual.length ; i++) {
83
+            Assert.assertEquals(expected[i],actual[i]);
84
+        }
80 85
     }
81 86
 
82 87
     @Test
83 88
     public void test2ReverseArray(){
84
-        int[] arr = new int[] {8,92,-32,12,-7,6,102,5,4};
85
-        Assert.assertNotSame(arraz.reverse(spiffyHandyIntArray), arr);
89
+        int[] expected = new int[] {1,2,3};
90
+        int[] actual = arraz.reverse(expected);
91
+        for (int i = 0; i <actual.length ; i++) {
92
+            Assert.assertEquals(expected[i],actual[i]);
93
+        }
86 94
     }
87 95
 
88 96
     @Test
@@ -149,8 +157,8 @@ public class ArrazTest {
149 157
 
150 158
     @Test
151 159
     public void test2RemoveElement(){
152
-        int [] arr = arraz.removeElement(spiffyHandyIntArray, 1);
153
-        Assert.assertFalse(arraz.containsValue(arr, 1));
160
+        int [] arr = arraz.removeElement(spiffyHandyIntArray, 4);
161
+        Assert.assertFalse(arraz.containsValue(arr, 4));
154 162
     }
155 163
 
156 164
     @Test
@@ -193,5 +201,212 @@ public class ArrazTest {
193 201
     }
194 202
 
195 203
     @Test
196
-    
204
+    public void test1Find2ndLargest(){
205
+        int result = arraz.find2ndLargest(spiffyHandyIntArray);
206
+        Assert.assertEquals(92, result);
207
+    }
208
+
209
+    @Test
210
+    public void test2Find2ndLargest(){
211
+        int[] arr = new int[]{-4,-3,-5,-2,-8,-2,-5};
212
+        int result = arraz.find2ndLargest(arr);
213
+        Assert.assertEquals(-2, result);
214
+    }
215
+
216
+    @Test
217
+    public void test1MakeArrayList(){
218
+        ArrayList<Integer> list = arraz.makeArrayList(spiffyHandyIntArray);
219
+        Assert.assertEquals(list.getClass(), ArrayList.class);
220
+    }
221
+
222
+    @Test
223
+    public void test2MakeArrayList(){
224
+        ArrayList<Integer> list = arraz.makeArrayList(spiffyHandyIntArray);
225
+        Assert.assertEquals(spiffyHandyIntArray.length, list.size());
226
+    }
227
+
228
+    @Test
229
+    public void test1MakeArray(){
230
+        ArrayList<Integer> list = new ArrayList<Integer>();
231
+        list.add(4);
232
+        list.add(3);
233
+        list.add(9);
234
+        list.add(8);
235
+        int[] arr = arraz.makeArray(list);
236
+        Assert.assertEquals(arr.getClass(), int[].class);
237
+    }
238
+
239
+    @Test
240
+    public void test2MakeArray(){
241
+        ArrayList<Integer> list = new ArrayList<Integer>();
242
+        list.add(4);
243
+        list.add(3);
244
+        list.add(9);
245
+        list.add(8);
246
+        int[] arr = arraz.makeArray(list);
247
+        Assert.assertEquals(list.size(), arr.length);
248
+    }
249
+
250
+    @Test
251
+    public void test1Check2Arrays(){
252
+        int[] testArr = new int[] {4,5,102,6,-7,12,-32,92,8};
253
+        boolean actual = arraz.check2Arrays(testArr,spiffyHandyIntArray);
254
+        Assert.assertTrue(actual);
255
+    }
256
+
257
+    @Test
258
+    public void test2Check2Arrays(){
259
+        int[] testArr = new int[] {4,5,102,6,-7,44,-32,92,8};
260
+        boolean actual = arraz.check2Arrays(testArr,spiffyHandyIntArray);
261
+        Assert.assertFalse(actual);
262
+    }
263
+
264
+    @Test
265
+    public void test1AverageWithoutMinMax(){
266
+        int actual = arraz.averageWithoutMinMax(spiffyHandyIntArray);
267
+        Assert.assertEquals(17, actual);
268
+    }
269
+
270
+    @Test
271
+    public void test2AverageWithoutMinMax(){
272
+        int[] testArr = new int[] {4,3,2,6,7,4,1};
273
+        int actual = arraz.averageWithoutMinMax(testArr);
274
+        Assert.assertEquals(3, actual);
275
+    }
276
+
277
+    @Test
278
+    public void test1Has65and77(){
279
+        int[] testArr = new int[] {4,3,2,6,7,4,1};
280
+        boolean actual = arraz.has65and77(testArr);
281
+        Assert.assertFalse(actual);
282
+    }
283
+
284
+    @Test
285
+    public void test2Has65and77(){
286
+        int[] testArr = new int[] {4,3,65,2,6,7,77,4,1};
287
+        boolean actual = arraz.has65and77(testArr);
288
+        Assert.assertTrue(actual);
289
+    }
290
+
291
+    @Test
292
+    public void test1TotalOf10sIs30(){
293
+        int[] testArr = new int[] {4,3,65,2,6,7,77,4,1};
294
+        boolean actual = arraz.toalOf10sIs30(testArr);
295
+        Assert.assertFalse(actual);
296
+    }
297
+
298
+    @Test
299
+    public void test2TotalOf10sIs30(){
300
+            int[] testArr = new int[] {4,3,10,2,6,7,10,4,10,1};
301
+            boolean actual = arraz.toalOf10sIs30(testArr);
302
+            Assert.assertTrue(actual);
303
+    }
304
+
305
+    @Test
306
+    public void test1makeCopyReverse(){
307
+        int[] actual = arraz.makeCopyReverse(spiffyHandyIntArray);
308
+        int[] arr = new int[] {8,92,-32,12,-7,6,102,5,4};
309
+        for (int i=0; i<arr.length; i++){
310
+            Assert.assertEquals(arr[i], actual[i]);
311
+        }
312
+    }
313
+
314
+    @Test
315
+    public void test2makeCopyReverse(){
316
+        int[] testArr = new int[] {4,3,2,6,7,4,1};
317
+        int[] actual = arraz.makeCopyReverse(testArr);
318
+        int[] arr = new int[] {1,4,7,6,2,3,4};
319
+        for (int i=0; i<arr.length; i++){
320
+            Assert.assertEquals(arr[i], actual[i]);
321
+        }
322
+    }
323
+
324
+    @Test
325
+    public void test1removeLastAndCopy(){
326
+        int[] testArr = new int[] {4,3,2,33,7,4,1};
327
+        int[] actual = arraz.removeLastAndCopy(testArr);
328
+        int[] arr = new int[] {4,3,2,33,7,4};
329
+        for (int i=0; i<arr.length; i++){
330
+            Assert.assertEquals(arr[i], actual[i]);
331
+        }
332
+    }
333
+
334
+    @Test
335
+    public void test2removeLastAndCopy(){
336
+        int[] testArr = new int[] {4,3,10,2,6,7,10,4,10,1};
337
+        int[] actual = arraz.removeLastAndCopy(testArr);
338
+        Assert.assertEquals(testArr.length-1,actual.length);
339
+    }
340
+
341
+    @Test
342
+    public void test1removeFirstAndCopy(){
343
+        int[] testArr = new int[] {4,3,2,33,7,9,1};
344
+        int[] actual = arraz.removeFirstAndCopy(testArr);
345
+        int[] arr = new int[] {3,2,33,7,9,1};
346
+        for (int i=0; i<arr.length; i++){
347
+            Assert.assertEquals(arr[i], actual[i]);
348
+        }
349
+    }
350
+
351
+    @Test
352
+    public void test2removeFirstAndCopy(){
353
+        int[] testArr = new int[] {4,3,10,2,6,7,10,4,10,1};
354
+        int[] actual = arraz.removeFirstAndCopy(testArr);
355
+       Assert.assertEquals(testArr.length-1, actual.length);
356
+    }
357
+
358
+    @Test
359
+    public void test1insertFirstAndCopy(){
360
+        int[] testArr = new int[] {4,3,2,33,7,9,1};
361
+        int[] actual = arraz.insertFirstAndCopy(testArr, 1);
362
+        int[] arr = new int[] {1,4,3,2,33,7,9,1};
363
+        for (int i=0; i<arr.length; i++){
364
+            Assert.assertEquals(arr[i], actual[i]);
365
+        }
366
+    }
367
+
368
+    @Test
369
+    public void test2insertFirstAndCopy(){
370
+        int[] testArr = new int[] {4,3,10,2,6,7,10,4,10,1};
371
+        int[] actual = arraz.insertFirstAndCopy(testArr,2);
372
+        Assert.assertEquals(testArr.length+1, actual.length);
373
+    }
374
+
375
+    @Test
376
+    public void test1insertEndAndCopy(){
377
+        int[] testArr = new int[] {4,3,2,33,7,9,1};
378
+        int[] actual = arraz.insertEndAndCopy(testArr, 1);
379
+        int[] arr = new int[] {4,3,2,33,7,9,1,1};
380
+        for (int i=0; i<arr.length; i++){
381
+            Assert.assertEquals(arr[i], actual[i]);
382
+        }
383
+    }
384
+
385
+    @Test
386
+    public void test2insertEndAndCopy(){
387
+        int[] testArr = new int[] {4,3,10,2,6,7,10,4,10,1};
388
+        int[] actual = arraz.insertEndAndCopy(testArr,2);
389
+        Assert.assertEquals(testArr.length+1, actual.length);
390
+    }
391
+
392
+    @Test
393
+    public void test1SortArrayEvenOdd(){
394
+        int[] spiffyHandyIntArray = new int[] {4,5,102,6,-7,12,-32,92,8};
395
+        int[] actual = arraz.sortArrayEvenOdd(spiffyHandyIntArray);
396
+        int[] expected = new int[]{4,102,6,12,-32,92,8,5,-7};
397
+        for (int i = 0; i < actual.length; i++) {
398
+            Assert.assertEquals(expected[i], actual[i]);
399
+        }
400
+    }
401
+
402
+    @Test
403
+    public void test2SortArrayEvenOdd(){
404
+        int[] testArr = new int[] {4,3,10,2,6,7,10,4,10,1};
405
+        int[] actual = arraz.sortArrayEvenOdd(testArr);
406
+        int[] expected = new int[]{4,10,2,6,10,4,10,3,7,1};
407
+        for (int i = 0; i < actual.length; i++) {
408
+            Assert.assertEquals(expected[i], actual[i]);
409
+        }
410
+    }
411
+
197 412
 }