thulasi 6 år sedan
förälder
incheckning
ce3eb6adc1
4 ändrade filer med 358 tillägg och 64 borttagningar
  1. 1
    1
      .idea/compiler.xml
  2. 77
    56
      .idea/workspace.xml
  3. 115
    7
      arraz/src/main/java/Arraz.java
  4. 165
    0
      arraz/src/test/java/ArrazTest.java

+ 1
- 1
.idea/compiler.xml Visa fil

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

+ 77
- 56
.idea/workspace.xml Visa fil

@@ -2,9 +2,7 @@
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" />
6
-      <change beforePath="$PROJECT_DIR$/arraz/arraz.iml" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/arraz.iml" afterDir="false" />
7
-      <change beforePath="$PROJECT_DIR$/arraz/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/pom.xml" afterDir="false" />
5
+      <change beforePath="$PROJECT_DIR$/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
8 6
       <change beforePath="$PROJECT_DIR$/arraz/src/main/java/Arraz.java" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/src/main/java/Arraz.java" afterDir="false" />
9 7
       <change beforePath="$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java" afterDir="false" />
10 8
     </list>
@@ -28,52 +26,56 @@
28 26
       </usages-collector>
29 27
       <usages-collector id="statistics.file.extensions.edit">
30 28
         <counts>
31
-          <entry key="java" value="4494" />
29
+          <entry key="java" value="6387" />
32 30
         </counts>
33 31
       </usages-collector>
34 32
       <usages-collector id="statistics.file.types.edit">
35 33
         <counts>
36
-          <entry key="JAVA" value="4494" />
34
+          <entry key="JAVA" value="6387" />
37 35
         </counts>
38 36
       </usages-collector>
39 37
       <usages-collector id="statistics.file.extensions.open">
40 38
         <counts>
41
-          <entry key="java" value="3" />
39
+          <entry key="java" value="4" />
42 40
         </counts>
43 41
       </usages-collector>
44 42
       <usages-collector id="statistics.file.types.open">
45 43
         <counts>
46
-          <entry key="JAVA" value="3" />
44
+          <entry key="JAVA" value="4" />
47 45
         </counts>
48 46
       </usages-collector>
49 47
     </session>
50 48
   </component>
51 49
   <component name="FileEditorManager">
52 50
     <leaf SIDE_TABS_SIZE_LIMIT_KEY="375">
53
-      <file pinned="false" current-in-tab="false">
54
-        <entry file="file://$PROJECT_DIR$/arraz/pom.xml">
55
-          <provider selected="true" editor-type-id="text-editor" />
56
-        </entry>
57
-      </file>
58 51
       <file pinned="false" current-in-tab="true">
59 52
         <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
60 53
           <provider selected="true" editor-type-id="text-editor">
61
-            <state relative-caret-position="231">
62
-              <caret line="189" column="4" selection-start-line="189" selection-start-column="4" selection-end-line="189" selection-end-column="4" />
54
+            <state relative-caret-position="292">
55
+              <caret line="291" column="8" lean-forward="true" selection-start-line="291" selection-start-column="8" selection-end-line="291" selection-end-column="8" />
63 56
               <folding>
64 57
                 <element signature="imports" expanded="true" />
65
-                <element signature="e#3653#3654#0" expanded="true" />
66
-                <element signature="e#3679#3680#0" expanded="true" />
58
+                <element signature="e#3843#3844#0" expanded="true" />
59
+                <element signature="e#3870#3871#0" expanded="true" />
67 60
               </folding>
68 61
             </state>
69 62
           </provider>
70 63
         </entry>
71 64
       </file>
72 65
       <file pinned="false" current-in-tab="false">
66
+        <entry file="file://$PROJECT_DIR$/arraz/src/main/java/MaxMin.java">
67
+          <provider selected="true" editor-type-id="text-editor">
68
+            <state relative-caret-position="225">
69
+              <caret line="15" lean-forward="true" selection-start-line="15" selection-end-line="15" />
70
+            </state>
71
+          </provider>
72
+        </entry>
73
+      </file>
74
+      <file pinned="false" current-in-tab="false">
73 75
         <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
