Let's see how unittest
can help us test the Tank class. Enter the following code into a text file in the same directory as the combatsim package:
import combatsim import combatsim.exceptions as ex import unittest class TestTank(unittest.TestCase): """Tests for the combatsim package.""" def setUp(self): """Called before EACH test is run.""" # Define parameters for the tank armor_values = {'front' : 100, 'side' : 50, 'rear' : 25, 'turret' : 75} main_gun_damage = 50 initial_position = (0.0, 0.0) # Create a tank object self.tank = combatsim.tank.Tank(armor_values, main_gun_damage, initial_position) def test_get_position(self): """Test method get_position""" position = self.tank.get_position() self.assertEqual(position, (0.0, 0.0)) def test_move(self): """Test method move""" self.tank.move(0, 1) ...