Question
Python 3.8 Question Below is a class Spinner: Complete the TODO in the following file: === Module Description === This module contains sample tests for
Python 3.8 Question
Below is a class Spinner:
Complete the TODO in the following file:
=== Module Description === This module contains sample tests for Prep 2. Complete the TODO in this file.
We suggest you also add your own tests to practice writing tests and to be confident your code is correct.
When writing a test case, make sure you create a new function, with its name starting with "test_". For example:
def test_my_test_case(): # Your test here """ from hypothesis import given from hypothesis.strategies import integers from prep2 import Spinner
def test_buggy_consecutive_spins() -> None: """Test consecutive spins of your Spinner class. This test case has a bug in it."""
# TODO: There is a bug in this test case -- find it and fix it. # In its original state, this test case should NOT pass if # your Spinner is implemented correctly! # Do NOT change or remove any of the lines labelled with # "Do not change this line".
s = Spinner(6) # Do not change this line s.spin(2) # Do not change this line expected_value1 = 2 assert s.position == expected_value1 # Do not change this line s.spin(2) # Do not change this line expected_value2 = 2 assert s.position == expected_value2 # Do not change this line
# === Sample test cases below === # Use the below test cases as an example for writing your own test cases, # and as a start to testing your prep2.py code.
# WARNING: THIS IS CURRENTLY AN EXTREMELY INCOMPLETE SET OF TESTS! # We will test your code on a much more thorough set of tests!
# For more information on hypothesis (one of the testing libraries we're using), # please see #
# This is a hypothesis test; it generates a random integer to use as input, # so that we don't need to hard-code a specific number of slots in the test. @given(slots=integers(min_value=1)) def test_new_spinner_position(slots: int) -> None: """Test that the position of a new spinner is always 0.""" spinner = Spinner(slots) assert spinner.position == 0
def test_doctest() -> None: """Test the given doctest in the Spinner class docstring.""" spinner = Spinner(8)
spinner.spin(4) assert spinner.position == 4
spinner.spin(2) assert spinner.position == 6
spinner.spin(2) assert spinner.position == 0
if __name__ == '__main__': import pytest pytest.main(['prep2_starter_tests.py'])
=== Module Description === This module contains the documentation for a simple class. Your job is to implement the class below according to its docstring; note this includes both the instance attributes* of the class and the *methods* we've documented. As usual, delete the TODO comments after you've completed each part. There is also a task inside prep2_starter_tests.py. Make sure to look at that file and complete the TODO there as well. # Do NOT use any imports beyond this one (randint)! from random import randint class Spinner: "A spinner for a board game. A spinner has a certain number of slots, numbered starting at 9 and increasing by 1 each slot. For example, if the spinner has they are numbered through 5, inclusive. A spinner also has an arrow that points to one of these slots. === Attributes === slots: The number of slots in this spinner. position: The slot number that the spinner's arrow is currently pointing to. === Sample Usage === Creating a spinner: >>> S = Spinner(8) >>> s. position Spinning the spinner: >>> s. spin(4) >>> s. position >>> s. spin(2) >>> s.position 6 >>> s. spin(2) >>> s.position slots: int position: int def __init__(self, size: int) -> None: "Initialize a new spinner withStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started