瀏覽代碼

up to MaxMin

Nathan Hall 6 年之前
父節點
當前提交
f411e7c248
共有 3 個文件被更改,包括 408 次插入82 次删除
  1. 122
    74
      arraz/.idea/workspace.xml
  2. 128
    6
      arraz/src/main/java/Arraz.java
  3. 158
    2
      arraz/src/test/java/ArrazTest.java

+ 122
- 74
arraz/.idea/workspace.xml 查看文件

@@ -2,6 +2,7 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="81f99a04-35ff-49d0-a7a5-4ed795a161d6" name="Default Changelist" 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$/src/main/java/Arraz.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Arraz.java" afterDir="false" />
6 7
       <change beforePath="$PROJECT_DIR$/src/test/java/ArrazTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/ArrazTest.java" afterDir="false" />
7 8
     </list>
@@ -22,30 +23,39 @@
22 23
       </usages-collector>
23 24
       <usages-collector id="statistics.file.types.open">
24 25
         <counts>
25
-          <entry key="JAVA" value="3" />
26
+          <entry key="JAVA" value="6" />
26 27
         </counts>
27 28
       </usages-collector>
28 29
       <usages-collector id="statistics.file.types.edit">
29 30
         <counts>
30
-          <entry key="JAVA" value="1519" />
31
+          <entry key="JAVA" value="3847" />
31 32
         </counts>
32 33
       </usages-collector>
33 34
     </session>
34 35
   </component>
35 36
   <component name="FileEditorManager">
36
-    <splitter split-orientation="horizontal" split-proportion="0.5">
37
+    <splitter split-orientation="horizontal" split-proportion="0.5571332">
37 38
       <split-first>
38 39
         <leaf>
39 40
           <file pinned="false" current-in-tab="true">
40 41
             <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
41 42
               <provider selected="true" editor-type-id="text-editor">
42
-                <state relative-caret-position="349">
43
-                  <caret line="82" column="4" lean-forward="true" selection-start-line="82" selection-start-column="4" selection-end-line="82" selection-end-column="4" />
43
+                <state relative-caret-position="550">
44
+                  <caret line="197" column="16" lean-forward="true" selection-start-line="197" selection-start-column="16" selection-end-line="197" selection-end-column="16" />
44 45
                   <folding>
45
-                    <element signature="e#1253#1254#0" expanded="true" />
46
-                    <element signature="e#1288#1289#0" expanded="true" />
47
-                    <element signature="e#1321#1322#0" expanded="true" />
48
-                    <element signature="e#1357#1358#0" expanded="true" />
46
+                    <element signature="imports" expanded="true" />
47
+                    <element signature="e#1375#1376#0" expanded="true" />
48
+                    <element signature="e#1410#1411#0" expanded="true" />
49
+                    <element signature="e#1454#1455#0" expanded="true" />
50
+                    <element signature="e#1490#1491#0" expanded="true" />
51
+                    <element signature="e#3458#3459#0" expanded="true" />
52
+                    <element signature="e#3492#3493#0" expanded="true" />
53
+                    <element signature="e#3523#3524#0" expanded="true" />
54
+                    <element signature="e#3557#3558#0" expanded="true" />
55
+                    <element signature="e#3596#3597#0" expanded="true" />
56
+                    <element signature="e#3634#3635#0" expanded="true" />
57
+                    <element signature="e#3673#3674#0" expanded="true" />
58
+                    <element signature="e#3711#3712#0" expanded="true" />
49 59
                   </folding>
50 60
                 </state>
51 61
               </provider>
@@ -58,8 +68,8 @@
58 68
           <file pinned="false" current-in-tab="true">
59 69
             <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
60 70
               <provider selected="true" editor-type-id="text-editor">
61
-                <state relative-caret-position="334">
62
-                  <caret line="151" column="36" selection-start-line="151" selection-start-column="36" selection-end-line="151" selection-end-column="36" />
71
+                <state relative-caret-position="73">
72
+                  <caret line="292" column="49" selection-start-line="292" selection-start-column="49" selection-end-line="292" selection-end-column="49" />
63 73
                   <folding>
64 74
                     <element signature="imports" expanded="true" />
65 75
                   </folding>
@@ -89,10 +99,10 @@
89 99
     <sorting>DEFINITION_ORDER</sorting>
