예제 #1
0
 def test_examples_for_part_one(self):
     self.assertEqual(Solver(from_str='(())').solve_part_one(), 0)
     self.assertEqual(Solver(from_str='()()').solve_part_one(), 0)
     self.assertEqual(Solver(from_str='(((').solve_part_one(), 3)
     self.assertEqual(Solver(from_str='(()(()(').solve_part_one(), 3)
     self.assertEqual(Solver(from_str='))(((((').solve_part_one(), 3)
     self.assertEqual(Solver(from_str='())').solve_part_one(), -1)
     self.assertEqual(Solver(from_str='))(').solve_part_one(), -1)
     self.assertEqual(Solver(from_str=')))').solve_part_one(), -3)
     self.assertEqual(Solver(from_str=')())())').solve_part_one(), -3)
 def test_example_part1(self):
     example_input = """
     +1
     -2
     +3
     +1
     """
     one = Solver(from_str=example_input).solve_part_one()
     self.assertEqual(one, 3)
    def test_example_part2(self):
        example_input = """
        +1
        -2
        +3
        +1
        """
        two = Solver(from_str=example_input).solve_part_two()

        self.assertEqual(two, 2)
    def test_other_examples_part2(self):
        example_input = """
        +1
        -1
        """
        two = Solver(from_str=example_input).solve_part_two()
        self.assertEqual(two, 0)

        example_input = """
        +3
        +3
        +4
        -2
        -4
        """
        two = Solver(from_str=example_input).solve_part_two()
        self.assertEqual(two, 10)

        example_input = """
        -6
        +3
        +8
        +5
        -6
        """
        two = Solver(from_str=example_input).solve_part_two()
        self.assertEqual(two, 5)

        example_input = """
        +7
        +7
        -2
        -7
        -4
        """
        two = Solver(from_str=example_input).solve_part_two()
        self.assertEqual(two, 14)
    def test_other_examples_part1(self):
        example_input = """
        +1
        +1
        +1
        """
        one = Solver(from_str=example_input).solve_part_one()
        self.assertEqual(one, 3)

        example_input = """
        +1
        +1
        -2
        """
        one = Solver(from_str=example_input).solve_part_one()
        self.assertEqual(one, 0)

        example_input = """
        -1
        -2
        -3
        """
        one = Solver(from_str=example_input).solve_part_one()
        self.assertEqual(one, -6)
예제 #6
0
 def r2_l3_leaves_you_2_blocks_east_and_3_blocks_north(self):
     s = Solver(from_str="R2, L3")
     s.solve_part_one()
     self.assertEqual(s.pos[0], 2)
     self.assertEqual(s.pos[1], 3)
     self.assertEqual(s.dist() == 5)
예제 #7
0
 def test_solution(self):
     (one, two) = Solver(from_file="input/december01.input").solve()
     self.assertEqual(one, 332)
     self.assertEqual(two, 166)
예제 #8
0
 def r8_r4_r4_r8_the_first_location_you_visit_twice_is_4_blocks_away(self):
     s = Solver(from_str="R8, R4, R4, R8")
     s.solve_part_two()
     self.assertEqual(s.pos[0], 4)
     self.assertEqual(s.pos[1], 0)
     self.assertEqual(s.dist() == 4)
예제 #9
0
 def r5_l5_r5_r3_leaves_you_12_blocks_away(self):
     s = Solver(from_str="R5, L5, R5, R3")
     s.solve_part_one()
     self.assertEqual(s.dist() == 12)
예제 #10
0
 def r2_r2_r2_leaves_you_2_blocks_due_south_of_your_starting_position(self):
     s = Solver(from_str="R2, R2, R2")
     s.solve_part_one()
     self.assertEqual(s.pos[0], 0)
     self.assertEqual(s.pos[1], -2)
     self.assertEqual(s.dist() == 2)
예제 #11
0
 def test_solution(self):
     (floor, position) = Solver(from_file='input/dec01.in').solve()
     self.assertEqual(floor, 280)
     self.assertEqual(position, 1797)
예제 #12
0
 def test_throws_if_santa_never_enters_basement(self):
     with self.assertRaises(RuntimeError):
         Solver(from_str='(').solve_part_two()
예제 #13
0
 def test_examples_for_part_two(self):
     self.assertEqual(Solver(from_str=')').solve_part_two(), 1)
     self.assertEqual(Solver(from_str='()())').solve_part_two(), 5)