Skip to content

Commit

Permalink
fix failed test - missing player metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamJ335-T2 committed Oct 22, 2024
1 parent 01fc517 commit 1f4b69f
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions src/app/model/group/group_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

class GroupSpec:
group_name = 'group_name'
player_adam = Player('1', 'Adam','Awesome', 4, '1', 5, 1000, 10)

def should_not_update_scroll_if_new_streak_lower_than_the_lowest_record_streak(self):
""" Should not update scroll if new streak lower than the lowest record streak """
# Given
players = [Player('1', 'Adam', 4, '1', 1000, 10), Player('2', 'Hayden', 3, '2', 1000, 10), Player('3', 'James', 2, '3', 1000, 10)]
players = [get_player('Adam'), get_player('Hayden'), get_player('James')]
scroll = [Record('Adam', 4, '1', 'today'), Record('Hayden', 3, '2', 'today'), Record('James', 2, '3', 'today')]
subject = Group(self.group_name, players, '1', scroll)

test = Player('4', 'Maciej', 1, '4', 1000, 10)
test = get_player('Maciej')

# When
subject.update_scroll(test)
Expand All @@ -26,11 +27,11 @@ def should_not_update_scroll_if_new_streak_lower_than_the_lowest_record_streak(s
def should_update_scroll_if_new_streak_lower_than_the_lowest_record_streak_but_scroll_has_capacity(self):
""" Should update scroll if new streak lower than the lowest record streak but scroll has capacity"""
# Given
players = [Player('1', 'Adam', 4, '1', 1000, 10), Player('2', 'Hayden', 3, '2', 1000, 10)]
players = [get_player('Adam'), get_player('Hayden')]
scroll = [Record('Adam', 4, '1', 'today'), Record('Hayden', 3, '2', 'today')]
subject = Group(self.group_name, players, '1', scroll)

test = Player('4', 'Maciej', 2, '4', 1000, 10)
test = Player('4', 'Maciej', 'Pole', 2, '4', 4, 1000, 10)
# Note :: streaks are defined as being >= 2

# When
Expand All @@ -42,12 +43,11 @@ def should_update_scroll_if_new_streak_lower_than_the_lowest_record_streak_but_s
def should_update_existing_record_if_player_streak_is_active_on_the_scroll(self):
""" Should update existing record if worthy player streak is active on the scroll """
# Given
players = [Player('1', 'Adam', 4, '1', 1000, 10), Player('2', 'Hayden', 3, '2', 1000, 10),
Player('3', 'James', 2, '3', 1000, 10)]
players = [get_player('Adam'), get_player('Hayden'), get_player('James')]
scroll = [Record('Adam', 4, '1', 'today'), Record('Hayden', 3, '2', 'today'), Record('James', 2, '3', 'today')]
subject = Group(self.group_name, players, '1', scroll)

test = Player('1', 'Adam', 5, '1', 1005, 10)
test = Player('1', 'Adam','Awesome', 5, '1',5, 1005, 10)

# When
subject.update_scroll(test)
Expand All @@ -59,11 +59,11 @@ def should_update_existing_record_if_player_streak_is_active_on_the_scroll(self)
def should_add_new_record_if_worthy_streak_is_not_active_on_the_scroll_and_scroll_below_capacity(self):
""" Should add new record if worthy streak is not active on the scroll and scroll below capacity """
# Given
players = [Player('1', 'Adam', 4, '1', 1000, 10), Player('2', 'Hayden', 3, '2', 1000, 10)]
players = [get_player('Adam'), get_player('Hayden')]
scroll = [Record('Adam', 4, '1', 'today'), Record('Hayden', 3, '2', 'today')]
subject = Group(self.group_name, players, '1', scroll)

test = Player('1', 'Adam', 5, '3', 1005, 11)
test = Player('1', 'Adam','Awesome', 5, '3',5, 1005, 11)

# When
subject.update_scroll(test)
Expand All @@ -78,12 +78,11 @@ def should_add_new_record_if_worthy_streak_is_not_active_on_the_scroll_and_scrol
def should_replace_an_old_record_if_worthy_streak_is_not_active_on_the_scroll_and_scroll_at_capacity(self):
""" Should replace an old record if worthy streak is not active on the scroll and scroll at capacity """
# Given
players = [Player('1', 'Adam', 4, '1', 1000, 10), Player('2', 'Hayden', 3, '2', 1000, 10),
Player('3', 'James', 2, '3', 1000, 10)]
players = [get_player('Adam'), get_player('Hayden'), get_player('James')]
scroll = [Record('Adam', 4, '1', 'today'), Record('Hayden', 3, '2', 'today'), Record('James', 2, '3', 'today')]
subject = Group(self.group_name, players, '1', scroll)

test = Player('1', 'Adam', 5, '4', 1005, 11)
test = Player('1', 'Adam','Awesome', 5, '4', 5, 1005, 11)

# When
subject.update_scroll(test)
Expand All @@ -98,10 +97,10 @@ def should_replace_an_old_record_if_worthy_streak_is_not_active_on_the_scroll_an
def should_dethrone_king_by_crowning_next_highest_player(self):
""" Should dethrone king by crowning next highest player """
# Given
players = [Player('1', 'Adam', 4, '1', 1000, 10), Player('2', 'Hayden', 3, '2', 1000, 10), Player('3', 'James', 2, '3', 1000, 10)]
players = [get_player('Adam'), get_player('Hayden'), get_player('James')]
subject = Group(self.group_name, players, '1', [])

test = Player('1', 'Adam', 0, '1', 1000, 10)
test = Player('1', 'Adam','Awesome', 0, '1',5, 1000, 10)

# When
subject.update_player(test)
Expand All @@ -111,10 +110,10 @@ def should_dethrone_king_by_crowning_next_highest_player(self):
assert subject.king == '2'

def should_dethrone_king_and_king_stays_same_with_other_player_updated(self):
players = [Player('1', 'Adam', 5, '1', 1000, 10), Player('2', 'Hayden', 4, '2', 1000, 10)]
players = [get_player('Adam'), get_player('Hayden')]
subject = Group(self.group_name, players, '1', [])

test = Player('1', 'Adam', 0, '1', 1000, 11)
test = Player('1', 'Adam','Awesome', 0, '1',5, 1000, 11)

# When
subject.update_player(test)
Expand All @@ -123,7 +122,7 @@ def should_dethrone_king_and_king_stays_same_with_other_player_updated(self):
assert subject.king == '2'

# And another player goes who is not the king
test_adam = Player('1', 'Adam', 1, '3', 1000, 12)
test_adam = Player('1', 'Adam','Awesome', 1, '3',5, 1000, 12)
subject.update_player(test_adam)

# Then : King is still Hayden
Expand All @@ -132,10 +131,10 @@ def should_dethrone_king_and_king_stays_same_with_other_player_updated(self):
def should_reset_streak_id_when_player_has_streak_of_zero(self):
""" Should reset streak id when player has streak of zero """
# Given
players = [Player('1','Adam', 4, '1', 1000, 10)]
players = [get_player('Adam')]
subject = Group(self.group_name, players, '1', [])

test = Player('1', 'Adam', 0, '1', 1000, 10)
test = Player('1', 'Adam','Awesome', 0, '1',5, 1000, 10)

# When
subject.update_player(test)
Expand All @@ -146,13 +145,25 @@ def should_reset_streak_id_when_player_has_streak_of_zero(self):
def should_not_reset_streak_id_when_player_has_non_zero_streak(self):
""" Should not reset streak id when player has non-zero streak """
# Given
players = [Player('1', 'Adam', 4, '1', 1000, 10)]
players = [get_player('Adam')]
subject = Group(self.group_name, players, '1', [])

test = Player('1', 'Adam', 5, '1', 1000, 10)
test = Player('1', 'Adam','Awesome', 5, '1',5, 1000, 10)

# When
subject.update_player(test)

# Then : Adam should have new streak id
assert [x for x in subject.players if x.name == 'Adam'][0].streak_id == '1'
assert [x for x in subject.players if x.name == 'Adam'][0].streak_id == '1'


def get_player(player_name):
if player_name == 'Adam':
return Player('1', 'Adam','Awesome', 5, '1',5, 1000, 10)
elif player_name == 'James':
return Player('3', 'James','Christian', 2, '3',2, 1000, 10)
elif player_name == 'Hayden':
return Player('2', 'Hayden','TestWell', 4, '2', 4, 1000, 10)
else:
return Player('4', 'Maciej', 'Pole', 1, '4', 4, 1000, 10)

0 comments on commit 1f4b69f

Please sign in to comment.