90 100
   </component>
91 101
   <component name="ProjectFrameBounds">
92
-    <option name="x" value="-235" />
93
-    <option name="y" value="-917" />
94
-    <option name="width" value="1781" />
95
-    <option name="height" value="817" />
102
+    <option name="x" value="-332" />
103
+    <option name="y" value="-934" />
104
+    <option name="width" value="1636" />
105
+    <option name="height" value="793" />
96 106
   </component>
97 107
   <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
98 108
   <component name="ProjectView">
@@ -149,7 +159,7 @@
149 159
   <component name="PropertiesComponent">
150 160
     <property name="WebServerToolWindowFactoryState" value="false" />
151 161
     <property name="aspect.path.notification.shown" value="true" />
152
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544051412169" />
162
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544142759655" />
153 163
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
154 164
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
155 165
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
@@ -166,69 +176,71 @@
166 176
       </list>
167 177
     </option>
168 178
   </component>
169
-  <component name="RunManager" selected="JUnit.ArrazTest">
170
-    <configuration name="ArrazTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
179
+  <component name="RunManager" selected="JUnit.ArrazTest.test2FindMaxMinOfArray">
180
+    <configuration name="ArrazTest.test2FindMaxMinOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
171 181
       <module name="arraz" />
172 182
       <option name="PACKAGE_NAME" value="" />
173 183
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
184
+      <option name="METHOD_NAME" value="test2FindMaxMinOfArray" />
185
+      <option name="TEST_OBJECT" value="method" />
174 186
       <method v="2">
175 187
         <option name="Make" enabled="true" />
176 188
       </method>
177 189
     </configuration>
178
-    <configuration name="ArrazTest.test1ReverseArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
190
+    <configuration name="ArrazTest.test2InsertIntoArrayAt" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
179 191
       <module name="arraz" />
180 192
       <option name="PACKAGE_NAME" value="" />
181 193
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
182
-      <option name="METHOD_NAME" value="test1ReverseArray" />
194
+      <option name="METHOD_NAME" value="test2InsertIntoArrayAt" />
183 195
       <option name="TEST_OBJECT" value="method" />
184 196
       <method v="2">
185 197
         <option name="Make" enabled="true" />
186 198
       </method>
187 199
     </configuration>
188
-    <configuration name="ArrazTest.test2ContainsValue" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
200
+    <configuration name="ArrazTest.test2RemoveElementFromArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
189 201
       <module name="arraz" />
190 202
       <option name="PACKAGE_NAME" value="" />
191 203
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
192
-      <option name="METHOD_NAME" value="test2ContainsValue" />
204
+      <option name="METHOD_NAME" value="test2RemoveElementFromArray" />
193 205
       <option name="TEST_OBJECT" value="method" />
194 206
       <method v="2">
195 207
         <option name="Make" enabled="true" />
196 208
       </method>
197 209
     </configuration>
198
-    <configuration name="ArrazTest.test2DoubleAverageOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
210
+    <configuration name="ArrazTest.testFindMaxMinOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
199 211
       <module name="arraz" />
200 212
       <option name="PACKAGE_NAME" value="" />
201 213
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
202
-      <option name="METHOD_NAME" value="test2DoubleAverageOfArray" />
214
+      <option name="METHOD_NAME" value="testFindMaxMinOfArray" />
203 215
       <option name="TEST_OBJECT" value="method" />
204 216
       <method v="2">
205 217
         <option name="Make" enabled="true" />
206 218
       </method>
207 219
     </configuration>
208
-    <configuration name="ArrazTest.test2ReverseArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
220
+    <configuration name="ArrazTest.testInsertIntoArrayAt" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
209 221
       <module name="arraz" />
210 222
       <option name="PACKAGE_NAME" value="" />
211 223
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
212
-      <option name="METHOD_NAME" value="test2ReverseArray" />
224
+      <option name="METHOD_NAME" value="testInsertIntoArrayAt" />
213 225
       <option name="TEST_OBJECT" value="method" />
214 226
       <method v="2">
215 227
         <option name="Make" enabled="true" />
216 228
       </method>
217 229
     </configuration>
218 230
     <list>
