Exemplo n.º 1
0
 def test_cannot_pickup_item_on_different_floor(self):
   with self.assertRaises(ElevatorPickupError):
     start = SimulatorState(0)
     start.add_item_to_floor('HG', 2)
     start.add_item_to_floor('HM', 1)
     rad_sim = RadiationContainmentSimulator(start)
     rad_sim.elevator_up(['HM'])
Exemplo n.º 2
0
 def test_move_elevator_with_two_items(self):
   start = SimulatorState(0)
   start.add_item_to_floor('HG', 2)
   start.add_item_to_floor('HM', 0)
   start.add_item_to_floor('NG', 2)
   start.add_item_to_floor('NM', 0)
   expected_floor_map = [
     {
       'generator': {
         'floor': 2,
         'name': 'HG'
       },
       'microchip': {
         'floor': 1,
         'name': 'HM'
       }
     },
     {
       'generator': {
         'floor': 2,
         'name': 'NG'
       },
       'microchip': {
         'floor': 1,
         'name': 'NM'
       }
     }
   ]
   rad_sim = RadiationContainmentSimulator(start)
   rad_sim.elevator_up(['NM', 'HM'])
   self.assert_simulator_state(rad_sim.get_simulator_state(), 1, expected_floor_map)
Exemplo n.º 3
0
 def test_cannot_move_elevator_into_basement(self):
   with self.assertRaises(ElevatorMoveError):
     start = SimulatorState(0)
     start.add_item_to_floor('CaG', 0)
     start.add_item_to_floor('CaM', 0)
     rad_sim = RadiationContainmentSimulator(start)
     rad_sim.elevator_down(['CaM'])
Exemplo n.º 4
0
 def test_cannot_move_elevator_outside_building(self):
   with self.assertRaises(ElevatorMoveError):
     start = SimulatorState(3)
     start.add_item_to_floor('CoG', 0)
     start.add_item_to_floor('CoM', 0)
     rad_sim = RadiationContainmentSimulator(start)
     rad_sim.elevator_up(['CoM'])
Exemplo n.º 5
0
 def test_check_fried_chips_after_all_cargo_moved():
   start = SimulatorState(2)
   start.add_item_to_floor('HG', 2)
   start.add_item_to_floor('HM', 2)
   start.add_item_to_floor('LiG', 2)
   start.add_item_to_floor('LiM', 3)
   rad_sim = RadiationContainmentSimulator(start)
   rad_sim.elevator_up(['HG', 'LiG'])
 def test_three_items(self):
     state = SimulatorState(0)
     state.add_item_to_floor('Z', 0)
     state.add_item_to_floor('Y', 0)
     state.add_item_to_floor('X', 0)
     cargo_list = CargoCalculator.calculate_cargos(state)
     self.assertEqual(
         cargo_list,
         [['Z'], ['Y'], ['X'], ['Z', 'Y'], ['Z', 'X'], ['Y', 'X']])
Exemplo n.º 7
0
 def test_cannot_exceed_two_items_in_elevator(self):
   with self.assertRaises(ElevatorCapacityError):
     start = SimulatorState(0)
     start.add_item_to_floor('HG', 0)
     start.add_item_to_floor('HM', 0)
     start.add_item_to_floor('XeG', 0)
     start.add_item_to_floor('XeM', 0)
     rad_sim = RadiationContainmentSimulator(start)
     rad_sim.elevator_up(['HM', 'HG', 'XeM'])
Exemplo n.º 8
0
 def test_chip_fried_when_exposed_to_other_generator(self):
   with self.assertRaises(FriedChipError):
     start = SimulatorState(0)
     start.add_item_to_floor('HG', 0)
     start.add_item_to_floor('HM', 0)
     start.add_item_to_floor('XeG', 1)
     start.add_item_to_floor('XeM', 0)
     rad_sim = RadiationContainmentSimulator(start)
     rad_sim.elevator_up(['HM'])