74 76
           <provider selected="true" editor-type-id="text-editor">
75
-            <state relative-caret-position="292">
76
-              <caret line="373" column="45" selection-start-line="373" selection-start-column="45" selection-end-line="373" selection-end-column="45" />
77
+            <state relative-caret-position="54">
78
+              <caret line="254" column="10" lean-forward="true" selection-start-line="254" selection-start-column="10" selection-end-line="254" selection-end-column="10" />
77 79
               <folding>
78 80
                 <element signature="imports" expanded="true" />
79 81
               </folding>
@@ -103,6 +105,11 @@
103 105
       </list>
104 106
     </option>
105 107
   </component>
108
+  <component name="FindInProjectRecents">
109
+    <findStrings>
110
+      <find>max</find>
111
+    </findStrings>
112
+  </component>
106 113
   <component name="Git.Settings">
107 114
     <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
108 115
   </component>
@@ -281,7 +288,7 @@
281 288
     <property name="GO_FMT" value="false" />
282 289
     <property name="WebServerToolWindowFactoryState" value="false" />
283 290
     <property name="aspect.path.notification.shown" value="true" />
284
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544194085762" />
291
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544225649855" />
285 292
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="JUnit4" />
286 293
     <property name="jdk.selected.JAVA_MODULE" value="1.8" />
287 294
     <property name="last_opened_file_path" value="$PROJECT_DIR$" />
@@ -289,7 +296,7 @@
289 296
     <property name="project.structure.last.edited" value="Project" />
290 297
     <property name="project.structure.proportion" value="0.15" />
291 298
     <property name="project.structure.side.proportion" value="0.2" />
292
-    <property name="settings.editor.selected.configurable" value="Errors" />
299
+    <property name="settings.editor.selected.configurable" value="reference.projectsettings.compiler.javacompiler" />
293 300
   </component>
294 301
   <component name="RecentsManager">
295 302
     <key name="CreateTestDialog.RecentsKey">
@@ -314,7 +321,7 @@
314 321
       </list>
315 322
     </option>
316 323
   </component>
317
-  <component name="RunManager" selected="JUnit.ArrazTest.test1RemoveDupesFromArray">
324
+  <component name="RunManager" selected="JUnit.ArrazTest">
318 325
     <configuration default="true" type="Applet" factoryName="Applet">
319 326
       <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
320 327
       <method v="2">
@@ -336,22 +343,22 @@
336 343
         <option name="Make" enabled="true" />
337 344
       </method>
338 345
     </configuration>
339
-    <configuration name="ArrazTest.test1CopyArrayByInterator" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
346
+    <configuration name="ArrazTest.test1RemoveDupesFromArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
340 347
       <module name="arraz" />
341 348
       <option name="PACKAGE_NAME" value="" />
342 349
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
343
-      <option name="METHOD_NAME" value="test1CopyArrayByInterator" />
350
+      <option name="METHOD_NAME" value="test1RemoveDupesFromArray" />
344 351
       <option name="TEST_OBJECT" value="method" />
345 352
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
346 353
       <method v="2">
347 354
         <option name="Make" enabled="true" />
348 355
       </method>
349 356
     </configuration>
350
-    <configuration name="ArrazTest.test1RemoveDupesFromArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
357
+    <configuration name="ArrazTest.test1RemoveLastItemAndCopy" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
351 358
       <module name="arraz" />
352 359
       <option name="PACKAGE_NAME" value="" />
353 360
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
354
-      <option name="METHOD_NAME" value="test1RemoveDupesFromArray" />
361
+      <option name="METHOD_NAME" value="test1RemoveLastItemAndCopy" />
355 362
       <option name="TEST_OBJECT" value="method" />
356 363
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
357 364
       <method v="2">
@@ -369,6 +376,17 @@
369 376
         <option name="Make" enabled="true" />
