Przeglądaj źródła

simulate and copyAndZeroOut wokring

Amy Gill 6 lat temu
rodzic
commit
df1cbb5b3e

+ 66
- 45
.idea/workspace.xml Wyświetl plik

@@ -2,12 +2,6 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="26347f4d-713c-461d-b161-a64822c4681e" name="Default" comment="">
5
-      <change beforePath="" afterPath="$PROJECT_DIR$/.idea/.name" />
6
-      <change beforePath="$PROJECT_DIR$/.idea/Game-Of-Life-Java.iml" afterPath="$PROJECT_DIR$/Game-Of-Life-Java.iml" />
7
-      <change beforePath="$PROJECT_DIR$/.idea/misc.xml" afterPath="$PROJECT_DIR$/.idea/misc.xml" />
8
-      <change beforePath="$PROJECT_DIR$/.idea/modules.xml" afterPath="$PROJECT_DIR$/.idea/modules.xml" />
9
-      <change beforePath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterPath="" />
10
-      <change beforePath="$PROJECT_DIR$/.idea/vcs.xml" afterPath="$PROJECT_DIR$/.idea/vcs.xml" />
11 5
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
12 6
       <change beforePath="$PROJECT_DIR$/src/main/java/com/zipcodeconway/ConwayGameOfLife.java" afterPath="$PROJECT_DIR$/src/main/java/com/zipcodeconway/ConwayGameOfLife.java" />
13 7
       <change beforePath="$PROJECT_DIR$/src/test/java/com/zipcodeconway/ConwayGameOfLifeTest.java" afterPath="$PROJECT_DIR$/src/test/java/com/zipcodeconway/ConwayGameOfLifeTest.java" />
@@ -21,7 +15,7 @@
21 15
     <option name="LAST_RESOLUTION" value="IGNORE" />
22 16
   </component>
23 17
   <component name="FileEditorManager">
24
-    <splitter split-orientation="horizontal" split-proportion="0.56901747">
18
+    <splitter split-orientation="horizontal" split-proportion="0.7649186">
25 19
       <split-first>
26 20
         <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
27 21
           <file leaf-file-name="SimpleWindow.java" pinned="false" current-in-tab="false">
@@ -37,8 +31,8 @@
37 31
           <file leaf-file-name="ConwayGameOfLife.java" pinned="false" current-in-tab="true">
38 32
             <entry file="file://$PROJECT_DIR$/src/main/java/com/zipcodeconway/ConwayGameOfLife.java">
39 33
               <provider selected="true" editor-type-id="text-editor">
40
-                <state relative-caret-position="450">
41
-                  <caret line="30" column="0" lean-forward="true" selection-start-line="30" selection-start-column="0" selection-end-line="30" selection-end-column="0" />
34
+                <state relative-caret-position="410">
35
+                  <caret line="54" column="43" lean-forward="false" selection-start-line="54" selection-start-column="43" selection-end-line="54" selection-end-column="43" />
42 36
                   <folding />
43 37
                 </state>
44 38
               </provider>
@@ -51,8 +45,8 @@
51 45
           <file leaf-file-name="ConwayGameOfLifeTest.java" pinned="false" current-in-tab="true">
52 46
             <entry file="file://$PROJECT_DIR$/src/test/java/com/zipcodeconway/ConwayGameOfLifeTest.java">
53 47
               <provider selected="true" editor-type-id="text-editor">
54
-                <state relative-caret-position="570">
55
-                  <caret line="76" column="23" lean-forward="false" selection-start-line="76" selection-start-column="23" selection-end-line="76" selection-end-column="23" />
48
+                <state relative-caret-position="593">
49
+                  <caret line="44" column="50" lean-forward="true" selection-start-line="44" selection-start-column="50" selection-end-line="44" selection-end-column="50" />
56 50
                   <folding />
57 51
                 </state>
58 52
               </provider>
@@ -188,7 +182,7 @@
188 182
       </list>
189 183
     </option>
190 184
   </component>
191
-  <component name="RunManager" selected="JUnit.ConwayGameOfLifeTest.edgeTest">
185
+  <component name="RunManager" selected="JUnit.ConwayGameOfLifeTest.runTest2">
192 186
     <configuration default="true" type="Applet" factoryName="Applet">
193 187
       <option name="HTML_USED" value="false" />
194 188
       <option name="WIDTH" value="400" />