Exemplo n.º 9
0
    def test_not_equals_elevator(self):
        state1 = SimulatorState(1)
        state1.add_item_to_floor('AM', 2)
        state1.add_item_to_floor('AG', 1)

        state2 = SimulatorState(2)
        state2.add_item_to_floor('AM', 2)
        state2.add_item_to_floor('AG', 1)

        self.assertFalse(state1 == state2)
    def test_puzzle_one(self):
        assembler = MicrochipAssembler()
        start = SimulatorState(0)
        start.add_item_to_floor('SrG', 0)
        start.add_item_to_floor('SrM', 0)
        start.add_item_to_floor('PuG', 0)
        start.add_item_to_floor('PuM', 0)
        start.add_item_to_floor('TmG', 1)
        start.add_item_to_floor('RuG', 1)
        start.add_item_to_floor('RuM', 1)
        start.add_item_to_floor('CmG', 1)
        start.add_item_to_floor('CmM', 1)
        start.add_item_to_floor('TmM', 2)

        self.assertEqual(37, assembler.solve(start))
 def test_acceptance(self):
     assembler = MicrochipAssembler()
     start = SimulatorState(0)
     start.add_item_to_floor('HM', 0)
     start.add_item_to_floor('LiM', 0)
     start.add_item_to_floor('HG', 1)
     start.add_item_to_floor('LiG', 2)
     self.assertEqual(11, assembler.solve(start))
Exemplo n.º 12
0
 def test_acceptance(self):
     state = SimulatorState(1)
     state.add_item_to_floor('TmG', 1)
     state.add_item_to_floor('RuG', 1)
     state.add_item_to_floor('RuM', 1)
     state.add_item_to_floor('CmG', 1)
     state.add_item_to_floor('CmM', 1)
     cargo_list = CargoCalculator.calculate_cargos(state)
     self.assertEqual(cargo_list, [
         ['TmG'],
         ['RuG'],
         ['RuM'],
         ['CmG'],
         ['CmM'],
         ['TmG', 'RuG'],
         ['TmG', 'RuM'],
         ['TmG', 'CmG'],
         ['TmG', 'CmM'],
         ['RuG', 'RuM'],
         ['RuG', 'CmG'],
         ['RuG', 'CmM'],
         ['RuM', 'CmG'],
         ['RuM', 'CmM'],
         ['CmG', 'CmM'],
     ])
Exemplo n.º 13
0
    def test_equivalent_states(self):
        state1 = SimulatorState(2)
        state1.add_item_to_floor('HM', 0)
        state1.add_item_to_floor('HG', 1)
        state1.add_item_to_floor('LiG', 1)
        state1.add_item_to_floor('LiM', 2)

        state2 = SimulatorState(2)
        state2.add_item_to_floor('LiG', 1)
        state2.add_item_to_floor('LiM', 0)
        state2.add_item_to_floor('HG', 1)
        state2.add_item_to_floor('HM', 2)

        self.assertTrue(SimulatorState.equivalent_states(state1, state2))
Exemplo n.º 14
0
    def test_hash_does_not_match(self):
        state1 = SimulatorState(2)
        state1.add_item_to_floor('AM', 2)
        state1.add_item_to_floor('BM', 2)
        state1.add_item_to_floor('AG', 1)
        state1.add_item_to_floor('BG', 1)

        state2 = SimulatorState(3)
        state2.add_item_to_floor('BM', 2)
        state2.add_item_to_floor('AM', 2)
        state2.add_item_to_floor('BG', 1)
        state2.add_item_to_floor('AG', 1)

        self.assertFalse(state1.__hash__() == state2.__hash__())
Exemplo n.º 15
0
    def test_hash_matches(self):
        state1 = SimulatorState(2)
        state1.add_item_to_floor('AM', 2)
        state1.add_item_to_floor('BM', 2)
        state1.add_item_to_floor('AG', 1)
        state1.add_item_to_floor('BG', 1)

        state2 = SimulatorState(2)
        state2.add_item_to_floor('BM', 2)
        state2.add_item_to_floor('AM', 2)
        state2.add_item_to_floor('BG', 1)
        state2.add_item_to_floor('AG', 1)

        self.assertTrue(state1.__hash__() == state2.__hash__())
