<commit_before>package edu.pdx.cs410J.whitlock;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 * Unit tests for the Student class.  In addition to the JUnit annotations,
 * they also make use of the <a href="http://hamcrest.org/JavaHamcrest/">hamcrest</a>
 * matchers for more readable assertion statements.
 */
public class GameOfLifeTest
{

  @Test
  public void oneDeadCellStaysDead() {
    GameOfLife game = new GameOfLife(1, 1);
    game.addRow(".");
    game.computeNextGeneration();
    assertThat(game.getRow(0), equalTo("."));
  }

  @Test
  public void oneLiveCellDies() {
    GameOfLife game = new GameOfLife(1, 1);
    game.addRow("*");
    game.computeNextGeneration();
    assertThat(game.getRow(0), equalTo("."));
  }

  @Test
  public void noLiveNeighborsAtTopLeft() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("*.");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(0, 0), equalTo(0));
  }

  @Test
  public void oneLiveNeighborToTheNorthwest() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("*.");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 1), equalTo(1));
  }

  @Test
  public void oneLiveNeighborToTheNorth() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("*.");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 0), equalTo(1));
  }

  @Test
  public void noLiveNeighborsAtTopRight() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(0, 1), equalTo(0));
  }

  @Test
  public void oneLiveNeighborToTheNortheast() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow(".*");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 0), equalTo(1));
  }

  @Test
  public void oneLiveNeighborToTheEast() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow(".*");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(0, 0), equalTo(1));
  }

  @Test
  public void noLiveNeighborsAtBottomRight() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 1), equalTo(0));
  }

  @Test
  public void oneLiveNeighborToTheSoutheast() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow(".*");
    assertThat(game.getNumberOfLiveNeighbors(0, 0), equalTo(1));
  }

  @Test
  public void oneLiveNeighborToTheSouth() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow(".*");
    assertThat(game.getNumberOfLiveNeighbors(0, 1), equalTo(1));
  }

  @Test
  public void noLiveNeighborsAtBottomLeft() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 0), equalTo(0));
  }

  @Test
  public void oneLiveNeighborToTheSouthwest() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("*.");
    assertThat(game.getNumberOfLiveNeighbors(0, 1), equalTo(1));
  }

  @Test
  public void oneLiveNeighborToTheWest() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("*.");
    assertThat(game.getNumberOfLiveNeighbors(1, 1), equalTo(1));
  }

  @Test
  public void liveCellWithTwoNeighborsLives() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("**");
    game.addRow("*.");
    game.computeNextGeneration();
    assertThat(game.getRow(0), equalTo("**"));
    assertThat(game.getRow(1).charAt(0), equalTo('*'));
  }

  @Test
  public void deadCellWithThreeLiveNeighborsBecomesAlive() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("**");
    game.addRow("*.");
    game.computeNextGeneration();
    assertThat(game.getRow(1).charAt(1), equalTo('*'));
  }

  @Test
  public void deadCellWithFourLiveNeighborsStaysDead() {
    GameOfLife game = new GameOfLife(2, 3);
    game.addRow("**.");
    game.addRow("*.*");
    game.computeNextGeneration();
    assertThat(game.getRow(1).charAt(1), equalTo('.'));
  }

  @Test
  public void testThatNextGenerationIsOnlyBasedOnPreviousGeneration() {
    GameOfLife game = new GameOfLife(2, 3);
    game.addRow("*.*");
    game.addRow("..*");
    assertThat(game.getCell(1, 1), equalTo(GameOfLife.DEAD_CELL));
    assertThat(game.getNumberOfLiveNeighbors(1, 1), equalTo(3));
    game.computeNextGeneration();
    assertThat(game.getRow(1).charAt(1), equalTo('*'));

  }

}
<commit_msg>Test multiple generations.<commit_after>package edu.pdx.cs410J.whitlock;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 * Unit tests for the Student class.  In addition to the JUnit annotations,
 * they also make use of the <a href="http://hamcrest.org/JavaHamcrest/">hamcrest</a>
 * matchers for more readable assertion statements.
 */
public class GameOfLifeTest
{

  @Test
  public void oneDeadCellStaysDead() {
    GameOfLife game = new GameOfLife(1, 1);
    game.addRow(".");
    game.computeNextGeneration();
    assertThat(game.getRow(0), equalTo("."));
  }