370 377
       </method>
371 378
     </configuration>
379
+    <configuration name="ArrazTest.test2RemoveLastItemAndCopy" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
380
+      <module name="arraz" />
381
+      <option name="PACKAGE_NAME" value="" />
382
+      <option name="MAIN_CLASS_NAME" value="ArrazTest" />
383
+      <option name="METHOD_NAME" value="test2RemoveLastItemAndCopy" />
384
+      <option name="TEST_OBJECT" value="method" />
385
+      <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
386
+      <method v="2">
387
+        <option name="Make" enabled="true" />
388
+      </method>
389
+    </configuration>
372 390
     <configuration default="true" type="JUnit" factoryName="JUnit">
373 391
       <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
374 392
       <method v="2">
@@ -394,16 +412,18 @@
394 412
     </configuration>
395 413
     <list>
396 414
       <item itemvalue="JUnit.ArrazTest" />
397
-      <item itemvalue="JUnit.ArrazTest.test1CopyArrayByInterator" />
398 415
       <item itemvalue="JUnit.ArrazTest.test2CopyArrayByInterator" />
399 416
       <item itemvalue="JUnit.ArrazTest.test1RemoveDupesFromArray" />
417
+      <item itemvalue="JUnit.ArrazTest.test1RemoveLastItemAndCopy" />
418
+      <item itemvalue="JUnit.ArrazTest.test2RemoveLastItemAndCopy" />
400 419
     </list>
401 420
     <recent_temporary>
402 421
       <list>
403 422
         <item itemvalue="JUnit.ArrazTest" />
423
+        <item itemvalue="JUnit.ArrazTest.test2RemoveLastItemAndCopy" />
424
+        <item itemvalue="JUnit.ArrazTest.test1RemoveLastItemAndCopy" />
404 425
         <item itemvalue="JUnit.ArrazTest.test1RemoveDupesFromArray" />
405 426
         <item itemvalue="JUnit.ArrazTest.test2CopyArrayByInterator" />
406
-        <item itemvalue="JUnit.ArrazTest.test1CopyArrayByInterator" />
407 427
       </list>
408 428
     </recent_temporary>
409 429
   </component>
@@ -422,7 +442,7 @@
422 442
       <workItem from="1544020724645" duration="762000" />
423 443
       <workItem from="1544059628498" duration="1362000" />
424 444
       <workItem from="1544064536860" duration="12499000" />
425
-      <workItem from="1544144402835" duration="7928000" />
445
+      <workItem from="1544144402835" duration="22092000" />
426 446
     </task>
427 447
     <task id="LOCAL-00001" summary="readme and docs">
428 448
       <created>1544021313039</created>
@@ -435,44 +455,45 @@
435 455
     <servers />
436 456
   </component>
437 457
   <component name="TestHistory">
438
-    <history-entry file="ArrazTest - 2018.12.06 at 20h 01m 34s.xml">
439
-      <configuration name="ArrazTest" configurationId="JUnit" />
458
+    <history-entry file="ArrazTest_test1RemoveLastItemAndCopy - 2018.12.07 at 15h 44m 39s.xml">
459
+      <configuration name="ArrazTest.test1RemoveLastItemAndCopy" configurationId="JUnit" />
440 460
     </history-entry>
441
-    <history-entry file="ArrazTest_test1RemoveDupesFromArray - 2018.12.06 at 20h 40m 58s.xml">
442
-      <configuration name="ArrazTest.test1RemoveDupesFromArray" configurationId="JUnit" />
461
+    <history-entry file="ArrazTest_test2RemoveLastItemAndCopy - 2018.12.07 at 15h 44m 54s.xml">
462
+      <configuration name="ArrazTest.test2RemoveLastItemAndCopy" configurationId="JUnit" />
443 463
     </history-entry>
