Example #1
0
 def test_default_substitution_battalion(self):
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(horses=horses,
                             elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     actual = bp.get_substitution_battalion(BattalionType.HORSES)
     expected: List[BattalionType] = []
     assert actual == expected
Example #2
0
def main():
    battalion_processor = BattalionProcessor(2,
                                             horses=1,
                                             elephants=2,
                                             armoured_tanks=3,
                                             sling_guns=4)
    battalion_processor.add_battalion_substituation(BattalionType.ELEPHANTS,
                                                    BattalionType.HORSES, 2)
    battalion_processor.add_battalion_substituation(
        BattalionType.ARMOUREDTANKS, BattalionType.ELEPHANTS, 2)
    battalion_processor.add_battalion_substituation(
        BattalionType.SLINGGUNS, BattalionType.ARMOUREDTANKS, 2)
    lengaburu_army = Army(horses=100,
                          elephants=50,
                          armoured_tanks=10,
                          sling_guns=5)

    with open("input.txt", "r") as testcases:
        for testcase in testcases:
            input = [int(x.strip()) for x in testcase.split(",")]
            enemy_army = Army(horses=input[0],
                              elephants=input[1],
                              armoured_tanks=input[2],
                              sling_guns=input[3])
            planner = BattlePlanner(battalion_processor,
                                    deepcopy(lengaburu_army))
            result, army = planner.get_winning_army(enemy_army)
            display_result(input, result, army)
Example #3
0
    def test_get_winning_army_3(self):
        horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
        our_army = Army(horses=horses, elephants=elephants,
                    armoured_tanks=armoured_tanks, sling_guns=sling_guns)
        enemy_army = Army(horses=600, elephants=100)
        horses_order, elephants_order, armoured_tanks_order, sling_guns_order = 1, 2, 3, 4
        bp = BattalionProcessor(4, horses=horses_order, elephants=elephants_order,
                                armoured_tanks=armoured_tanks_order,
                                sling_guns=sling_guns_order)
        bp.add_battalion_substituation(BattalionType.ELEPHANTS, BattalionType.HORSES, 1)                        

        battle_result, winning_army = BattlePlanner(bp, deepcopy(our_army)).get_winning_army(deepcopy(enemy_army))
        assert battle_result == False
        assert winning_army == {BattalionType.HORSES: 100,
                                BattalionType.ELEPHANTS: 50}
Example #4
0
 def test_custom_substitution_battalion(self):
     bp = BattalionProcessor()
     bp.add_battalion_substituation(BattalionType.HORSES,
                                    BattalionType.ARMOUREDTANKS, 2)
     bp.add_battalion_substituation(BattalionType.HORSES,
                                    BattalionType.ELEPHANTS, 4)
     assert set(bp.get_substitution_battalion(BattalionType.HORSES)) == set(
         [(BattalionType.ELEPHANTS, 4), (BattalionType.ARMOUREDTANKS, 2)])
     assert set(bp.get_substitution_battalion(
         BattalionType.ARMOUREDTANKS)) == set([(BattalionType.HORSES, 0.5)])
     assert set(bp.get_substitution_battalion(
         BattalionType.ELEPHANTS)) == set([(BattalionType.HORSES, 0.25)])
Example #5
0
 def test_resolve_battalion_1(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     our_army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(1, horses=horses, elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     bp.add_battalion_substituation(BattalionType.ELEPHANTS, BattalionType.HORSES, 2)                                
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 199) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 200) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 201) == False
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 150) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 100) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 5) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.HORSES, 250) == False
Example #6
0
 def test_resolve_with_similar_battalion(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(horses=horses, elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     planner = BattlePlanner(bp, army)
     assert planner.resolve_with_similar_battalion(BattalionType.HORSES, 50) == 0
     assert planner.resolve_with_similar_battalion(BattalionType.ELEPHANTS, 80) == 30
     assert planner.resolve_with_similar_battalion(BattalionType.ARMOUREDTANKS, 20) == 10
Example #7
0
 def test_resolve_battalion_4(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     our_army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(3, horses=horses, elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 29) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 30) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 31) == False
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 104) == False
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 105) == False
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 106) == False        
Example #8
0
 def test_get_default_battalion_seniority(self):
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(horses=horses,
                             elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     assert bp.get_battalion_seniority(BattalionType.HORSES) == 1
     assert bp.get_battalion_seniority(BattalionType.ELEPHANTS) == 2
     assert bp.get_battalion_seniority(BattalionType.ARMOUREDTANKS) == 3
     assert bp.get_battalion_seniority(BattalionType.SLINGGUNS) == 4
Example #9
0
 def test_get_winning_army_1(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     our_army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     enemy_army = Army(horses=200, elephants=100,
                 armoured_tanks=20, sling_guns=10)
     horses_order, elephants_order, armoured_tanks_order, sling_guns_order = 1, 2, 3, 4
     bp = BattalionProcessor(2, horses=horses_order, elephants=elephants_order,
                             armoured_tanks=armoured_tanks_order,
                             sling_guns=sling_guns_order)
                             
     battle_result, winning_army = BattlePlanner(bp, deepcopy(our_army)).get_winning_army(deepcopy(enemy_army))
     assert battle_result == True
     assert winning_army == {BattalionType.HORSES: 100,
                             BattalionType.ELEPHANTS: 50,
                             BattalionType.ARMOUREDTANKS: 10,
                             BattalionType.SLINGGUNS: 5}
Example #10
0
 def test_get_custom_battalion_seniority(self):
     armoured_tanks, sling_guns, elephants, horses = 4, 3, 2, 1
     bp = BattalionProcessor(horses=horses,
                             elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     assert bp.get_battalion_seniority(BattalionType.HORSES) == horses
     assert bp.get_battalion_seniority(BattalionType.ELEPHANTS) == elephants
     assert bp.get_battalion_seniority(
         BattalionType.ARMOUREDTANKS) == armoured_tanks
     assert bp.get_battalion_seniority(
         BattalionType.SLINGGUNS) == sling_guns
Example #11
0
 def test_add_substitution_battalion(self):
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(horses=horses,
                             elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     bp.add_battalion_substituation(BattalionType.HORSES,
                                    BattalionType.ELEPHANTS, 4)
     assert bp.get_substitution_battalion(BattalionType.HORSES) == [
         (BattalionType.ELEPHANTS, 4)
     ]
     assert bp.get_substitution_battalion(BattalionType.ELEPHANTS) == [
         (BattalionType.HORSES, 0.25)
     ]
Example #12
0
 def test_resolve_battalion_3(self):
     horses, elephants, armoured_tanks, sling_guns = 100, 50, 10, 5
     our_army = Army(horses=horses, elephants=elephants,
                 armoured_tanks=armoured_tanks, sling_guns=sling_guns)
     horses, elephants, armoured_tanks, sling_guns = 1, 2, 3, 4
     bp = BattalionProcessor(3, horses=horses, elephants=elephants,
                             armoured_tanks=armoured_tanks,
                             sling_guns=sling_guns)
     bp.add_battalion_substituation(BattalionType.ELEPHANTS, BattalionType.HORSES, 2)                                
     bp.add_battalion_substituation(BattalionType.ARMOUREDTANKS, BattalionType.HORSES, 4)
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 30) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 104) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 105) == True
     assert BattlePlanner(bp, deepcopy(our_army)).resolve_battalion(BattalionType.ARMOUREDTANKS, 106) == False
Example #13
0
 def test_apply_power_rule(self):
     bp = BattlePlanner(BattalionProcessor(), Army())
     assert bp.apply_power_rule(7) == 4
     assert bp.apply_power_rule(5) == 3