@@ -260,6 +254,31 @@
260 254
       <envs />
261 255
       <patterns />
262 256
     </configuration>
257
+    <configuration name="ConwayGameOfLifeTest.runTest1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
258
+      <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea">
259
+        <pattern>
260
+          <option name="PATTERN" value="com.zipcodeconway.*" />
261
+          <option name="ENABLED" value="true" />
262
+        </pattern>
263
+      </extension>
264
+      <module name="Game-Of-Life-Java" />
265
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
266
+      <option name="ALTERNATIVE_JRE_PATH" />
267
+      <option name="PACKAGE_NAME" value="com.zipcodeconway" />
268
+      <option name="MAIN_CLASS_NAME" value="com.zipcodeconway.ConwayGameOfLifeTest" />
269
+      <option name="METHOD_NAME" value="runTest1" />
270
+      <option name="TEST_OBJECT" value="method" />
271
+      <option name="VM_PARAMETERS" value="-ea" />
272
+      <option name="PARAMETERS" />
273
+      <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
274
+      <option name="ENV_VARIABLES" />
275
+      <option name="PASS_PARENT_ENVS" value="true" />
276
+      <option name="TEST_SEARCH_SCOPE">
277
+        <value defaultName="singleModule" />
278
+      </option>
279
+      <envs />
280
+      <patterns />
281
+    </configuration>
263 282
     <configuration name="ConwayGameOfLifeTest.runTest2" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
264 283
       <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea">
265 284
         <pattern>
@@ -345,16 +364,18 @@
345 364
       <option name="PROGRAM_PARAMETERS" />
346 365
       <predefined_log_file id="idea.log" enabled="true" />
347 366
     </configuration>
348
-    <list size="3">
367
+    <list size="4">
349 368
       <item index="0" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.isAliveTest" />
350 369
       <item index="1" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.runTest2" />
351 370
       <item index="2" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.edgeTest" />
371
+      <item index="3" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.runTest1" />
352 372
     </list>
353 373
     <recent_temporary>
354
-      <list size="3">
355
-        <item index="0" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.edgeTest" />
356
-        <item index="1" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.isAliveTest" />
357
-        <item index="2" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.runTest2" />
374
+      <list size="4">
375
+        <item index="0" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.runTest2" />
376
+        <item index="1" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.runTest1" />
377
+        <item index="2" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.edgeTest" />
378
+        <item index="3" class="java.lang.String" itemvalue="JUnit.ConwayGameOfLifeTest.isAliveTest" />
358 379
       </list>
359 380
     </recent_temporary>
360 381
   </component>
@@ -372,44 +393,44 @@
372 393
       <option name="presentableId" value="Default" />
373 394
       <updated>1520867652526</updated>
374 395
       <workItem from="1520867656190" duration="4128000" />
375
-      <workItem from="1520872722088" duration="3717000" />
396
+      <workItem from="1520872722088" duration="7338000" />
376 397
     </task>
377 398
     <servers />
378 399
   </component>
379 400
   <component name="TestHistory">
380
-    <history-entry file="ConwayGameOfLifeTest_edgeTest - 2018.03.12 at 13h 12m 33s.xml">
381
-      <configuration name="ConwayGameOfLifeTest.edgeTest" configurationId="JUnit" />
401
+    <history-entry file="ConwayGameOfLifeTest_runTest1 - 2018.03.12 at 14h 02m 05s.xml">
402
+      <configuration name="ConwayGameOfLifeTest.runTest1" configurationId="JUnit" />
382 403
     </history-entry>
383
-    <history-entry file="ConwayGameOfLifeTest_edgeTest - 2018.03.12 at 13h 13m 13s.xml">
384
-      <configuration name="ConwayGameOfLifeTest.edgeTest" configurationId="JUnit" />
404
+    <history-entry file="ConwayGameOfLifeTest_runTest1 - 2018.03.12 at 14h 02m 14s.xml">
405
+      <configuration name="ConwayGameOfLifeTest.runTest1" configurationId="JUnit" />
385 406
     </history-entry>
386
-    <history-entry file="ConwayGameOfLifeTest_edgeTest - 2018.03.12 at 13h 13m 38s.xml">
387
-      <configuration name="ConwayGameOfLifeTest.edgeTest" configurationId="JUnit" />
407
+    <history-entry file="ConwayGameOfLifeTest_runTest1 - 2018.03.12 at 14h 12m 14s.xml">
408
+      <configuration name="ConwayGameOfLifeTest.runTest1" configurationId="JUnit" />
388 409
     </history-entry>
