示例#1
0
    def test_get_alignment(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'us'
        x_location = 2
        y_location = 2

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        result = ship.get_alignment()
        print(result)

        # Assert
        self.assertEqual(align, result)
示例#2
0
    def test_change_alignment_them_to_us(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'them'
        x_location = 2
        y_location = 2

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        ship.change_alignment()
        print(ship._align)

        # Assert
        self.assertNotEqual(align, ship._align)
示例#3
0
    def test_change_alignment_us_to_them(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'us'
        x_location = 2
        y_location = 2

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        ship.change_alignment()
        print(ship._align)

        # Assert
        self.assertNotEqual(
            align, ship._align)  # wont be equal because alignment is changed
示例#4
0
    def test_get_alignment_incorrect_align_name(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'Use'
        x_location = 2
        y_location = 2

        # Act
        ship = Ship(name, type_, x_location, y_location, align)

        # Assert
        try:
            result = ship.get_alignment()
            print(result)
        except ValueError:
            print("Pass")
            self.assertTrue(True)
示例#5
0
    def test_init(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = Alignment.us
        x_location = 2
        y_location = 2

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        print(ship.status())

        # Assert
        self.assertEqual(name, ship._name)
        self.assertEqual(type_, ship._type)
        self.assertEqual(align, ship._align)
        self.assertEqual(x_location, ship._x_location)
        self.assertEqual(y_location, ship._y_location)
示例#6
0
    def test_status(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = Alignment.us
        x_location = 2
        y_location = 4

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        result = ship.status()
        print(result)

        # Assert
        self.assertEqual(
            str("Ship name: {},Ship type: {}, Current health: {},"
                " Location ({},{}) ").format(name, type_, 0, x_location,
                                             y_location), result)
    def test_attack_chaotic_alignment_in_range(self):
        # Arrange

        # Act
        ship = Battle('Nship', 'Battle', 3, 3, 'chaotic')
        target = Ship('BattleEnemy', 'Battle', 0, 7, 'them')
        ship._current_health = 90
        ship._max_health = 100
        ship._torpedoes = 9
        target._current_health = 50
        target._max_health = 100
        print(ship._torpedoes)
        print(target._current_health)
        ship.attack(target)
        print(ship._torpedoes)
        print(target._current_health)

        # Assert
        self.assertEqual(8, ship._torpedoes)
        self.assertEqual(30, target._current_health)
    def test_attack_diff_alignment_in_range_zero_torpedoes(self):
        # Arrange

        # Act
        ship = Battle('Nship', 'Battle', 3, 3, 'them')
        target = Ship('BattleEnemy', 'Battle', 0, 7, 'us')
        ship._current_health = 90
        ship._max_health = 100
        ship._torpedoes = 0
        target._current_health = 100
        target._max_health = 100
        print(ship._torpedoes)
        print(target._current_health)
        ship.attack(target)
        print(ship._torpedoes)
        print(target._current_health)

        # Assert
        self.assertEqual(0, ship._torpedoes)
        self.assertEqual(90, target._current_health)
    def test_attack_diff_alignment_out_of_range(self):
        # Arrange

        # Act
        ship = Battle('Nship', 'Battle', 30, 30, 'them')
        target = Ship('BattleEnemy', 'Battle', 0, 7, 'us')
        ship._current_health = 90
        ship._max_health = 100
        ship._torpedoes = 8
        target._current_health = 80
        target._max_health = 100
        print(ship._torpedoes)
        print(target._current_health)
        ship.attack(target)
        print(ship._torpedoes)
        print(target._current_health)

        # Assert
        self.assertEqual(8, ship._torpedoes)
        self.assertEqual(80, target._current_health)
示例#10
0
    def test_attack_chaotic_alignment_and_in_range(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'chaotic'
        x_location = 3
        y_location = 3

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        ship._range = 10
        ship._max_health = 100
        ship._current_health = 90
        ship._attack_power = 10
        target = Battle('BattleEnemy', 'Battle', 0, 7, 'them')
        target._current_health = 50
        ship.attack(target)
        print(target._current_health)
        print(ship._current_health)

        # Assert
        self.assertEqual(40, target._current_health)
示例#11
0
    def test_assess_damage_max_health_add_damage_in_case_of_repair_ship(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'them'
        x_location = 2
        y_location = 2
        amount_of_damage = 10

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        ship._current_health = 100
        ship._max_health = 100

        ship.assess_damage(amount_of_damage)

        # Assert
        self.assertEqual(100, ship._current_health)
示例#12
0
    def test_assess_damage_current_health_zero_ship_destroyed(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'them'
        x_location = 2
        y_location = 2
        amount_of_damage = -10

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        ship._current_health = 0
        ship._max_health = 100

        ship.assess_damage(amount_of_damage)

        # Assert
        self.assertEqual(0, ship._current_health)
示例#13
0
    def test_move_current_health_is_less(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'us'
        x_location = 2
        y_location = 2

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        ship._max_health = 100
        ship._current_health = 90
        ship.move()
        print(ship._current_health)

        # Assert
        self.assertNotEqual(90,
                            ship._current_health)  # 90 and 91 won't be equal
示例#14
0
    def test__get_distance_from_target(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'them'
        x_location = 3
        y_location = 3

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        ship._range = 10
        ship._max_health = 100
        ship._attack_power = 10
        target = Cruiser('Cruise1', 'Cruiser', 0, 7, 'us')
        result = ship._get_distance_from_target(target)
        print(result)

        # Assert
        self.assertEqual(5, result)
示例#15
0
    def test_move_current_health_is_max(self):
        # Arrange
        name = 'NShip'
        type_ = 'Battle'
        align = 'us'
        x_location = 2
        y_location = 2

        # Act
        ship = Ship(name, type_, x_location, y_location, align)
        ship._max_health = 100
        ship._current_health = 100
        ship.move()
        print(ship._current_health)

        # Assert
        self.assertEqual(
            100,
            ship._current_health)  # current health = max health - so equal