219
-      <item itemvalue="JUnit.ArrazTest.test2ContainsValue" />
220
-      <item itemvalue="JUnit.ArrazTest.test1ReverseArray" />
221
-      <item itemvalue="JUnit.ArrazTest.test2ReverseArray" />
222
-      <item itemvalue="JUnit.ArrazTest" />
223
-      <item itemvalue="JUnit.ArrazTest.test2DoubleAverageOfArray" />
231
+      <item itemvalue="JUnit.ArrazTest.test2RemoveElementFromArray" />
232
+      <item itemvalue="JUnit.ArrazTest.testInsertIntoArrayAt" />
233
+      <item itemvalue="JUnit.ArrazTest.test2InsertIntoArrayAt" />
234
+      <item itemvalue="JUnit.ArrazTest.testFindMaxMinOfArray" />
235
+      <item itemvalue="JUnit.ArrazTest.test2FindMaxMinOfArray" />
224 236
     </list>
225 237
     <recent_temporary>
226 238
       <list>
227
-        <item itemvalue="JUnit.ArrazTest" />
228
-        <item itemvalue="JUnit.ArrazTest.test2DoubleAverageOfArray" />
229
-        <item itemvalue="JUnit.ArrazTest.test2ReverseArray" />
230
-        <item itemvalue="JUnit.ArrazTest.test1ReverseArray" />
231
-        <item itemvalue="JUnit.ArrazTest.test2ContainsValue" />
239
+        <item itemvalue="JUnit.ArrazTest.test2FindMaxMinOfArray" />
240
+        <item itemvalue="JUnit.ArrazTest.testFindMaxMinOfArray" />
241
+        <item itemvalue="JUnit.ArrazTest.test2InsertIntoArrayAt" />
242
+        <item itemvalue="JUnit.ArrazTest.testInsertIntoArrayAt" />
243
+        <item itemvalue="JUnit.ArrazTest.test2RemoveElementFromArray" />
232 244
       </list>
233 245
     </recent_temporary>
234 246
   </component>
@@ -242,47 +254,47 @@
242 254
       <option name="number" value="Default" />
243 255
       <option name="presentableId" value="Default" />
244 256
       <updated>1544046001151</updated>
245
-      <workItem from="1544046022231" duration="5261000" />
257
+      <workItem from="1544046022231" duration="18399000" />
246 258
     </task>
247 259
     <servers />
248 260
   </component>
249 261
   <component name="TestHistory">
250
-    <history-entry file="ArrazTest_test1ReverseArray - 2018.12.05 at 17h 24m 39s.xml">
251
-      <configuration name="ArrazTest.test1ReverseArray" configurationId="JUnit" />
262
+    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 21m 09s.xml">
263
+      <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
252 264
     </history-entry>
253
-    <history-entry file="ArrazTest_test1ReverseArray - 2018.12.05 at 17h 35m 52s.xml">
254
-      <configuration name="ArrazTest.test1ReverseArray" configurationId="JUnit" />
265
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 22m 09s.xml">
266
+      <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
255 267
     </history-entry>
256
-    <history-entry file="ArrazTest_test1ReverseArray - 2018.12.05 at 17h 36m 18s.xml">
257
-      <configuration name="ArrazTest.test1ReverseArray" configurationId="JUnit" />
268
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 23m 02s.xml">
269
+      <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
258 270
     </history-entry>
259
-    <history-entry file="ArrazTest_test2ReverseArray - 2018.12.05 at 17h 40m 35s.xml">
260
-      <configuration name="ArrazTest.test2ReverseArray" configurationId="JUnit" />
271
+    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 23m 30s.xml">
272
+      <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
261 273
     </history-entry>
262
-    <history-entry file="ArrazTest_test2ReverseArray - 2018.12.05 at 17h 41m 55s.xml">
263
-      <configuration name="ArrazTest.test2ReverseArray" configurationId="JUnit" />
274
+    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 23m 50s.xml">
275
+      <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
264 276
     </history-entry>
265
-    <history-entry file="ArrazTest_test2ReverseArray - 2018.12.05 at 17h 42m 17s.xml">
266
-      <configuration name="ArrazTest.test2ReverseArray" configurationId="JUnit" />
277
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 28m 37s.xml">
278
+      <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
267 279
     </history-entry>
