def test_text_init(self): "Test the Conway object creation from text" # 1. Create Conway object from text myobj = conway.Conway(text=aoc_18.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 6) self.assertEqual(len(myobj.grid), 15) self.assertEqual(myobj.size, 6) # 3. Check methods self.assertEqual(myobj.number_on(), 15) self.assertEqual(str(myobj), EXAMPLE_TEXT.strip()) self.assertEqual(myobj.neighbors((0, 0)), 1) self.assertEqual(myobj.neighbors((1, 1)), 2) self.assertEqual(myobj.neighbors((1, 4)), 6) myobj.grid = myobj.next_gen() self.assertEqual(str(myobj), STEP_ONE.strip()) myobj.grid = myobj.next_gen() self.assertEqual(str(myobj), STEP_TWO.strip()) myobj.grid = myobj.next_gen() myobj.grid = myobj.next_gen() self.assertEqual(myobj.number_on(), 4)
def test_part_two(self): "Test part two example of Conway object" # 1. Create Conway object from text myobj = conway.Conway(part2=True, text=aoc_18.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_part_one(self): "Test part one example of Conway object" # 1. Create Conway object from text myobj = conway.Conway(text=aoc_18.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
def test_text_init(self): "Test the Conway object creation from text" # 1. Create Conway object from text myobj = conway.Conway(text=aoc_11.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 10) self.assertEqual(myobj.rows, 10) self.assertEqual(myobj.cols, 10) self.assertEqual(myobj.rnds, 0) self.assertEqual(myobj.limit, 4) self.assertEqual(len(myobj.seats), 71) self.assertEqual(len(myobj.current), 0) self.assertEqual(myobj.previous, None) # 3. Test methods self.assertEqual(str(myobj), EXAMPLE_TEXT.strip()) myobj.fill_all_seats() self.assertEqual(myobj.rnds, 1) self.assertEqual(len(myobj.seats), 71) self.assertEqual(len(myobj.current), 71) self.assertEqual(myobj.count_occupied(), 71) self.assertEqual(myobj.unchanged(), False) self.assertEqual(str(myobj), ROUND_ONE) myobj.next_round() self.assertEqual(myobj.rnds, 2) self.assertEqual(len(myobj.seats), 71) self.assertEqual(len(myobj.current), 20) self.assertEqual(myobj.count_occupied(), 20) self.assertEqual(myobj.unchanged(), False) self.assertEqual(str(myobj), ROUND_TWO) myobj.next_round() self.assertEqual(myobj.rnds, 3) self.assertEqual(myobj.unchanged(), False) self.assertEqual(str(myobj), ROUND_THREE) myobj.next_round() self.assertEqual(myobj.rnds, 4) self.assertEqual(myobj.unchanged(), False) self.assertEqual(str(myobj), ROUND_FOUR) myobj.next_round() self.assertEqual(myobj.rnds, 5) self.assertEqual(myobj.unchanged(), False) self.assertEqual(str(myobj), ROUND_FIVE) self.assertEqual(myobj.count_occupied(), 37) myobj.next_round() self.assertEqual(myobj.rnds, 6) self.assertEqual(myobj.unchanged(), True) self.assertEqual(str(myobj), ROUND_FIVE) self.assertEqual(myobj.count_occupied(), 37)
def test_empty_init(self): "Test the default Conway creation" # 1. Create default Conway object myobj = conway.Conway() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(len(myobj.grid), 0) self.assertEqual(myobj.size, 0)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = conway.Conway(part2=True, text=input_lines) # 2. Determine the solution for part two solution = solver.part_two(verbose=args.verbose, limit=args.limit) if solution is None: print("There is no solution") else: print("The solution for part two is %s" % (solution)) # 3. Return result return solution is not None
def test_empty_init(self): "Test the default Conway creation" # 1. Create default Conway object myobj = conway.Conway() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.rows, 0) self.assertEqual(myobj.cols, 0) self.assertEqual(myobj.rnds, 0) self.assertEqual(myobj.limit, 4) self.assertEqual(len(myobj.seats), 0) self.assertEqual(len(myobj.current), 0) self.assertEqual(myobj.previous, None)
import conway x = conway.Conway(3, 3) x.currentField = [[True, True, False], [True, True, False], [False, False, False]]