444
-    <history-entry file="ArrazTest_test1RemoveDupesFromArray - 2018.12.06 at 20h 42m 02s.xml">
445
-      <configuration name="ArrazTest.test1RemoveDupesFromArray" configurationId="JUnit" />
464
+    <history-entry file="ArrazTest - 2018.12.07 at 15h 57m 05s.xml">
465
+      <configuration name="ArrazTest" configurationId="JUnit" />
446 466
     </history-entry>
447
-    <history-entry file="ArrazTest - 2018.12.07 at 08h 22m 44s.xml">
467
+    <history-entry file="ArrazTest - 2018.12.07 at 15h 58m 53s.xml">
448 468
       <configuration name="ArrazTest" configurationId="JUnit" />
449 469
     </history-entry>
450
-    <history-entry file="ArrazTest - 2018.12.07 at 08h 22m 48s.xml">
470
+    <history-entry file="ArrazTest - 2018.12.07 at 16h 37m 22s.xml">
451 471
       <configuration name="ArrazTest" configurationId="JUnit" />
452 472
     </history-entry>
453
-    <history-entry file="ArrazTest - 2018.12.07 at 08h 30m 08s.xml">
473
+    <history-entry file="ArrazTest - 2018.12.07 at 16h 38m 12s.xml">
454 474
       <configuration name="ArrazTest" configurationId="JUnit" />
455 475
     </history-entry>
456
-    <history-entry file="ArrazTest - 2018.12.07 at 08h 36m 40s.xml">
476
+    <history-entry file="ArrazTest - 2018.12.07 at 16h 41m 20s.xml">
457 477
       <configuration name="ArrazTest" configurationId="JUnit" />
458 478
     </history-entry>
459
-    <history-entry file="ArrazTest - 2018.12.07 at 08h 38m 07s.xml">
479
+    <history-entry file="ArrazTest - 2018.12.07 at 18h 03m 22s.xml">
460 480
       <configuration name="ArrazTest" configurationId="JUnit" />
461 481
     </history-entry>
462
-    <history-entry file="ArrazTest - 2018.12.07 at 09h 15m 22s.xml">
482
+    <history-entry file="ArrazTest - 2018.12.07 at 18h 10m 22s.xml">
463 483
       <configuration name="ArrazTest" configurationId="JUnit" />
464 484
     </history-entry>
465
-    <history-entry file="ArrazTest - 2018.12.07 at 09h 36m 49s.xml">
485
+    <history-entry file="ArrazTest - 2018.12.07 at 18h 30m 20s.xml">
466 486
       <configuration name="ArrazTest" configurationId="JUnit" />
467 487
     </history-entry>
468 488
   </component>
469 489
   <component name="TimeTrackingManager">
470
-    <option name="totallyTimeSpent" value="25011000" />
490
+    <option name="totallyTimeSpent" value="39175000" />
471 491
   </component>
472 492
   <component name="ToolWindowManager">
473 493
     <frame x="0" y="23" width="1280" height="709" extended-state="0" />
494
+    <editor active="true" />
474 495
     <layout>
475
-      <window_info content_ui="combo" id="Project" order="0" weight="0.18659128" />
496
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18659128" />
476 497
       <window_info id="Structure" order="1" weight="0.24959612" />
477 498
       <window_info id="Designer" order="2" />
478 499
       <window_info id="Image Layers" order="3" />
@@ -481,8 +502,8 @@
481 502
       <window_info id="Favorites" order="6" side_tool="true" />
482 503
       <window_info anchor="bottom" id="Message" order="0" />
483 504
       <window_info anchor="bottom" id="Find" order="1" />
484
-      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32996634" />
485
-      <window_info anchor="bottom" id="Debug" order="3" weight="0.39730638" />
505
+      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.2777778" />
506
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.3956229" />
486 507
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
487 508
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
488 509
       <window_info anchor="bottom" id="TODO" order="6" />
@@ -550,16 +571,16 @@
550 571
         </state>
551 572
       </provider>
552 573
     </entry>