389
-    <history-entry file="ConwayGameOfLifeTest_edgeTest - 2018.03.12 at 13h 14m 04s.xml">
390
-      <configuration name="ConwayGameOfLifeTest.edgeTest" configurationId="JUnit" />
410
+    <history-entry file="ConwayGameOfLifeTest_runTest1 - 2018.03.12 at 14h 35m 45s.xml">
411
+      <configuration name="ConwayGameOfLifeTest.runTest1" configurationId="JUnit" />
391 412
     </history-entry>
392
-    <history-entry file="ConwayGameOfLifeTest_edgeTest - 2018.03.12 at 13h 23m 38s.xml">
393
-      <configuration name="ConwayGameOfLifeTest.edgeTest" configurationId="JUnit" />
413
+    <history-entry file="ConwayGameOfLifeTest_runTest2 - 2018.03.12 at 13h 57m 25s.xml">
414
+      <configuration name="ConwayGameOfLifeTest.runTest2" configurationId="JUnit" />
394 415
     </history-entry>
395
-    <history-entry file="ConwayGameOfLifeTest_isAliveTest - 2018.03.12 at 12h 49m 47s.xml">
396
-      <configuration name="ConwayGameOfLifeTest.isAliveTest" configurationId="JUnit" />
416
+    <history-entry file="ConwayGameOfLifeTest_runTest2 - 2018.03.12 at 14h 02m 09s.xml">
417
+      <configuration name="ConwayGameOfLifeTest.runTest2" configurationId="JUnit" />
397 418
     </history-entry>
398
-    <history-entry file="ConwayGameOfLifeTest_isAliveTest - 2018.03.12 at 12h 51m 24s.xml">
399
-      <configuration name="ConwayGameOfLifeTest.isAliveTest" configurationId="JUnit" />
419
+    <history-entry file="ConwayGameOfLifeTest_runTest2 - 2018.03.12 at 14h 35m 52s.xml">
420
+      <configuration name="ConwayGameOfLifeTest.runTest2" configurationId="JUnit" />
400 421
     </history-entry>
401
-    <history-entry file="ConwayGameOfLifeTest_isAliveTest - 2018.03.12 at 12h 54m 30s.xml">
402
-      <configuration name="ConwayGameOfLifeTest.isAliveTest" configurationId="JUnit" />
422
+    <history-entry file="ConwayGameOfLifeTest_runTest2 - 2018.03.12 at 14h 42m 04s.xml">
423
+      <configuration name="ConwayGameOfLifeTest.runTest2" configurationId="JUnit" />
403 424
     </history-entry>
404
-    <history-entry file="ConwayGameOfLifeTest_isAliveTest - 2018.03.12 at 12h 56m 35s.xml">
405
-      <configuration name="ConwayGameOfLifeTest.isAliveTest" configurationId="JUnit" />
425
+    <history-entry file="ConwayGameOfLifeTest_runTest2 - 2018.03.12 at 14h 42m 23s.xml">
426
+      <configuration name="ConwayGameOfLifeTest.runTest2" configurationId="JUnit" />
406 427
     </history-entry>
407
-    <history-entry file="ConwayGameOfLifeTest_isAliveTest - 2018.03.12 at 13h 23m 35s.xml">
408
-      <configuration name="ConwayGameOfLifeTest.isAliveTest" configurationId="JUnit" />
428
+    <history-entry file="ConwayGameOfLifeTest_runTest2 - 2018.03.12 at 14h 43m 18s.xml">
429
+      <configuration name="ConwayGameOfLifeTest.runTest2" configurationId="JUnit" />
409 430
     </history-entry>
410 431
   </component>
411 432
   <component name="TimeTrackingManager">
412
-    <option name="totallyTimeSpent" value="7845000" />
433
+    <option name="totallyTimeSpent" value="11466000" />
413 434
   </component>
414 435
   <component name="ToolWindowManager">
415 436
     <frame x="-317" y="-1057" width="1882" height="1057" extended-state="0" />
@@ -424,8 +445,8 @@
424 445
       <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
425 446
       <window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
426 447
       <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
427
-      <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.23180874" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
428
-      <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32952183" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
448
+      <window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.23180874" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
449
+      <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32952183" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
429 450
       <window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
430 451
       <window_info id="Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
