Nathan Hall 6 년 전
부모
커밋
1887227f10
3개의 변경된 파일135개의 추가작업 그리고 70개의 파일을 삭제
  1. 56
    57
      arraz/.idea/workspace.xml
  2. 33
    10
      arraz/src/main/java/Arraz.java
  3. 46
    3
      arraz/src/test/java/ArrazTest.java

+ 56
- 57
arraz/.idea/workspace.xml 파일 보기

@@ -28,7 +28,7 @@
28 28
       </usages-collector>
29 29
       <usages-collector id="statistics.file.types.edit">
30 30
         <counts>
31
-          <entry key="JAVA" value="3847" />
31
+          <entry key="JAVA" value="4534" />
32 32
         </counts>
33 33
       </usages-collector>
34 34
     </session>
@@ -40,10 +40,10 @@
40 40
           <file pinned="false" current-in-tab="true">
41 41
             <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
42 42
               <provider selected="true" editor-type-id="text-editor">
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" />
43
+                <state relative-caret-position="94">
44
+                  <caret line="108" column="18" selection-start-line="108" selection-start-column="18" selection-end-line="108" selection-end-column="18" />
45 45
                   <folding>
46
-                    <element signature="imports" expanded="true" />
46
+                    <element signature="e#1659#1668#0" expanded="true" />
47 47
                     <element signature="e#1375#1376#0" expanded="true" />
48 48
                     <element signature="e#1410#1411#0" expanded="true" />
49 49
                     <element signature="e#1454#1455#0" expanded="true" />
@@ -68,8 +68,8 @@
68 68
           <file pinned="false" current-in-tab="true">
69 69
             <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
70 70
               <provider selected="true" editor-type-id="text-editor">
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" />
71
+                <state relative-caret-position="96">
72
+                  <caret line="339" column="15" selection-start-line="339" selection-start-column="15" selection-end-line="339" selection-end-column="15" />
73 73
                   <folding>
74 74
                     <element signature="imports" expanded="true" />
75 75
                   </folding>
@@ -99,10 +99,9 @@
99 99
     <sorting>DEFINITION_ORDER</sorting>
100 100
   </component>
101 101
   <component name="ProjectFrameBounds">
102
-    <option name="x" value="-332" />
103
-    <option name="y" value="-934" />
104
-    <option name="width" value="1636" />
105
-    <option name="height" value="793" />
102
+    <option name="y" value="159" />
103
+    <option name="width" value="1280" />
104
+    <option name="height" value="747" />
106 105
   </component>
107 106
   <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
108 107
   <component name="ProjectView">
@@ -159,7 +158,7 @@
159 158
   <component name="PropertiesComponent">
160 159
     <property name="WebServerToolWindowFactoryState" value="false" />
161 160
     <property name="aspect.path.notification.shown" value="true" />
162
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544142759655" />
161
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1544154073764" />
163 162
     <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
164 163
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
165 164
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
@@ -176,71 +175,71 @@
176 175
       </list>
177 176
     </option>
178 177
   </component>
179
-  <component name="RunManager" selected="JUnit.ArrazTest.test2FindMaxMinOfArray">
180
-    <configuration name="ArrazTest.test2FindMaxMinOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
178
+  <component name="RunManager" selected="JUnit.ArrazTest.test2Find2ndLargestValueFromArray">
179
+    <configuration name="ArrazTest.test2Find2ndLargestValueFromArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
181 180
       <module name="arraz" />
182 181
       <option name="PACKAGE_NAME" value="" />
183 182
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
184
-      <option name="METHOD_NAME" value="test2FindMaxMinOfArray" />
183
+      <option name="METHOD_NAME" value="test2Find2ndLargestValueFromArray" />
185 184
       <option name="TEST_OBJECT" value="method" />
186 185
       <method v="2">
187 186
         <option name="Make" enabled="true" />
188 187
       </method>
189 188
     </configuration>
190
-    <configuration name="ArrazTest.test2InsertIntoArrayAt" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
189
+    <configuration name="ArrazTest.test2FindMaxMinOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
191 190
       <module name="arraz" />
192 191
       <option name="PACKAGE_NAME" value="" />
193 192
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
194
-      <option name="METHOD_NAME" value="test2InsertIntoArrayAt" />
193
+      <option name="METHOD_NAME" value="test2FindMaxMinOfArray" />
195 194
       <option name="TEST_OBJECT" value="method" />
196 195
       <method v="2">
197 196
         <option name="Make" enabled="true" />
198 197
       </method>
199 198
     </configuration>