268
-    <history-entry file="ArrazTest_test2ReverseArray - 2018.12.05 at 17h 50m 11s.xml">
269
-      <configuration name="ArrazTest.test2ReverseArray" configurationId="JUnit" />
280
+    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 28m 45s.xml">
281
+      <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
270 282
     </history-entry>
271
-    <history-entry file="ArrazTest_test2ReverseArray - 2018.12.05 at 17h 55m 19s.xml">
272
-      <configuration name="ArrazTest.test2ReverseArray" configurationId="JUnit" />
283
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 30m 52s.xml">
284
+      <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
273 285
     </history-entry>
274
-    <history-entry file="ArrazTest_test2ReverseArray - 2018.12.05 at 17h 56m 34s.xml">
275
-      <configuration name="ArrazTest.test2ReverseArray" configurationId="JUnit" />
286
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 32m 29s.xml">
287
+      <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
276 288
     </history-entry>
277
-    <history-entry file="ArrazTest_test2ReverseArray - 2018.12.05 at 17h 56m 47s.xml">
278
-      <configuration name="ArrazTest.test2ReverseArray" configurationId="JUnit" />
289
+    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 32m 40s.xml">
290
+      <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
279 291
     </history-entry>
280 292
   </component>
281 293
   <component name="TimeTrackingManager">
282
-    <option name="totallyTimeSpent" value="5261000" />
294
+    <option name="totallyTimeSpent" value="18399000" />
283 295
   </component>
284 296
   <component name="ToolWindowManager">
285
-    <frame x="-236" y="-893" width="1781" height="817" extended-state="0" />
297
+    <frame x="-332" y="-934" width="1636" height="793" extended-state="0" />
286 298
     <editor active="true" />
287 299
     <layout>
288 300
       <window_info id="Image Layers" />
@@ -290,17 +302,17 @@
290 302
       <window_info id="UI Designer" />
291 303
       <window_info id="Capture Tool" />
292 304
       <window_info id="Favorites" side_tool="true" />
293
-      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.11673375" />
305
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.072145544" />
294 306
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
295
-      <window_info anchor="bottom" id="Messages" weight="0.32905984" />
307
+      <window_info anchor="bottom" id="Messages" weight="0.3259587" />
296 308
       <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
297 309
       <window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
298
-      <window_info anchor="bottom" id="Terminal" weight="0.32905984" />
310
+      <window_info anchor="bottom" id="Terminal" weight="0.3649289" />
299 311
       <window_info anchor="bottom" id="Event Log" side_tool="true" />
300 312
       <window_info anchor="bottom" id="Message" order="0" />
301 313
       <window_info anchor="bottom" id="Find" order="1" />
302
-      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32905984" />
303
-      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
314
+      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.40855458" />
315
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.39810428" />
304 316
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
305 317
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
306 318
       <window_info anchor="bottom" id="TODO" order="6" />
@@ -322,25 +334,61 @@
322 334
     <option name="myLimit" value="2678400000" />
323 335
   </component>
324 336
   <component name="editorHistoryManager">
325
-    <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
337
+    <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/src.zip!/java/io/PrintStream.java">
326 338
       <provider selected="true" editor-type-id="text-editor">
327
-        <state relative-caret-position="334">
328
-          <caret line="151" column="36" selection-start-line="151" selection-start-column="36" selection-end-line="151" selection-end-column="36" />
339
+        <state relative-caret-position="111">
340
+          <caret line="596" selection-start-line="596" selection-end-line="596" />
329 341
           <folding>
330
-            <element signature="imports" expanded="true" />
342
+            <element signature="e#20871#20872#0" expanded="true" />
343
+          </folding>
344
+        </state>
345
+      </provider>
346
+    </entry>
347
+    <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/src.zip!/java/lang/String.java">
348
+      <provider selected="true" editor-type-id="text-editor">
349
+        <state relative-caret-position="118">
350
+          <caret line="3098" selection-start-line="3098" selection-end-line="3098" />
351
+          <folding>
352
+            <element signature="e#121769#121770#0" expanded="true" />
331 353
           </folding>
332 354
         </state>
333 355
       </provider>
334 356
     </entry>
357
+    <entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/src.zip!/java/lang/Integer.java">
358
+      <provider selected="true" editor-type-id="text-editor">
359
+        <state relative-caret-position="148">
360
+          <caret line="399" selection-start-line="399" selection-end-line="399" />
361
+        </state>
362
+      </provider>
363
+    </entry>
335 364
     <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
