forked from tpapendieck/ciip-examples
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
package de.edu.hsfulda.ciip.tdd;
|
|
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
import static org.junit.Assert.assertThat;
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.Parameterized;
|
|
import org.junit.runners.Parameterized.Parameter;
|
|
import org.junit.runners.Parameterized.Parameters;
|
|
|
|
@RunWith(Parameterized.class)
|
|
public class StatusDeadTest {
|
|
private static State[] states = { mock(State.class, "alife"), new StateDead() };
|
|
private static final int alife = 0;
|
|
private static final int dead = 1;
|
|
|
|
@Parameters(name = "{index}: condition: {0} expected: {2}")
|
|
public static Collection<Object[]> data() {
|
|
|
|
return Arrays
|
|
.asList(new Object[][] { { "all dead", 0, dead }, { "one alife", 1, dead }, { "two alife", 2, dead },
|
|
{ "four alife", 4, dead }, { "five alife", 5, dead }, { "three alife", 3, alife } });
|
|
}
|
|
|
|
@Parameter // first data value (0) is default
|
|
public /* NOT private */ String assertMessage;
|
|
|
|
@Parameter(1)
|
|
public /* NOT private */ int aliveneigborCount;
|
|
|
|
@Parameter(2)
|
|
public /* NOT private */ int expected;
|
|
|
|
@Test
|
|
public void calculateNextState() {
|
|
// arrange
|
|
List<State> neigborStates = new ArrayList<>();
|
|
for (int i = 0; i < aliveneigborCount; i++)
|
|
neigborStates.add(states[alife]);
|
|
while (neigborStates.size() < 8) {
|
|
neigborStates.add(states[dead]);
|
|
}
|
|
Collections.shuffle(neigborStates);
|
|
|
|
// act
|
|
State stateDead = states[dead];
|
|
State result = stateDead.nextBy(neigborStates);
|
|
|
|
// assert
|
|
assertThat(assertMessage, result, equalTo(states[expected]));
|
|
}
|
|
|
|
}
|