200
-    <configuration name="ArrazTest.test2RemoveElementFromArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
199
+    <configuration name="ArrazTest.test2RemoveDupesFromArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
201 200
       <module name="arraz" />
202 201
       <option name="PACKAGE_NAME" value="" />
203 202
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
204
-      <option name="METHOD_NAME" value="test2RemoveElementFromArray" />
203
+      <option name="METHOD_NAME" value="test2RemoveDupesFromArray" />
205 204
       <option name="TEST_OBJECT" value="method" />
206 205
       <method v="2">
207 206
         <option name="Make" enabled="true" />
208 207
       </method>
209 208
     </configuration>
210
-    <configuration name="ArrazTest.testFindMaxMinOfArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
209
+    <configuration name="ArrazTest.testFind2ndLargestValueFromArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
211 210
       <module name="arraz" />
212 211
       <option name="PACKAGE_NAME" value="" />
213 212
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
214
-      <option name="METHOD_NAME" value="testFindMaxMinOfArray" />
213
+      <option name="METHOD_NAME" value="testFind2ndLargestValueFromArray" />
215 214
       <option name="TEST_OBJECT" value="method" />
216 215
       <method v="2">
217 216
         <option name="Make" enabled="true" />
218 217
       </method>
219 218
     </configuration>
220
-    <configuration name="ArrazTest.testInsertIntoArrayAt" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
219
+    <configuration name="ArrazTest.testRemoveDupesFromArray" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
221 220
       <module name="arraz" />
222 221
       <option name="PACKAGE_NAME" value="" />
223 222
       <option name="MAIN_CLASS_NAME" value="ArrazTest" />
224
-      <option name="METHOD_NAME" value="testInsertIntoArrayAt" />
223
+      <option name="METHOD_NAME" value="testRemoveDupesFromArray" />
225 224
       <option name="TEST_OBJECT" value="method" />
226 225
       <method v="2">
227 226
         <option name="Make" enabled="true" />
228 227
       </method>
229 228
     </configuration>
230 229
     <list>
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 230
       <item itemvalue="JUnit.ArrazTest.test2FindMaxMinOfArray" />
231
+      <item itemvalue="JUnit.ArrazTest.testRemoveDupesFromArray" />
232
+      <item itemvalue="JUnit.ArrazTest.test2RemoveDupesFromArray" />
233
+      <item itemvalue="JUnit.ArrazTest.testFind2ndLargestValueFromArray" />
234
+      <item itemvalue="JUnit.ArrazTest.test2Find2ndLargestValueFromArray" />
236 235
     </list>
237 236
     <recent_temporary>
238 237
       <list>
238
+        <item itemvalue="JUnit.ArrazTest.test2Find2ndLargestValueFromArray" />
239
+        <item itemvalue="JUnit.ArrazTest.testFind2ndLargestValueFromArray" />
240
+        <item itemvalue="JUnit.ArrazTest.test2RemoveDupesFromArray" />
241
+        <item itemvalue="JUnit.ArrazTest.testRemoveDupesFromArray" />
239 242
         <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" />
244 243
       </list>
245 244
     </recent_temporary>
246 245
   </component>
@@ -254,47 +253,47 @@
254 253
       <option name="number" value="Default" />
255 254
       <option name="presentableId" value="Default" />
256 255
       <updated>1544046001151</updated>
257
-      <workItem from="1544046022231" duration="18399000" />
256
+      <workItem from="1544046022231" duration="21160000" />
258 257
     </task>
259 258
     <servers />
260 259
   </component>
261 260
   <component name="TestHistory">
262
-    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 21m 09s.xml">
261
+    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 32m 40s.xml">
263 262
       <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
264 263
     </history-entry>
265
-    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 22m 09s.xml">
264
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 21h 55m 22s.xml">
266 265
       <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
267 266
     </history-entry>
268
-    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 23m 02s.xml">
267
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 21h 55m 58s.xml">
269 268
       <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
270 269
     </history-entry>
271
-    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 23m 30s.xml">
272
-      <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
273
-    </history-entry>
274
-    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 23m 50s.xml">
275
-      <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
270
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 21h 59m 30s.xml">
271
+      <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
276 272
     </history-entry>
277
-    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 28m 37s.xml">
273
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 22h 10m 25s.xml">
278 274
       <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
279 275
     </history-entry>
280
-    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 28m 45s.xml">
276
+    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 22h 10m 33s.xml">
281 277
       <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
282 278
     </history-entry>