  @Test
  public void oneLiveCellDies() {
    GameOfLife game = new GameOfLife(1, 1);
    game.addRow("*");
    game.computeNextGeneration();
    assertThat(game.getRow(0), equalTo("."));
  }

  @Test
  public void noLiveNeighborsAtTopLeft() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("*.");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(0, 0), equalTo(0));
  }

  @Test
  public void oneLiveNeighborToTheNorthwest() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("*.");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 1), equalTo(1));
  }

  @Test
  public void oneLiveNeighborToTheNorth() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("*.");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 0), equalTo(1));
  }

  @Test
  public void noLiveNeighborsAtTopRight() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(0, 1), equalTo(0));
  }

  @Test
  public void oneLiveNeighborToTheNortheast() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow(".*");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 0), equalTo(1));
  }

  @Test
  public void oneLiveNeighborToTheEast() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow(".*");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(0, 0), equalTo(1));
  }

  @Test
  public void noLiveNeighborsAtBottomRight() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 1), equalTo(0));
  }

  @Test
  public void oneLiveNeighborToTheSoutheast() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow(".*");
    assertThat(game.getNumberOfLiveNeighbors(0, 0), equalTo(1));
  }

  @Test
  public void oneLiveNeighborToTheSouth() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow(".*");
    assertThat(game.getNumberOfLiveNeighbors(0, 1), equalTo(1));
  }

  @Test
  public void noLiveNeighborsAtBottomLeft() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("..");
    assertThat(game.getNumberOfLiveNeighbors(1, 0), equalTo(0));
  }

  @Test
  public void oneLiveNeighborToTheSouthwest() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("*.");
    assertThat(game.getNumberOfLiveNeighbors(0, 1), equalTo(1));
  }

  @Test
  public void oneLiveNeighborToTheWest() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("..");
    game.addRow("*.");
    assertThat(game.getNumberOfLiveNeighbors(1, 1), equalTo(1));
  }

  @Test
  public void liveCellWithTwoNeighborsLives() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("**");
    game.addRow("*.");
    game.computeNextGeneration();
    assertThat(game.getRow(0), equalTo("**"));
    assertThat(game.getRow(1).charAt(0), equalTo('*'));
  }

  @Test
  public void deadCellWithThreeLiveNeighborsBecomesAlive() {
    GameOfLife game = new GameOfLife(2, 2);
    game.addRow("**");
    game.addRow("*.");
    game.computeNextGeneration();
    assertThat(game.getRow(1).charAt(1), equalTo('*'));
  }

  @Test
  public void deadCellWithFourLiveNeighborsStaysDead() {
    GameOfLife game = new GameOfLife(2, 3);
    game.addRow("**.");
    game.addRow("*.*");
    game.computeNextGeneration();
    assertThat(game.getRow(1).charAt(1), equalTo('.'));
  }

  @Test
  public void nextGenerationIsOnlyBasedOnPreviousGeneration() {
    GameOfLife game = new GameOfLife(2, 3);
    game.addRow("*.*");
    game.addRow("..*");
    assertThat(game.getCell(1, 1), equalTo(GameOfLife.DEAD_CELL));
    assertThat(game.getNumberOfLiveNeighbors(1, 1), equalTo(3));
    game.computeNextGeneration();
    assertThat(game.getRow(1).charAt(1), equalTo('*'));
  }

  @Test
  public void multipleGenerationsAndEveryoneDies() {
    GameOfLife game = new GameOfLife(2, 3);
    game.addRow("*.*");
    game.addRow("..*");
    game.computeNextGeneration();

    assertThat(game.getRow(0), equalTo(".*."));
    assertThat(game.getRow(1), equalTo(".*."));

    game.computeNextGeneration();

    assertThat(game.getRow(0), equalTo("..."));
    assertThat(game.getRow(1), equalTo("..."));
  }

}

{'fraction_non_alphanumeric': 0.168141592920354, 'fraction_numerical': 0.019573138990109318, 'mean_word_length': 3.8319919517102616, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3316500', 'n_tokens_mistral': 3554, 'n_tokens_neox': 3393, 'n_words': 617}