Exemple #1
0
 def test_mask(self):
     starting_world = {'mask': None}
     mask_instruction = Instruction('mask', "XXX01X1")
     self.assertEqual(
         fourteen.main.DockingInstructionSet().mask(mask_instruction,
                                                    starting_world),
         {'mask': 'XXX01X1'})
Exemple #2
0
    def test_mem(self):
        starting_world = {'memory': {}, 'mask': "1XXXX0X".rjust(36, "X")}
        mem_instruction = Instruction('mem', (8, 11))

        new_world = fourteen.main.DockingInstructionSet().mem(
            mem_instruction, starting_world)

        self.assertEqual(new_world['memory'][8], 73)
Exemple #3
0
 def mem_instruction(result):
     return Instruction("mem", (int(result.address), int(result.operand)))
Exemple #4
0
 def mask_instruction(result):
     return Instruction("mask", result.operand)
Exemple #5
0
def ferry_parser(filename):
    lines = None
    with open(filename) as f:
        lines = f.read().splitlines()

    return [ Instruction(i[0], int(i[1:])) for i in lines ]
Exemple #6
0
    def test_test_right(self):
        starting_world = {'ship_position': (0,0), 'position': (10,4)}
        right_instruction = Instruction('R', 90)
        expected_world = twelve.main.FerryInstructions2().right(right_instruction, starting_world)

        self.assertEqual(expected_world, {'ship_position': (0,0), 'position': (4,-10)} ) 
Exemple #7
0
 def test_north(self):
     starting_world = { 'position': (0,0) }
     north_instruction = Instruction('N', 20)
     expected_world = twelve.main.FerryInstructions().north(north_instruction, starting_world)
     self.assertEqual(expected_world, {'position': (0, 20)}) 
Exemple #8
0
 def test_forward_direction_270(self):
     starting_world = { 'position': (0,0), 'direction': 270}
     forward_instruction = Instruction('F', 20)
     expected_world = twelve.main.FerryInstructions().forward(forward_instruction, starting_world)
     self.assertEqual(expected_world, {'position': (-20, 0), 'direction': 270}) 
Exemple #9
0
 def test_right_greater_than_360(self):
     starting_world = { 'direction': 180 }
     right_instruction = Instruction('R', 270 )
     expected_world = twelve.main.FerryInstructions().right(right_instruction, starting_world)
     self.assertEqual(expected_world, {'direction': 90}) 
Exemple #10
0
 def test_right_less_than_0(self):
     starting_world = { 'direction': 0 }
     right_instruction = Instruction('L', 90)
     expected_world = twelve.main.FerryInstructions().left(right_instruction, starting_world)
     self.assertEqual(expected_world, {'direction': 270}) 
Exemple #11
0
 def test_left(self):
     starting_world = { 'direction': 0 }
     left_instruction = Instruction('L', 90)
     expected_world = twelve.main.FerryInstructions().left(left_instruction, starting_world)
     self.assertEqual(expected_world, {'direction': -90}) 
Exemple #12
0
 def test_west(self):
     starting_world = { 'position': (0,0) }
     west_instruction = Instruction('W', 20)
     expected_world = twelve.main.FerryInstructions().west(west_instruction, starting_world)
     self.assertEqual(expected_world, {'position': (-20, 0)}) 
Exemple #13
0
    def test_forward(self):
        starting_world = {'ship_position': (0,0), 'position': (10,4)}
        forward_instruction = Instruction('F', 3)
        expected_world = twelve.main.FerryInstructions2().forward(forward_instruction, starting_world)

        self.assertEqual(expected_world, {'ship_position': (30,12), 'position': (10,4)} ) 
Exemple #14
0
    def test_left_360(self):
        starting_world = {'ship_position': (0,0), 'position': (10,4)}
        left_instruction = Instruction('L', 360)
        expected_world = twelve.main.FerryInstructions2().left(left_instruction, starting_world)

        self.assertEqual(expected_world, {'ship_position': (0,0), 'position': (10,4)} ) 
Exemple #15
0
 def test_south(self):
     starting_world = { 'position': (0,0) }
     south_instruction = Instruction('S', 20)
     expected_world = twelve.main.FerryInstructions().south(south_instruction, starting_world)
     self.assertEqual(expected_world, {'position': (0, -20)})