283
-    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 30m 52s.xml">
284
-      <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
285
-    </history-entry>
286
-    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 19h 32m 29s.xml">
279
+    <history-entry file="ArrazTest_testFindMaxMinOfArray - 2018.12.06 at 22h 15m 48s.xml">
287 280
       <configuration name="ArrazTest.testFindMaxMinOfArray" configurationId="JUnit" />
288 281
     </history-entry>
289
-    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 19h 32m 40s.xml">
282
+    <history-entry file="ArrazTest_test2FindMaxMinOfArray - 2018.12.06 at 22h 15m 54s.xml">
290 283
       <configuration name="ArrazTest.test2FindMaxMinOfArray" configurationId="JUnit" />
291 284
     </history-entry>
285
+    <history-entry file="ArrazTest_testRemoveDupesFromArray - 2018.12.06 at 22h 31m 40s.xml">
286
+      <configuration name="ArrazTest.testRemoveDupesFromArray" configurationId="JUnit" />
287
+    </history-entry>
288
+    <history-entry file="ArrazTest_test2RemoveDupesFromArray - 2018.12.06 at 22h 32m 31s.xml">
289
+      <configuration name="ArrazTest.test2RemoveDupesFromArray" configurationId="JUnit" />
290
+    </history-entry>
292 291
   </component>
293 292
   <component name="TimeTrackingManager">
294
-    <option name="totallyTimeSpent" value="18399000" />
293
+    <option name="totallyTimeSpent" value="21160000" />
295 294
   </component>
296 295
   <component name="ToolWindowManager">
297
-    <frame x="-332" y="-934" width="1636" height="793" extended-state="0" />
296
+    <frame x="0" y="159" width="1280" height="747" extended-state="0" />
298 297
     <editor active="true" />
299 298
     <layout>
300 299
       <window_info id="Image Layers" />
@@ -302,16 +301,16 @@
302 301
       <window_info id="UI Designer" />
303 302
       <window_info id="Capture Tool" />
304 303
       <window_info id="Favorites" side_tool="true" />
305
-      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.072145544" />
304
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.09289176" />
306 305
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
307
-      <window_info anchor="bottom" id="Messages" weight="0.3259587" />
306
+      <window_info anchor="bottom" id="Messages" weight="0.32594937" />
308 307
       <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
309 308
       <window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
310
-      <window_info anchor="bottom" id="Terminal" weight="0.3649289" />
309
+      <window_info anchor="bottom" id="Terminal" weight="0.3908228" />
311 310
       <window_info anchor="bottom" id="Event Log" side_tool="true" />
312 311
       <window_info anchor="bottom" id="Message" order="0" />
313 312
       <window_info anchor="bottom" id="Find" order="1" />
314
-      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.40855458" />
313
+      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.40822786" />
315 314
       <window_info anchor="bottom" id="Debug" order="3" weight="0.39810428" />
316 315
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
317 316
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -363,10 +362,10 @@
363 362
     </entry>
364 363
     <entry file="file://$PROJECT_DIR$/src/main/java/Arraz.java">
365 364
       <provider selected="true" editor-type-id="text-editor">
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" />
365
+        <state relative-caret-position="94">
366
+          <caret line="108" column="18" selection-start-line="108" selection-start-column="18" selection-end-line="108" selection-end-column="18" />
368 367
           <folding>
369
-            <element signature="imports" expanded="true" />
368
+            <element signature="e#1659#1668#0" expanded="true" />
370 369
             <element signature="e#1375#1376#0" expanded="true" />
371 370
             <element signature="e#1410#1411#0" expanded="true" />
372 371
             <element signature="e#1454#1455#0" expanded="true" />
@@ -385,8 +384,8 @@
385 384
     </entry>
386 385
     <entry file="file://$PROJECT_DIR$/src/test/java/ArrazTest.java">
387 386
       <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" />
387
+        <state relative-caret-position="96">
388
+          <caret line="339" column="15" selection-start-line="339" selection-start-column="15" selection-end-line="339" selection-end-column="15" />
390 389
           <folding>
391 390
             <element signature="imports" expanded="true" />
392 391
           </folding>

+ 33
- 10
arraz/src/main/java/Arraz.java 파일 보기

@@ -1,7 +1,4 @@
1
-import java.util.ArrayList;
2
-import java.util.Arrays;
3
-import java.util.Iterator;
4
-import java.util.List;
1
+import java.util.*;
5 2
 
