Skip to content

Commit

Permalink
Update v2.12.1
Browse files Browse the repository at this point in the history
Added test cases
  • Loading branch information
sakan811 committed Sep 16, 2024
1 parent 7288ce2 commit b463d47
Showing 3 changed files with 120 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_character/test_calculate_damage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest
from hsr_simulation.character import Character


@pytest.fixture
def character():
return Character()


def test_dmg_reduction_when_enemy_not_broken(character):
# Set up the character with enemy not broken
character.enemy_weakness_broken = False
initial_toughness = character.current_enemy_toughness

# Call the method
dmg = character._calculate_damage(skill_multiplier=1, break_amount=10, can_crit=False)

# Assert the damage is reduced
assert dmg < character.atk
assert character.current_enemy_toughness == initial_toughness - 10


def test_no_dmg_reduction_when_enemy_broken(character):
# Set up the character with enemy broken
character.enemy_weakness_broken = True
initial_toughness = character.current_enemy_toughness

# Call the method
dmg = character._calculate_damage(skill_multiplier=1, break_amount=10, can_crit=False)

# Assert the damage is not reduced
assert dmg == character.atk
assert character.current_enemy_toughness == initial_toughness - 10
42 changes: 42 additions & 0 deletions tests/test_character/test_check_if_enemy_weakness_broken.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest
from hsr_simulation.character import Character

@pytest.fixture
def character():
return Character()

def test_enemy_weakness_broken(character):
# Set up the character with enemy toughness <= 0 and weakness not broken
character.current_enemy_toughness = 0
character.enemy_weakness_broken = False

# Call the method
character.check_if_enemy_weakness_broken()

# Assert the enemy weakness is broken and turn delayed duration is set
assert character.enemy_weakness_broken is True
assert character.enemy_turn_delayed_duration_weakness_broken == 1

def test_enemy_weakness_not_broken(character):
# Set up the character with enemy toughness > 0
character.current_enemy_toughness = 10
character.enemy_weakness_broken = False

# Call the method
character.check_if_enemy_weakness_broken()

# Assert the enemy weakness is not broken
assert character.enemy_weakness_broken is False
assert character.enemy_turn_delayed_duration_weakness_broken == 0

def test_enemy_already_weakness_broken(character):
# Set up the character with enemy weakness already broken
character.current_enemy_toughness = 0
character.enemy_weakness_broken = True

# Call the method
character.check_if_enemy_weakness_broken()

# Assert the enemy weakness remains broken and turn delayed duration is unchanged
assert character.enemy_weakness_broken is True
assert character.enemy_turn_delayed_duration_weakness_broken == 0
45 changes: 45 additions & 0 deletions tests/test_character/test_simulate_enemy_weakness_broken.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
from hsr_simulation.character import Character


@pytest.fixture
def character():
return Character()


def test_enemy_weakness_broken(character):
# Set up the character with enemy weakness broken
character.enemy_weakness_broken = True
character.enemy_turn_delayed_duration_weakness_broken = 1

# Call the method
character._simulate_enemy_weakness_broken()

# Assert the enemy turn delayed duration is decreased
assert character.enemy_turn_delayed_duration_weakness_broken == 0


def test_enemy_weakness_broken_regenerate(character):
# Set up the character with enemy weakness broken and no delay duration
character.enemy_weakness_broken = True
character.enemy_turn_delayed_duration_weakness_broken = 0

# Call the method
character._simulate_enemy_weakness_broken()

# Assert the enemy toughness is regenerated and weakness is not broken
assert character.current_enemy_toughness == character.enemy_toughness
assert not character.enemy_weakness_broken


def test_enemy_not_weakness_broken(character):
# Set up the character with enemy not weakness broken
character.enemy_weakness_broken = False

# Call the method
character._simulate_enemy_weakness_broken()

# Assert nothing changes
assert character.enemy_turn_delayed_duration_weakness_broken == 0
assert character.current_enemy_toughness == character.enemy_toughness
assert not character.enemy_weakness_broken

0 comments on commit b463d47

Please sign in to comment.