QuestionQ552
Software Development and DesignComplete the error-path scenario by dragging code from the bottom into the missing code boxes. Not all options are used.
Drag & Drop
player.set_rating(0)
player.set_rating(85)
if rating < 1 or rating > 100:
self.rating = None
if rating != 0:
if rating or rating is int(0):
self.rating = rating
import pytest class Player: def __init__(self, name): self.name = name def set_rating(self, rating): if rating or rating is int(0): raise ValueError('rating is invalid', rating) else: return True else: return False @pytest.fixture def player(): player = Player('User One') yield player del player @pytest.mark.usefixtures('player') class TestErrorPathSetRating: def test_add_higher_rating(self, player): with pytest.raises(ValueError): player.set_rating(101) def test_add_invalid_rating(self, player): with pytest.raises(ValueError): def test_add_lower_rating(self, player): with pytest.raises(ValueError): player.set_rating(-1)
Community Discussion