6 3
 public class Arraz {
7 4
 
@@ -90,6 +87,36 @@ public class Arraz {
90 87
         return arr;
91 88
     }
92 89
 
90
+    public Integer[] removeDupesFromArray(Integer[] array) {
91
+        Set<Integer> list = new HashSet<Integer>();
92
+        int count = 0;
93
+
94
+        for (Integer i : array){
95
+            list.add(i);
96
+        }
97
+
98
+        int len = list.size();
99
+        Integer[] newArr = new Integer[len];
100
+
101
+        for (Integer i : list){
102
+            newArr[count] = i;
103
+            count++;
104
+        }
105
+
106
+        return newArr;
107
+    }
108
+
109
+    public Integer find2ndLargestValueFromArray(Integer[] array) {
110
+        if (array.length < 2){
111
+            return -1;
112
+        }
113
+
114
+        Integer[] arr = new Integer[array.length];
115
+                Arrays.sort(array);
116
+
117
+        return array[array.length - 2];
118
+    }
119
+
93 120
     public class OddEven {
94 121
         public int odds;
95 122
         public int evens;
@@ -186,8 +213,8 @@ public class Arraz {
186 213
     public MaxMin findMaxMinOfArray(int[] array) {
187 214
         MaxMin mn = new MaxMin();
188 215
 
189
-        mn.max = array[0];
190
-        mn.min = array[0];
216
+        mn.setMax(array[0]);
217
+        mn.setMin(array[0]);
191 218
 
192 219
         for (int i : array){
193 220
             if ( i > mn.getMax() ){
@@ -197,12 +224,8 @@ public class Arraz {
197 224
             if ( i < mn.getMin() ){
198 225
                 mn.setMin(i);
199 226
             }
200
-
201
-            System.out.println("Max is: " + mn.max);
202
-            System.out.println("Min is: " + mn.min);
203 227
         }
204 228
 
205 229
         return mn;
206
-
207 230
     }
208 231
 }

+ 46
- 3
arraz/src/test/java/ArrazTest.java 파일 보기

@@ -286,11 +286,12 @@ public class ArrazTest {
286 286
         int[] array = {1,5,2,4,3};
287 287
         int expected = 5;
288 288
 
289
+        Arraz arraz = new Arraz();
289 290
         Arraz.MaxMin mn = arraz.new MaxMin();
290 291
 
291 292
         arraz.findMaxMinOfArray(array);
292 293
 
293
-        Assert.assertEquals(expected, mn.getMax());
294
+        Assert.assertEquals(expected, arraz.findMaxMinOfArray(array).getMax());
294 295
 
295 296
     }
296 297
 
@@ -300,13 +301,55 @@ public class ArrazTest {
300 301
         int[] array = {1,5,2,-1,0};
301 302
         int expected = -1;
302 303
 
304
+        Arraz arraz = new Arraz();
303 305
         Arraz.MaxMin mn = arraz.new MaxMin();
304 306
 
305
-        arraz.findMaxMinOfArray(array);
306 307
 
307
-        Assert.assertEquals(expected, mn.getMin());
308
+        Assert.assertEquals(expected, arraz.findMaxMinOfArray(array).getMin());
309
+
310
+    }
311
+
312
+    @Test
313
+    public void testRemoveDupesFromArray(){
314
+
315
+        Integer[] array = {1,2,3,2,4,4,5,6,7,7,8};
316
+
317
+        Integer[] expected = {1,2,3,4,5,6,7,8};
318
+        Integer[] actual = arraz.removeDupesFromArray(array);
319
+
320
+        Assert.assertEquals(expected, actual);
321
+    }
322
+
323
+    @Test
324
+    public void test2RemoveDupesFromArray(){
325
+
326
+        Integer[] array = {1,1,1,1,1,1,1,1};
327
+
328
+        Integer[] expected = {1};
329
+        Integer[] actual = arraz.removeDupesFromArray(array);
330
+
331
+        Assert.assertEquals(expected, actual);
332
+    }
333
+
334
+    @Test
335
+    public void testFind2ndLargestValueFromArray(){
336
+
337
+        Integer[] array = {1,2,3,4,5};
338
+
339
+        Integer expected = 4;
340
+        Integer actual = arraz.find2ndLargestValueFromArray(array);
308 341
 
342
+        Assert.assertEquals(expected, actual);
309 343
     }
310 344
 
345
+    @Test
346
+    public void test2Find2ndLargestValueFromArray(){
347
+
348
+        Integer[] array = {1};
311 349
 
350
+        Integer expected = -1;
351
+        Integer actual = arraz.find2ndLargestValueFromArray(array);
352
+
353
+        Assert.assertEquals(expected, actual);
354
+    }
312 355
 }