class TestUpgradeTires( unittest.TestCase ): # Your test class is a subclass of unittest.Testcase, this is important def setUp( self ): # This method is used to set up anything you wish to test prior to every test method below. self.myPlayer = Player(12, "Sean") self.myPlayer.truck.money = 10000 self.actionCont = ActionController() def test_upgrade_sticky(self): self.myPlayer.truck.tires = TireType.tire_normal self.myPlayer.truck.money = 10000 expectedCash = 10000 - stats.GameStats.tire_switch_cost self.actionCont.upgrade_level(self.myPlayer, ObjectType.tires, TireType.tire_sticky) self.assertEqual(self.myPlayer.truck.tires, TireType.tire_sticky) self.assertEqual(expectedCash, self.myPlayer.truck.money) def test_upgrade_econ(self): self.myPlayer.truck.tires = TireType.tire_normal self.myPlayer.truck.money = 10000 expectedCash = 10000 - stats.GameStats.tire_switch_cost self.actionCont.upgrade_level(self.myPlayer, ObjectType.tires, TireType.tire_econ) self.assertEqual(self.myPlayer.truck.tires, TireType.tire_econ) def test_upgrade_normal(self): self.myPlayer.truck.tires = TireType.tire_sticky self.myPlayer.truck.money = 10000 expectedCash = 10000 - stats.GameStats.tire_switch_cost self.actionCont.upgrade_level(self.myPlayer, ObjectType.tires, TireType.tire_normal) self.assertEqual(self.myPlayer.truck.tires, TireType.tire_normal) def test_same_type(self): self.myPlayer.truck.money = 10000 expectedCash = 10000 self.myPlayer.truck.tires = TireType.tire_normal self.actionCont.upgrade_level(self.myPlayer, ObjectType.tires, TireType.tire_normal) self.assertEqual(self.myPlayer.truck.tires, TireType.tire_normal) self.assertEqual(self.myPlayer.truck.money, expectedCash) def test_upgrade_beyond_allowable(self): self.myPlayer.truck.tires = TireType.tire_normal self.myPlayer.truck.money = 10000 self.actionCont.upgrade_level(self.myPlayer, ObjectType.tires, 10) self.assertEqual(self.myPlayer.truck.tires, TireType.tire_normal) self.assertEqual(self.myPlayer.truck.money, 10000) def test_no_money(self): self.myPlayer.truck.tires = TireType.tire_normal self.myPlayer.truck.money = 10 self.actionCont.upgrade_level(self.myPlayer, ObjectType.tires, TireType.tire_sticky) self.assertEqual(self.myPlayer.truck.tires, TireType.tire_normal) self.assertEqual(self.myPlayer.truck.money, 10)
class TestUpgradeRabbitFoot(unittest.TestCase): # This method is used to set up anything you wish to test prior to every test method below. def setUp(self): self.myPlayer = Player(12, "Sean") self.myPlayer.truck.money = 10000 self.actionCont = ActionController() # Test methods should always start with the word 'test' def test_upgrade_one_level(self): self.myPlayer.truck.addons.level = 0 self.myPlayer.truck.money = 10000 expectedCash = 10000 - stats.GameStats.costs_and_effectiveness[ObjectType.rabbitFoot]['cost'][1] self.actionCont.upgrade_level(self.myPlayer, ObjectType.rabbitFoot) self.assertEqual(self.myPlayer.truck.addons.level,RabbitFootLevel.level_one) self.assertEqual(expectedCash, self.myPlayer.truck.money) self.assertTrue(isinstance(self.myPlayer.truck.addons, RabbitFoot)) def test_upgrade_two_level(self): self.myPlayer.truck.addons.level = 0 self.myPlayer.truck.money = 10000 expectedCash = 10000 - stats.GameStats.costs_and_effectiveness[ObjectType.rabbitFoot]['cost'][1] - stats.GameStats.costs_and_effectiveness[ObjectType.rabbitFoot]['cost'][2] self.actionCont.upgrade_level(self.myPlayer, ObjectType.rabbitFoot) self.actionCont.upgrade_level(self.myPlayer, ObjectType.rabbitFoot) self.assertEqual(self.myPlayer.truck.addons.level, RabbitFootLevel.level_two) self.assertEqual(expectedCash, self.myPlayer.truck.money) self.assertTrue(isinstance(self.myPlayer.truck.addons, RabbitFoot)) def test_upgrade_beyond_allowable(self): self.myPlayer.truck.addons.level = 0 self.myPlayer.truck.money = 100000 expectedCash = self.myPlayer.truck.money - helpers.addTogetherDictValues(stats.GameStats.costs_and_effectiveness[ObjectType.rabbitFoot]['cost']) self.actionCont.upgrade_level(self.myPlayer, ObjectType.rabbitFoot) self.actionCont.upgrade_level(self.myPlayer, ObjectType.rabbitFoot) self.actionCont.upgrade_level(self.myPlayer, ObjectType.rabbitFoot) self.actionCont.upgrade_level(self.myPlayer, ObjectType.rabbitFoot) self.actionCont.upgrade_level(self.myPlayer, ObjectType.rabbitFoot) self.assertEqual(self.myPlayer.truck.addons.level, RabbitFootLevel.level_three) self.assertEqual(self.myPlayer.truck.money, expectedCash) self.assertTrue(isinstance(self.myPlayer.truck.addons, RabbitFoot)) def test_no_money(self): self.myPlayer.truck.addons.level = 0 self.myPlayer.truck.money = 1 self.actionCont.upgrade_level(self.myPlayer, ObjectType.rabbitFoot) self.assertEqual(self.myPlayer.truck.addons.level, RabbitFootLevel.level_zero) self.assertEqual(self.myPlayer.truck.money, 1)
class TestUpgradeTank(unittest.TestCase): # This method is used to set up anything you wish to test prior to every test method below. def setUp(self): self.myPlayer = Player(12, "Sean") self.myPlayer.truck.money = 10000 self.actionCont = ActionController() # Test methods should always start with the word 'test' def test_upgrade_one_level(self): self.myPlayer.truck.body.level = 0 self.myPlayer.truck.money = 10000 expectedCash = 10000 - stats.GameStats.costs_and_effectiveness[ ObjectType.tank]['cost'][1] self.actionCont.upgrade_level(self.myPlayer, ObjectType.tank) self.assertEqual(self.myPlayer.truck.body.level, TankLevel.level_one) self.assertEqual(expectedCash, self.myPlayer.truck.money) self.assertTrue(isinstance(self.myPlayer.truck.body, Tank)) def test_upgrade_two_level(self): self.myPlayer.truck.body.level = 0 expectedCash = 10000 - stats.GameStats.costs_and_effectiveness[ ObjectType. tank]['cost'][1] - stats.GameStats.costs_and_effectiveness[ ObjectType.tank]['cost'][2] self.actionCont.upgrade_level(self.myPlayer, ObjectType.tank) self.actionCont.upgrade_level(self.myPlayer, ObjectType.tank) self.assertEqual(self.myPlayer.truck.body.level, TankLevel.level_two) self.assertEqual(expectedCash, self.myPlayer.truck.money) self.assertTrue(isinstance(self.myPlayer.truck.body, Tank)) def test_upgrade_beyond_allowable(self): self.myPlayer.truck.body = PoliceScanner() self.myPlayer.truck.body.level = 0 self.myPlayer.truck.money = 100000 expectedCash = self.myPlayer.truck.money - \ helpers.addTogetherDictValues( stats.GameStats.costs_and_effectiveness[ObjectType.tank]['cost']) self.actionCont.upgrade_level(self.myPlayer, ObjectType.tank) self.actionCont.upgrade_level(self.myPlayer, ObjectType.tank) self.actionCont.upgrade_level(self.myPlayer, ObjectType.tank) self.actionCont.upgrade_level(self.myPlayer, ObjectType.tank) self.actionCont.upgrade_level(self.myPlayer, ObjectType.tank) self.assertEqual(self.myPlayer.truck.body.level, TankLevel.level_three) self.assertEqual(self.myPlayer.truck.money, expectedCash) self.assertTrue(isinstance(self.myPlayer.truck.body, Tank)) def test_no_money(self): self.myPlayer.truck.body.level = 0 self.myPlayer.truck.money = 1 self.actionCont.upgrade_level(self.myPlayer, ObjectType.tank) self.assertEqual(self.myPlayer.truck.body.level, TankLevel.level_zero) self.assertEqual(self.myPlayer.truck.money, 1) def test_not_tank(self): self.myPlayer.truck.body = HeadLights() self.myPlayer.truck.money = 1 self.assertEqual( self.myPlayer.truck.body.current_gas, stats.GameStats.costs_and_effectiveness[ObjectType.tank] ['effectiveness'][0] * stats.GameStats.truck_starting_gas) self.assertEqual( self.myPlayer.truck.body.max_gas, stats.GameStats.costs_and_effectiveness[ObjectType.tank] ['effectiveness'][0] * stats.GameStats.truck_starting_gas) self.assertEqual(self.myPlayer.truck.money, 1) def test_not_tank_upgrade(self): self.myPlayer.truck.body = HeadLights() self.myPlayer.truck.money = 10000 expectedCash = 10000 - stats.GameStats.costs_and_effectiveness[ ObjectType.headlights]['cost'][1] self.actionCont.upgrade_level(self.myPlayer, ObjectType.headlights) self.assertEqual(self.myPlayer.truck.body.level, HeadlightLevel.level_one) self.assertEqual( self.myPlayer.truck.body.current_gas, stats.GameStats.costs_and_effectiveness[ObjectType.tank] ['effectiveness'][0] * stats.GameStats.truck_starting_gas) self.assertEqual( self.myPlayer.truck.body.max_gas, stats.GameStats.costs_and_effectiveness[ObjectType.tank] ['effectiveness'][0] * stats.GameStats.truck_starting_gas) self.assertEqual(self.myPlayer.truck.money, expectedCash)