336 365
       <provider selected="true" editor-type-id="text-editor">
337
-        <state relative-caret-position="349">
338
-          <caret line="82" column="4" lean-forward="true" selection-start-line="82" selection-start-column="4" selection-end-line="82" selection-end-column="4" />
366
+        <state relative-caret-position="550">
367
+          <caret line="197" column="16" lean-forward="true" selection-start-line="197" selection-start-column="16" selection-end-line="197" selection-end-column="16" />
339 368
           <folding>
340
-            <element signature="e#1253#1254#0" expanded="true" />
341
-            <element signature="e#1288#1289#0" expanded="true" />
342
-            <element signature="e#1321#1322#0" expanded="true" />
343
-            <element signature="e#1357#1358#0" expanded="true" />
369
+            <element signature="imports" expanded="true" />
370
+            <element signature="e#1375#1376#0" expanded="true" />
371
+            <element signature="e#1410#1411#0" expanded="true" />
372
+            <element signature="e#1454#1455#0" expanded="true" />
373
+            <element signature="e#1490#1491#0" expanded="true" />
374
+            <element signature="e#3458#3459#0" expanded="true" />
375
+            <element signature="e#3492#3493#0" expanded="true" />
376
+            <element signature="e#3523#3524#0" expanded="true" />
377
+            <element signature="e#3557#3558#0" expanded="true" />
378
+            <element signature="e#3596#3597#0" expanded="true" />
379
+            <element signature="e#3634#3635#0" expanded="true" />
380
+            <element signature="e#3673#3674#0" expanded="true" />
381
+            <element signature="e#3711#3712#0" expanded="true" />
382
+          </folding>
383
+        </state>
384
+      </provider>
385
+    </entry>
386
+    <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
387
+      <provider selected="true" editor-type-id="text-editor">
388
+        <state relative-caret-position="73">
389
+          <caret line="292" column="49" selection-start-line="292" selection-start-column="49" selection-end-line="292" selection-end-column="49" />
390
+          <folding>
391
+            <element signature="imports" expanded="true" />
344 392
           </folding>
345 393
         </state>
346 394
       </provider>

+ 128
- 6
arraz/src/main/java/Arraz.java 查看文件