Exemplo n.º 16
0
    def test_equals(self):
        state1 = SimulatorState(2)
        state1.add_item_to_floor('AM', 2)
        state1.add_item_to_floor('BM', 2)
        state1.add_item_to_floor('AG', 1)
        state1.add_item_to_floor('BG', 1)

        state2 = SimulatorState(2)
        state2.add_item_to_floor('BM', 2)
        state2.add_item_to_floor('AM', 2)
        state2.add_item_to_floor('BG', 1)
        state2.add_item_to_floor('AG', 1)

        self.assertTrue(state1 == state2)
Exemplo n.º 17
0
 def test_simulation_not_complete(self):
     state = SimulatorState(2)
     state.add_item_to_floor('CG', 2)
     state.add_item_to_floor('AG', 3)
     state.add_item_to_floor('BG', 3)
     state.add_item_to_floor('AM', 3)
     state.add_item_to_floor('BM', 3)
     state.add_item_to_floor('CM', 3)
     self.assertFalse(state.is_complete())
 def test_backtrack_to_complete_simulation(self):
     assembler = MicrochipAssembler()
     start = SimulatorState(2)
     start.add_item_to_floor('AM', 2)
     start.add_item_to_floor('BM', 2)
     start.add_item_to_floor('CM', 2)
     start.add_item_to_floor('AG', 3)
     start.add_item_to_floor('BG', 3)
     start.add_item_to_floor('CG', 3)
     self.assertEqual(3, assembler.solve(start))
Exemplo n.º 19
0
 def test_items_on_multiple_floors(self):
     state = SimulatorState(0)
     state.add_item_to_floor('Z', 0)
     state.add_item_to_floor('Y', 0)
     state.add_item_to_floor('X', 0)
     state.add_item_to_floor('A', 1)
     state.add_item_to_floor('B', 2)
     state.add_item_to_floor('C', 3)
     cargo_list = CargoCalculator.calculate_cargos(state)
     self.assertEqual(
         cargo_list,
         [['Z'], ['Y'], ['X'], ['Z', 'Y'], ['Z', 'X'], ['Y', 'X']])
 def test_two_moves_to_completion(self):
     assembler = MicrochipAssembler()
     start = SimulatorState(1)
     start.add_item_to_floor('CoG', 1)
     start.add_item_to_floor('CoM', 3)
     self.assertEqual(2, assembler.solve(start))
Exemplo n.º 21
0
 def test_one_item(self):
     state = SimulatorState(0)
     state.add_item_to_floor('Z', 0)
     cargo_list = CargoCalculator.calculate_cargos(state)
     self.assertEqual(cargo_list, [['Z']])
Exemplo n.º 22
0
 def test_simulation_complete(self):
     state = SimulatorState(0)
     state.add_item_to_floor('LiG', 3)
     state.add_item_to_floor('LiM', 3)
     self.assertTrue(state.is_complete())
Exemplo n.º 23
0
    def test_different_states(self):
        state1 = SimulatorState(3)
        state1.add_item_to_floor('CM', 2)
        state1.add_item_to_floor('AG', 3)
        state1.add_item_to_floor('BG', 3)
        state1.add_item_to_floor('CG', 3)
        state1.add_item_to_floor('AM', 3)
        state1.add_item_to_floor('BM', 3)

        state2 = SimulatorState(3)
        state2.add_item_to_floor('BM', 2)
        state2.add_item_to_floor('CM', 2)
        state2.add_item_to_floor('AG', 3)
        state2.add_item_to_floor('BG', 3)
        state2.add_item_to_floor('CG', 3)
        state2.add_item_to_floor('AM', 3)

        self.assertFalse(SimulatorState.equivalent_states(state1, state2))
 def test_one_move_to_completion(self):
     assembler = MicrochipAssembler()
     start = SimulatorState(2)
     start.add_item_to_floor('HG', 2)
     start.add_item_to_floor('HM', 3)
     self.assertEqual(1, assembler.solve(start))