<commit_before>package ru.game_of_life

import org.junit.Test

import static ru.game_of_life.Conway2.Field.*

/**
 * User: dima
 * Date: 23/10/2012
 */
class Conway2 {
  @Test void whenAllCellsAreDeadNothingHappens() {
    assert new Field("""
---
---
---
""").next() == new Field("""
---
---
---
""")
  }

  @Test void lonelyCellDies() {
    assert new Field("""
---
-0-
---
""").next() == new Field("""
---
---
---
""")
  }

  @Test void crowdedCellDies() {
    assert new Field("""
0-0
-0-
0-0
""").next().cellAt(1, 1) == DEAD_CELL
  }

  static class Field {
    static NONE = " "
    static DEAD_CELL = "-"
    static ALIVE_CELL = "0"

    private final List<List> data

    Field(String s) {
      data = s.trim().split("\n").collect{ it.toList() }
    }

    Field(List<List> data) {
      this.data = data
    }

    Field next() {
      def isLonelyCell = { row, col -> true }

      def newData = (0..<data.size()).collect{ (0..<data.size()).collect{ NONE }}
      for (int row = 0; row < data.size; row++) {
        for (int col = 0; col < data.size; col++) {
          if (isLonelyCell(row, col)) newData[row][col] = DEAD_CELL
          else newData[row][col] = data[row][col]<commit_msg>conway game of life (groovy) 5<commit_after>package ru.game_of_life

import org.junit.Test

import static ru.game_of_life.Conway2.Field.*

/**
 * User: dima
 * Date: 23/10/2012
 */
class Conway2 {
  @Test void whenAllCellsAreDeadNothingHappens() {
    assert new Field("""
---
---
---
""").next() == new Field("""
---
---
---
""")
  }

  @Test void lonelyCellDies() {
    assert new Field("""
---
-0-
---
""").next() == new Field("""
---
---
---
""")
  }

  @Test void crowdedCellDies() {
    assert new Field("""
0-0
-0-
0-0
""").next().cellAt(1, 1) == DEAD_CELL
  }

  @Test void cellWithJustEnoughNeighborsBecomesAlive() {
    assert new Field("""
0-0
---
---
""").next().cellAt(1, 1) == ALIVE_CELL
  }

  static class Field {
    static NONE = " "
    static DEAD_CELL = "-"
    static ALIVE_CELL = "0"

    private final List<List> data

    Field(String s) {
      data = s.trim().split("\n").collect{ it.toList() }
    }

    Field(List<List> data) {
      this.data = data
    }

    Field next() {
      def isLonelyCell = { row, col -> true }

      def newData = (0..<data.size()).collect{ (0..<data.size()).collect{ NONE }}
      for (int row = 0; row < data.size; row++) {
        for (int col = 0; col < data.size; col++) {
          if (isLonelyCell(row, col)) newData[row][col] = DEAD_CELL
          else newData[row][col] = data[row][col]
{'fraction_non_alphanumeric': 0.20626223091976517, 'fraction_numerical': 0.019960861056751468, 'mean_word_length': 2.3499344692005244, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '126170', 'n_tokens_mistral': 1002, 'n_tokens_neox': 955, 'n_words': 216}