Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.class
.idea/
.project
JavaLife.iml
out/

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
6 changes: 6 additions & 0 deletions com/laboon/JavaLife.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.laboon;


public class JavaLife {

/**
Expand Down Expand Up @@ -71,6 +72,11 @@ public static void main(String[] args) {
System.exit(1);
}
JavaLife jl = new JavaLife(size, seed, percent, maxIterations);
/*try{
Thread.sleep(200000);
}catch(InterruptedException e){

}*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

????

}

}
19 changes: 17 additions & 2 deletions com/laboon/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public World iterate() {
*/

public String toString() {
String toReturn = " ";
/*String toReturn = " ";
for (int j= 0; j < _size; j++) {
toReturn += String.valueOf(j % 10);
}
Expand All @@ -127,7 +127,22 @@ public String toString() {
}
toReturn += "\n";
}
return toReturn;
return toReturn;// this code is bad, and you should feel bad */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made deliberately inefficient, so I don't feel too bad. I think I did a good job of making it poorly written!


StringBuilder sb = new StringBuilder(" ");
for(int j=0; j<_size; j++){
sb.append(j % 10);
}
sb.append("\n");
for(int j=0; j<_size; j++){
sb.append(j%10).append(" ");
for(int k=0; k<_size; k++){
sb.append(_world[j][k].getStateRep());
}
sb.append("\n");
}
return sb.toString();

}

/**
Expand Down
44 changes: 44 additions & 0 deletions com/laboon/WorldTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Created by steven on 3/31/15.
*/

package com.laboon;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;


public class WorldTest {

@Test
public void testZero(){
World testWorld = new World(0,25,25);
String out = testWorld.toString();
assertEquals(" \n", out);
}

@Test
public void testSeed(){
World testWorld = new World(2,25,25);
String out = testWorld.toString();
String expected = " 01\n0 ..\n1 ..";
assertEquals(expected, out);
}

@Test
public void testDead(){
World testWorld = new World(2, 25, 0);
String out = testWorld.toString();
String expected = " 01\n0 ..\n1 ..";
assertEquals(expected, out);
}

@Test
public void testAlive(){
World testWorld = new World(2,25,100);
String out = testWorld.toString();
String expected = "01\n0 XX\n1 XX"
assertEquals(expected, out);
}

}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could check some larger sizes, more edge cases, more complex worlds, etc. But overall pretty good.