431 452
       <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.09836957" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
@@ -489,16 +510,16 @@
489 510
     </entry>
490 511
     <entry file="file://$PROJECT_DIR$/src/test/java/com/zipcodeconway/ConwayGameOfLifeTest.java">
491 512
       <provider selected="true" editor-type-id="text-editor">
492
-        <state relative-caret-position="570">
493
-          <caret line="76" column="23" lean-forward="false" selection-start-line="76" selection-start-column="23" selection-end-line="76" selection-end-column="23" />
513
+        <state relative-caret-position="593">
514
+          <caret line="44" column="50" lean-forward="true" selection-start-line="44" selection-start-column="50" selection-end-line="44" selection-end-column="50" />
494 515
           <folding />
495 516
         </state>
496 517
       </provider>
497 518
     </entry>
498 519
     <entry file="file://$PROJECT_DIR$/src/main/java/com/zipcodeconway/ConwayGameOfLife.java">
499 520
       <provider selected="true" editor-type-id="text-editor">
500
-        <state relative-caret-position="450">
501
-          <caret line="30" column="0" lean-forward="true" selection-start-line="30" selection-start-column="0" selection-end-line="30" selection-end-column="0" />
521
+        <state relative-caret-position="410">
522
+          <caret line="54" column="43" lean-forward="false" selection-start-line="54" selection-start-column="43" selection-end-line="54" selection-end-column="43" />
502 523
           <folding />
503 524
         </state>
504 525
       </provider>

+ 22
- 1
src/main/java/com/zipcodeconway/ConwayGameOfLife.java Wyświetl plik

@@ -5,14 +5,17 @@ public class ConwayGameOfLife {
5 5
     private Integer edge;
6 6
     int[][] currentGen;
7 7
     int[][] nextGen;
8
+    private SimpleWindow ourDisplayWindow;
8 9
 
9 10
 
10 11
     public ConwayGameOfLife(Integer dimension) {
12
+        this.ourDisplayWindow= new SimpleWindow(dimension);
11 13
         this.edge=dimension-1;
12 14
         this.nextGen = new int[dimension][dimension];
13 15
     }
14 16
 
15 17
     public ConwayGameOfLife(Integer dimension, int[][] startMatrix) {
18
+        this.ourDisplayWindow= new SimpleWindow(dimension);
16 19
         this.edge=dimension-1;
17 20
         this.currentGen = startMatrix;
18 21
         this.nextGen = new int[dimension][dimension];
@@ -35,13 +38,31 @@ public class ConwayGameOfLife {
35 38
 
36 39
     public int[][] simulate(Integer maxGenerations) {
37 40
 
41
+        for (int i = 0; i <= maxGenerations; i++){
42
+            this.ourDisplayWindow.display(currentGen, i);
43
+            this.ourDisplayWindow.sleep(125);
44
+            copyAndZeroOut(nextGen,currentGen);
45
+        }
38 46
 
39
-        return new int[1][1];
47
+        return currentGen;
40 48
     }
41 49
 
42 50
     // copy the values of 'next' matrix to 'current' matrix,
43 51
     // and then zero out the contents of 'next' matrix
44 52
     public void copyAndZeroOut(int[][] next, int[][] current) {
53
+        for (int i = 0; i < next.length ; i++){
54
+            for (int j = 0; j <next.length; j++) {
55
+                next[i][j] = isAlive(i,j,current);
56
+            }
57
+        }
58
+
59
+        for (int i = 0; i < next.length ; i++){
60
+            for (int j = 0; j <next.length; j++) {
61
+                current[i][j] = next[i][j];
62
+                next[i][j] = 0;
63
+
64
+            }
65
+        }
45 66
     }
46 67
 
47 68
     // Calculate if an individual cell should be alive in the next generation.

+ 7
- 0
src/test/java/com/zipcodeconway/ConwayGameOfLifeTest.java Wyświetl plik

@@ -45,6 +45,13 @@ public class ConwayGameOfLifeTest {
45 45
         assertTrue(java.util.Arrays.deepEquals(results, expected));
46 46
     }
47 47
 
48
+//    @Test
49
+//    public void copyAndZeroOutTest(){
50
+//        ConwayGameOfLife sim = new ConwayGameOfLife(5);
51
+//        //Given
52
+//
53
+//    }
54
+
48 55
     @Test
49 56
     public void isAliveTest(){
50 57