예제 #1
0
 def test_blinker(self):
     rules = day11.gol_rules()
     start = ["..........", \
              "..........", \
              "..........", \
              "..........", \
              "..........", \
              "...###....", \
              "..........", \
              "..........", \
              "..........", \
              ".........." ]
     expet = ["..........", \
              "..........", \
              "..........", \
              "..........", \
              "....#.....", \
              "....#.....", \
              "....#.....", \
              "..........", \
              "..........", \
              ".........." ]
     ca = day11.Automaton(day11.lines_to_grid(start), rules)
     ca.generation()
     self.assertEqual(ca.grid(), day11.lines_to_grid(expet))
     ca.generation()
     self.assertEqual(ca.grid(), day11.lines_to_grid(start))
     ca.generation()
     self.assertEqual(ca.grid(), day11.lines_to_grid(expet))
     ca.generation()
     self.assertEqual(ca.grid(), day11.lines_to_grid(start))
예제 #2
0
 def test_run_to_stable(self):
     rules = day11.part_1_rules()
     start = [
         "L.LL.LL.LL", "LLLLLLL.LL", "L.L.L..L..", "LLLL.LL.LL",
         "L.LL.LL.LL", "L.LLLLL.LL", "..L.L.....", "LLLLLLLLLL",
         "L.LLLLLL.L", "L.LLLLL.LL"
     ]
     ca = day11.Automaton(day11.lines_to_grid(start), rules)
     ca.run_to_stable()
     expect = day11.lines_to_grid([
         "#.#L.L#.##", "#LLL#LL.L#", "L.#.L..#..", "#L##.##.L#",
         "#.#L.LL.LL", "#.#L#L#.##", "..L.L.....", "#L#L##L#L#",
         "#.LLLLLL.L", "#.#L#L#.##"
     ])
     self.assertEqual(expect, ca.grid())
     self.assertEqual(37, ca.count_occupied())
예제 #3
0
 def test_visibility(self):
     rules = day11.part_2_rules()
     start = [
         "L.LL.LL.LL", "LLLLLLL.LL", "L.L.L..L..", "LLLL.LL.LL",
         "L.LL.LL.LL", "L.LLLLL.LL", "..L.L.....", "LLLLLLLLLL",
         "L.LLLLLL.L", "L.LLLLL.LL"
     ]
     ca = day11.Automaton(day11.lines_to_grid(start), rules,
                          day11.visibility_neighbourhood)
     ca.run_to_stable()
     expect = day11.lines_to_grid([
         "#.L#.L#.L#", "#LLLLLL.LL", "L.L.L..#..", "##L#.#L.L#",
         "L.L#.LL.L#", "#.LLLL#.LL", "..#.L.....", "LLL###LLL#",
         "#.LLLLL#.L", "#.L#LL#.L#"
     ])
     self.assertEqual(expect, ca.grid())
     self.assertEqual(26, ca.count_occupied())
예제 #4
0
 def test_pentadecathlon(self):
     rules = day11.gol_rules()
     start = ["......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "..........#...........................", \
              ".........#.#..........................", \
              "........#...#.........................", \
              "........#...#.........................", \
              "........#...#.........................", \
              "........#...#.........................", \
              "........#...#.........................", \
              "........#...#.........................", \
              ".........#.#..........................", \
              "..........#...........................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................"]
     ca = day11.Automaton(day11.lines_to_grid(start), rules)
     ca.run(15)
     self.assertEqual(ca.grid(), day11.lines_to_grid(start))
예제 #5
0
 def test_gosper(self):
     rules = day11.gol_rules()
     start = ["......................................", \
              ".........................#............", \
              ".......................#.#............", \
              ".............##......##............##.", \
              "............#...#....##............##.", \
              ".##........#.....#...##...............", \
              ".##........#...#.##....#.#............", \
              "...........#.....#.......#............", \
              "............#...#.....................", \
              ".............##.......................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................"]
     expet = ["......................................", \
              "..........................#...........", \
              ".......................####...........", \
              "..............#.......####.........##.", \
              ".............#.#......#..#.........##.", \
              ".##.........#...##....####.....#......", \
              ".##.........#...##.....####....#......", \
              "............#...##........#...........", \
              ".............#.#......................", \
              "..............#.......................", \
              ".......................#.#............", \
              "........................##............", \
              "........................#.............", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "...............................#......", \
              "................................##....", \
              "...............................##.....", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................", \
              "......................................"]
     ca = day11.Automaton(day11.lines_to_grid(start), rules)
     ca.run(58)
     self.assertEqual(ca.grid(), day11.lines_to_grid(expet))