574
+    <entry file="file://$PROJECT_DIR$/arraz/pom.xml">
575
+      <provider selected="true" editor-type-id="text-editor" />
576
+    </entry>
553 577
     <entry file="file://$PROJECT_DIR$/arraz/src/main/java/MaxMin.java">
554 578
       <provider selected="true" editor-type-id="text-editor">
555
-        <state relative-caret-position="180">
556
-          <caret line="12" column="9" lean-forward="true" selection-start-line="12" selection-start-column="9" selection-end-line="12" selection-end-column="9" />
579
+        <state relative-caret-position="225">
580
+          <caret line="15" lean-forward="true" selection-start-line="15" selection-end-line="15" />
557 581
         </state>
558 582
       </provider>
559 583
     </entry>
560
-    <entry file="file://$PROJECT_DIR$/arraz/pom.xml">
561
-      <provider selected="true" editor-type-id="text-editor" />
562
-    </entry>
563 584
     <entry file="file://$PROJECT_DIR$/README.md">
564 585
       <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
565 586
         <state split_layout="SECOND">
@@ -572,8 +593,8 @@
572 593
     </entry>
573 594
     <entry file="file://$PROJECT_DIR$/arraz/src/test/java/ArrazTest.java">
574 595
       <provider selected="true" editor-type-id="text-editor">
575
-        <state relative-caret-position="292">
576
-          <caret line="373" column="45" selection-start-line="373" selection-start-column="45" selection-end-line="373" selection-end-column="45" />
596
+        <state relative-caret-position="54">
597
+          <caret line="254" column="10" lean-forward="true" selection-start-line="254" selection-start-column="10" selection-end-line="254" selection-end-column="10" />
577 598
           <folding>
578 599
             <element signature="imports" expanded="true" />
579 600
           </folding>
@@ -582,12 +603,12 @@
582 603
     </entry>
583 604
     <entry file="file://$PROJECT_DIR$/arraz/src/main/java/Arraz.java">
584 605
       <provider selected="true" editor-type-id="text-editor">
585
-        <state relative-caret-position="231">
586
-          <caret line="189" column="4" selection-start-line="189" selection-start-column="4" selection-end-line="189" selection-end-column="4" />
606
+        <state relative-caret-position="292">
607
+          <caret line="291" column="8" lean-forward="true" selection-start-line="291" selection-start-column="8" selection-end-line="291" selection-end-column="8" />
587 608
           <folding>
588 609
             <element signature="imports" expanded="true" />
589
-            <element signature="e#3653#3654#0" expanded="true" />
590
-            <element signature="e#3679#3680#0" expanded="true" />
610
+            <element signature="e#3843#3844#0" expanded="true" />
611
+            <element signature="e#3870#3871#0" expanded="true" />
591 612
           </folding>
592 613
         </state>
593 614
       </provider>

+ 115
- 7
arraz/src/main/java/Arraz.java Visa fil

@@ -123,9 +123,19 @@ public class Arraz {
123 123
     }
124 124
 
125 125
     public int[] removeDupesFromArray(int[] arr) {
126
-       // ArrayList<Integer> list = new ArrayList<Integer>(Arrays.asList(arr));
127
-       // return newArr;
128
-        return null;
126
+        ArrayList<Integer> list = new ArrayList<>();
127
+        for(int n : arr) {
128
+            if(!list.contains(n))
129
+                list.add(n);
130
+        }
131
+        arr = new int[list.size()];
132
+        int index = 0;
133
+        for(int n : list) {
134
+            arr[index] = list.get(index);
135
+            index++;
136
+        }
137
+        //return newArr;
138
+        return arr;
129 139
     }
130 140
 