@@ -1,3 +1,8 @@
1
+import java.util.ArrayList;
2
+import java.util.Arrays;
3
+import java.util.Iterator;
4
+import java.util.List;
5
+
1 6
 public class Arraz {
2 7
 
3 8
     public int sumValuesOfArray(int[] arr) {
@@ -49,8 +54,8 @@ public class Arraz {
49 54
 
50 55
     public boolean containsValue(int[] arr, int value) {
51 56
 
52
-        for (int i : arr){
53
-            if ( i == value){
57
+        for (int i : arr) {
58
+            if (i == value) {
54 59
                 return true;
55 60
             }
56 61
         }
@@ -61,26 +66,143 @@ public class Arraz {
61 66
     public int[] reverseArray(int[] array1) {
62 67
         int[] array2 = new int[array1.length];
63 68
 
64
-        for (int i = 0; i < array1.length; i++){
69
+        for (int i = 0; i < array1.length; i++) {
65 70
             array2[array1.length - 1 - i] = array1[i];
66 71
         }
67 72
 
68 73
         return array2;
69 74
     }
70 75
 
71
-    public class OddEven{
76
+    public int[] insertIntoArray(int[] array, int pos, int value) {
77
+
78
+        int[] arr = new int[array.length + 1];
79
+        int count = 0;
80
+
81
+        for (int i = 0; i < array.length; i++) {
82
+            if( i == pos - 1 ){
83
+                arr[count] = value;
84
+                count++;
85
+            }
86
+
87
+            arr[count] = array[i];
88
+            count++;
89
+        }
90
+        return arr;
91
+    }
92
+
93
+    public class OddEven {
72 94
         public int odds;
73 95
         public int evens;
74 96
 
75
-        public int getOdds() {
97
+        public int getOdds(int[] array) {
76 98
             return odds;
77 99
         }
78 100
 
79
-        public int getEvens() {
101
+        public int getEvens(int[] array) {
80 102
             return evens;
81 103
         }
104
+
105
+
106
+        public void getOddEvensOfArray(int[] array1) {
107
+            for (int i : array1) {
108
+                if (i % 2 == 0) {
109
+                    evens += 1;
110
+                } else {
111
+                    odds += 1;
112
+                }
113
+            }
114
+        }
115
+    }
116
+
117
+    public Integer[] copyArrayByIterator(Integer[] array1) {
118
+
119
+        int i = 0;
120
+        Integer[] newArr = new Integer[array1.length];
121
+        Iterator<Integer> iterator = Arrays.asList(array1).iterator();
122
+
123
+        while (iterator.hasNext()) {
124
+            newArr[i] = iterator.next();
125
+            i++;
126
+        }
127
+        return newArr;
128
+    }
129
+
130
+
131
+    public int findIndexOf(int[] array1, int value) {
132
+        int count = 0;
133
+        for (int i : array1) {
134
+            if (i == value) {
135
+                return count;
136
+            }
137
+            count++;
138
+        }
139
+        System.out.println("Value of " + value + " does not exist");
140
+        return -1;
141
+    }
142
+
143
+    public Integer[] copyArrayByLoop(Integer[] array3) {
144
+        Integer[] intArr = new Integer[array3.length];
145
+
146
+        for (int j = 0; j < array3.length; j++) {
147
+            intArr[j] = array3[j];
148
+        }
149
+        return intArr;
150
+    }
151
+
152
+    public Integer[] removeElementFromArray(Integer[] array, Integer value) {
153
+        Integer[] arr = new Integer[array.length-1];
154
+        int count = 0;
155
+        for (Integer i: array){
156
+            if (i != value){
157
+                arr[count] = i;
158
+                count++;
159
+            }
160
+        }
161
+        return arr;
82 162
     }
83 163
 
84 164
 
165
+    public class MaxMin {
166
+        public int max;
167
+        public int min;
85 168
 
169
+        public int getMax() {
170
+            return max;
171
+        }
172
+
173
+        public int getMin() {
174
+            return min;
175
+        }
176
+
177
+        public void setMax(int max) {
178
+            this.max = max;
179
+        }
180
+
181
+        public void setMin(int min) {
182
+            this.min = min;
183
+        }
184
+    }
185
+
186
+    public MaxMin findMaxMinOfArray(int[] array) {
187
+        MaxMin mn = new MaxMin();
188
+
189
+        mn.max = array[0];
190
+        mn.min = array[0];
191
+
192
+        for (int i : array){
193
+            if ( i > mn.getMax() ){
194
+                mn.setMax(i);
195
+            }
196
+
197
+            if ( i < mn.getMin() ){
198
+                mn.setMin(i);
199
+            }
200
+
201
+            System.out.println("Max is: " + mn.max);
202
+            System.out.println("Min is: " + mn.min);
203
+        }
204
+
205
+        return mn;
206
+
207
+    }
86 208
 }

+ 158
- 2
arraz/src/test/java/ArrazTest.java 查看文件

@@ -144,13 +144,169 @@ public class ArrazTest {
144 144
 
145 145
     @Test
146 146
     public void testGetOddEvensOfArray(){
147
+        Arraz.OddEven oe = arraz.new OddEven();
147 148
 
149
+        int expected = 3;
150
+        oe.getOddEvensOfArray(array1);
148 151
 
149
-        int[] expected = {1,2,3,4,5};
150
-        int[] actual = arraz.reverseArray(array2);
152
+        Assert.assertEquals(expected, oe.getOdds(array1));
153
+
154
+    }
155
+
156
+    @Test
157
+    public void test2GetOddEvensOfArray(){
158
+        Arraz.OddEven oe = arraz.new OddEven();
159
+
160
+        int expected = 2;
161
+        oe.getOddEvensOfArray(array1);
162
+
163
+        Assert.assertEquals(expected, oe.getEvens(array1));
164
+
165
+    }
166
+
167
+    @Test
168
+    public void testFindIndexOf(){
169
+
170
+        int value = 3;
171
+        int expected = 2;
172
+        int actual = arraz.findIndexOf(array1, value);
173
+
174
+        Assert.assertEquals(expected, actual);
175
+
176
+    }
177
+
178
+    @Test
179
+    public void test2FindIndexOf(){
180
+
181
+        int value = 7;
182
+        int expected = -1;
183
+        int actual = arraz.findIndexOf(array1, value);
184
+
185
+        Assert.assertEquals(expected, actual);
186
+
187
+    }
188
+
189
+    Integer[] array3 = {1,2,3,4,5};
190
+
191
+    @Test
192
+    public void testCopyArrayByIterator(){
193
+
194
+        Integer[] expected = {1,2,3,4,5};
195
+        Integer[] actual = arraz.copyArrayByIterator(array3);
196
+
197
+        Assert.assertTrue(Arrays.equals(expected, actual));
198
+
199
+    }
200
+
201
+    Integer[] array4 = {1};
202
+    @Test
203
+    public void test2CopyArrayByIterator(){
204
+
205
+        Integer[] expected = {1};
206
+        Integer[] actual = arraz.copyArrayByIterator(array4);
207
+
208
+        Assert.assertTrue(Arrays.equals(expected, actual));
209
+
210
+    }
211
+
212
+    @Test
213
+    public void testCopyArrayByLoop(){
214
+
215
+        Integer[] expected = {1,2,3,4,5};
216
+        Integer[] actual = arraz.copyArrayByLoop(array3);
217
+
218
+        Assert.assertTrue(Arrays.equals(expected, actual));
219
+
220
+    }
221
+
222
+    @Test
223
+    public void test2CopyArrayByLoop(){
224
+        Integer[] array3 = {-1};
151 225
 
226
+        Integer[] expected = {-1};
227
+        Integer[] actual = arraz.copyArrayByLoop(array3);
152 228
 
229
+        Assert.assertTrue(Arrays.equals(expected, actual));
153 230
 
154 231
     }
155 232
 
233
+    @Test
234
+    public void testRemoveElementFromArray(){
235
+        Integer[] array = {1,2,3,4,5};
236
+        Integer value = 3;
237
+
238
+        Integer[] expected = {1,2,4,5};
239
+        Integer[] actual = arraz.removeElementFromArray(array, value);
240
+
241
+        Assert.assertTrue(Arrays.equals(expected, actual));
242
+
243
+    }
244
+
245
+    @Test
246
+    public void test2RemoveElementFromArray() {
247
+        Integer[] array = {1};
248
+        Integer value = 1;
249
+
250
+        Integer[] expected = {};
251
+        Integer[] actual = arraz.removeElementFromArray(array, value);
252
+
253
+        Assert.assertTrue(Arrays.equals(expected, actual));
254
+
255
+    }
256
+
257
+    @Test
258
+    public void testInsertIntoArrayAt() {
259
+        int pos = 3;
260
+        int value = 4;
261
+        int[] array = {1,2,3,4,5};
262
+
263
+
264
+        int[] expected = {1,2,4,3,4,5};
265
+        int[] actual = arraz.insertIntoArray(array, pos, value);
266
+
267
+        Assert.assertTrue(Arrays.equals(expected, actual));
268
+    }
269
+
270
+    @Test
271
+    public void test2InsertIntoArrayAt() {
272
+        int pos = 1;
273
+        int value = 4;
274
+        int[] array = {1,2,3,4,5};
275
+
276
+
277
+        int[] expected = {4,1,2,3,4,5};
278
+        int[] actual = arraz.insertIntoArray(array, pos, value);
279
+
280
+        Assert.assertTrue(Arrays.equals(expected, actual));
281
+    }
282
+
283
+    @Test
284
+    public void testFindMaxMinOfArray(){
285
+
286
+        int[] array = {1,5,2,4,3};
287
+        int expected = 5;
288
+
289
+        Arraz.MaxMin mn = arraz.new MaxMin();
290
+
291
+        arraz.findMaxMinOfArray(array);
292
+
293
+        Assert.assertEquals(expected, mn.getMax());
294
+
295
+    }
296
+
297
+    @Test
298
+    public void test2FindMaxMinOfArray(){
299
+
300
+        int[] array = {1,5,2,-1,0};
301
+        int expected = -1;
302
+
303
+        Arraz.MaxMin mn = arraz.new MaxMin();
304
+
305
+        arraz.findMaxMinOfArray(array);
306
+
307
+        Assert.assertEquals(expected, mn.getMin());
308
+
309
+    }
310
+
311
+
156 312
 }