131 141
     public int find2ndLargestValueFromArray(int[] arr) {
@@ -182,11 +192,109 @@ public class Arraz {
182 192
     }
183 193
 
184 194
     public boolean arrayHas65and77(int[] arr) {
185
-        for(int n : arr) {
186
-            if (n != 65 || n != 77)
187
-                return false;
195
+        ArrayList<Integer> list = new ArrayList<>();
196
+        for(int n : arr)
197
+            list.add(n);
198
+
199
+        if(list.contains(65) && list.contains(77))
200
+            return true;
201
+        else return false;
202
+    }
203
+
204
+
205
+    public boolean theTotalofTensIs30(int[] arr) {
206
+        int sum = 0;
207
+        for(int n : arr){
208
+            if(n == 10)
209
+                sum += n;
188 210
         }
189
-        return true;
211
+
212
+        if(sum == 30)
213
+            return true;
214
+        else return false;
215
+    }
216
+
217
+    public int[] smallestAndSecondSmallest(int[] arr) {
218
+        int smallest = Integer.MAX_VALUE;
219
+        int secondSmallest = smallest;
220
+        for(int n : arr){
221
+            if(n < smallest) {
222
+                secondSmallest = smallest;
223
+                smallest = n;
224
+            }
225
+            else if(n < secondSmallest)
226
+                secondSmallest = smallest;
227
+        }
228
+       return new int[]{smallest, secondSmallest};
229
+    }
230
+
231
+    public int[] makeMeACopyPlease(int[] arr) {
232
+        int[] cpyArr = Arrays.copyOf(arr,arr.length);
233
+        int[] revArr = new int[cpyArr.length];
234
+        int index = 0;
235
+        for(int i = arr.length - 1; i >= 0; i--){
236
+            revArr[index] = arr[i];
237
+            index++;
238
+        }
239
+        return revArr;
190 240
     }
191 241
 
242
+    public int[] removeLastItemAndCopy(int[] arr) {
243
+        int[] newArr = new int[arr.length-1];
244
+        for(int i = 0;i<arr.length-1;i++){
245
+            newArr[i] = arr[i];
246
+        }
247
+        return newArr;
248
+    }
249
+
250
+    public int[] removeFirstItemAndCopy(int[] arr) {
251
+        int[] newArr = new int[arr.length-1];
252
+
253
+        for(int i = 1; i<arr.length; i++){
254
+            newArr[i-1] = arr[i];
255
+        }
256
+        return newArr;
257
+    }
258
+
259
+    public int[] insertAtStartAndCopy(int[] arr, int n) {
260
+        int[] newArr = new int[arr.length+1];
261
+        newArr[0] = n;
262
+        for(int i = 0; i<arr.length; i++){
263
+            newArr[i+1] = arr[i];
264
+        }
265
+        return newArr;
266
+    }
267
+
268
+    public int[] insertAtEndAndCopy(int[] arr, int n) {
269
+        int[] newArr = new int[arr.length+1];
270
+        newArr[newArr.length-1] = n;
271
+        for(int i = 0; i<arr.length; i++){
272
+            newArr[i] = arr[i];
273
+        }
274
+        return newArr;
275
+    }
276
+
277
+    public int[] sortArrayIntoEvensThenOdds(int[] arr) {
278
+        Arrays.sort(arr);
279
+
280
+        int[] sortedArr = new int[arr.length];
281
+        List<Integer> evens = new ArrayList<>();
282
+        List<Integer> odds = new ArrayList<>();
283
+
284
+        for(int i = 0;i<arr.length;i++){
285
+            if(arr[i] %2 == 0)
286
+                evens.add(arr[i]);
287
+            else
288
+                odds.add(arr[i]);
289
+        }
290
+
291
+        evens.addAll(odds);
292
+        for(int i = 0;i<arr.length;i++){
293
+            sortedArr[i] = evens.get(i);
294
+        }
295
+
296
+        return sortedArr;
297
+    }
298
+
299
+
192 300
 }

+ 165
- 0
arraz/src/test/java/ArrazTest.java Visa fil

@@ -382,4 +382,169 @@ public class ArrazTest {
382 382
                 boolean actual = arraz.arrayHas65and77(arr);
383 383
                 Assert.assertEquals(expected, actual);
384 384
             }
385
+
386
+            @Test
387
+            public void test1TheTotalofTensIs30(){
388
+                int[] arr = new int[]{65,10,9,10, 10,77};
389
+                boolean expected = true;
390
+                boolean actual = arraz.theTotalofTensIs30(arr);
391
+                Assert.assertEquals(expected, actual);
392
+            }
393
+
394
+            @Test
395
+            public void test2TheTotalofTensIs30(){
396
+                int[] arr = new int[]{51,83,96, 10};
397
+                boolean expected = false;
398
+                boolean actual = arraz.theTotalofTensIs30(arr);
399
+                Assert.assertEquals(expected, actual);
400
+            }
401
+
402
+            @Test
403
+            public void test1FindSmallestAndSecondSmallest(){
404
+                int[] arr = new int[]{5,3,1,8};
405
+                int[] expected = {1,3};
406
+                int[] actual = arraz.smallestAndSecondSmallest(arr);
407
+                Assert.assertEquals(expected.length, actual.length);
408
+                Assert.assertEquals(expected[0], actual[0]);
409
+                Assert.assertEquals(expected[1], actual[1]);
410
+            }
411
+
412
+            @Test
413
+            public void test2FindSmallestAndSecondSmallest(){
414
+                int[] arr = new int[]{50,9,13,5,8};
415
+                int[] expected = {5, 9};
416
+                int[] actual = arraz.smallestAndSecondSmallest(arr);
417
+                Assert.assertEquals(expected.length, actual.length);
418
+            }
419
+
420
+            @Test
421
+            public void test1MakeMeACopyPlease(){
422
+                int[] arr = new int[]{5,3,1};
423
+                int[] expected = {1,3,5};
424
+                int[] actual = arraz.makeMeACopyPlease(arr);
425
+                Assert.assertEquals(expected.length, actual.length);    
426
+                Assert.assertEquals(expected[0], actual[0]);
427
+                Assert.assertEquals(expected[1], actual[1]);
428
+                Assert.assertEquals(expected[2], actual[2]);
429
+            }
430
+
431
+            @Test
432
+            public void test2MakeMeACopyPlease(){
433
+                int[] arr = new int[]{50,9};
434
+                int[] expected = {9, 50};
435
+                int[] actual = arraz.makeMeACopyPlease(arr);
436
+                Assert.assertEquals(expected.length, actual.length);
437
+                Assert.assertEquals(expected[0], actual[0]);
438
+                Assert.assertEquals(expected[1], actual[1]);
439
+            }
440
+
441
+            @Test
442
+            public void test1RemoveLastItemAndCopy(){
443
+                int[] arr = new int[]{5,3,1,6};                            
444
+                int[] expected = {5,3,1};
445
+                int[] actual = arraz.removeLastItemAndCopy(arr);
446
+                Assert.assertEquals(expected.length, actual.length);
447
+                Assert.assertEquals(expected[0], actual[0]);
448
+                Assert.assertEquals(expected[1], actual[1]);
449
+                Assert.assertEquals(expected[2], actual[2]);
450
+            }
451
+
452
+            @Test
453
+            public void test2RemoveLastItemAndCopy(){
454
+                int[] arr = new int[]{50,9, 8};
455
+                int[] expected = {50, 9};
456
+                int[] actual = arraz.removeLastItemAndCopy(arr);
457
+                Assert.assertEquals(expected.length, actual.length);
458
+                Assert.assertEquals(expected[0], actual[0]);
459
+                Assert.assertEquals(expected[1], actual[1]);
460
+            }
461
+
462
+            @Test
463
+            public void test1RemoveFirstItemAndCopy(){
464
+                int[] arr = new int[]{5,3,1,6};
465
+                int[] expected = {3,1, 6};
466
+                int[] actual = arraz.removeFirstItemAndCopy(arr);
467
+                Assert.assertEquals(expected.length, actual.length);
468
+                Assert.assertEquals(expected[0], actual[0]);
469
+                Assert.assertEquals(expected[1], actual[1]);
470
+                Assert.assertEquals(expected[2], actual[2]);
471
+            }
472
+
473
+            @Test
474
+            public void test2RemoveFirstItemAndCopy(){
475
+                int[] arr = new int[]{50,9, 8};
476
+                int[] expected = {9, 8};
477
+                int[] actual = arraz.removeFirstItemAndCopy(arr);
478
+                Assert.assertEquals(expected.length, actual.length);
479
+                Assert.assertEquals(expected[0], actual[0]);
480
+                Assert.assertEquals(expected[1], actual[1]);
481
+            }
482
+
483
+            @Test
484
+            public void test1InsertAtStartAndCopy(){
485
+                int[] arr = new int[]{50,9, 8};
486
+                int[] expected = {3,50,9, 8};
487
+                int[] actual = arraz.insertAtStartAndCopy(arr, 3);
488
+                Assert.assertEquals(expected.length, actual.length);
489
+                Assert.assertEquals(expected[0], actual[0]);
490
+                Assert.assertEquals(expected[1], actual[1]);
491
+                Assert.assertEquals(expected[2], actual[2]);
492
+                Assert.assertEquals(expected[3], actual[3]);
493
+            }
494
+
495
+            @Test
496
+            public void test2InsertAtStartAndCopy(){
497
+                int[] arr = new int[]{98, 34};
498
+                int[] expected = {73,98,34};
499
+                int[] actual = arraz.insertAtStartAndCopy(arr, 73);
500
+                Assert.assertEquals(expected.length, actual.length);
501
+                Assert.assertEquals(expected[0], actual[0]);
502
+                Assert.assertEquals(expected[1], actual[1]);
503
+                Assert.assertEquals(expected[2], actual[2]);
504
+            }
505
+
506
+            @Test
507
+            public void test1InsertAtEndAndCopy(){
508
+                int[] arr = new int[]{50,9, 8};
509
+                int[] expected = {50,9, 8, 3};
510
+                int[] actual = arraz.insertAtEndAndCopy(arr, 3);
511
+                Assert.assertEquals(expected.length, actual.length);
512
+                Assert.assertEquals(expected[0], actual[0]);
513
+                Assert.assertEquals(expected[1], actual[1]);
514
+                Assert.assertEquals(expected[2], actual[2]);
515
+                Assert.assertEquals(expected[3], actual[3]);
516
+            }
517
+
518
+            @Test
519
+            public void test2InsertAtEndAndCopy(){
520
+                int[] arr = new int[]{98, 34};
521
+                int[] expected = {98,34,73};
522
+                int[] actual = arraz.insertAtEndAndCopy(arr, 73);
523
+                Assert.assertEquals(expected.length, actual.length);
524
+                Assert.assertEquals(expected[0], actual[0]);
525
+                Assert.assertEquals(expected[1], actual[1]);
526
+                Assert.assertEquals(expected[2], actual[2]);
527
+            }
528
+
529
+            @Test
530
+            public void test1SortArrayIntoEvensThenOdds(){
531
+               int[] arr = new int[]{5,3,1,6,4};
532
+               int[] expected = {4,6,1,3,5};
533
+               int[] actual = arraz.sortArrayIntoEvensThenOdds(arr);
534
+               Assert.assertEquals(expected.length, actual.length);
535
+               Assert.assertEquals(expected[0], actual[0]);
536
+               Assert.assertEquals(expected[1], actual[1]);
537
+               Assert.assertEquals(expected[2], actual[2]);
538
+            }
539
+
540
+            @Test
541
+            public void test2SortArrayIntoEvensThenOdds(){
542
+              int[] arr = new int[]{9,3,2,6};
543
+              int[] expected = {2, 6, 3, 9};
544
+              int[] actual = arraz.sortArrayIntoEvensThenOdds(arr);
545
+              Assert.assertEquals(expected.length, actual.length);
546
+              Assert.assertEquals(expected[0], actual[0]);
547
+              Assert.assertEquals(expected[1], actual[1]);
548
+              Assert.assertEquals(expected[2], actual[2]);
549
+            }
385 550
 }