def test_glass_repr__returns_expected_value(): """ Test the object representation of a glass. This test is used to verify that the object representation of a glass contains the expected information (i.e. uid and position). """ glass = moet.create_glass("A") assert "moet.glass.Glass(uid=A, pos=None)" in repr(glass)
def test_set_glass_capacity__with_invalid_numbers__returns_expected(): """ Test setting the value for the amount of liquid a glass can hold. In this case, we're using invalid numbers (i.e. negative numbers) """ glass = moet.create_glass("A") with pytest.raises(ValueError): glass.capacity = -100
def test_glass_str__returns_uid(): """ Test the string representation of a glass. This test is used to verify that the string representation of a glass is the glass's unique identifier. """ glass = moet.create_glass("A") assert str(glass) == glass.uid
def test_create_glass__returns_expected_value(): """ Test creating a glass. This test demonstrates how to create a glass. It is also used to verify the initial values of the glass properties. """ glass = moet.create_glass("A") assert glass.uid == "A" assert glass.position is None
def test_set_glass_millilitres__with_negative_number__raises_value_error(): """ Test setting the amount of liquid in the glass directly. This test demonstrates the behaviour when trying to set the amount of liquid in a glass using a negative number. """ glass = moet.create_glass("A") with pytest.raises(ValueError): glass.quantity = -100
def test_set_glass_capacity__with_valid_numbers__returns_expected(): """ Test setting the value for the amount of liquid a glass can hold. In this case, we're using valid numbers (i.e. 0 or greater) """ glass = moet.create_glass("A") numbers = [0, 1, 250, 0.0, 100.5] for number in numbers: glass.capacity = number assert glass.capacity == number
def test_fill_glass__with_no_overflow__returns_expected(number): """ Test filling a glass with liquid. Args: number (int or float): The number of millilitres to fill the glass with. """ glass = moet.create_glass("A") overflow = glass.fill(number) assert not overflow assert glass.quantity == number
def test_fill_glass__with_overflow__returns_expected(number): """ Test filling a glass with liquid. This test demonstrates the behaviour when trying to fill a glass with more liquid than it is capable of holding. Args: number (int or float): The number of millilitres to fill the glass with. """ glass = moet.create_glass("A") overflow = glass.fill(number) assert overflow == number - 250 assert glass.quantity == 250
def test_add_glasses_to_tower(number): """ Test adding glasses to a tower. This test demonstrates how to add glasses to a tower of glasses. It then verifies that the glasses were added by checking the properties of the tower. Args: number (int): The number of glasses to add to the tower. """ tower = moet.Tower() glasses = [] for index in range(number): id_ = moet.utils.get_id(index) glass = moet.create_glass(id_) tower.add_glass(glass) glasses.append(glass) assert tower.glasses == glasses
def test_add_glasses_to_tower__returns_expected_positions(number): """ Test getting the position of a glass in the tower. This test demonstrates how to get the position of a glass in a tower of glasses. Args: number (int): The number of glasses to add to the tower """ tower = moet.Tower() # Add glasses for index in range(number): id_ = moet.utils.get_id(index) glass = moet.create_glass(id_) tower.add_glass(glass) # Check positions. rows = list(tower.get_rows()) for row_index, row in enumerate(rows): for column_index, glass in enumerate(row): print(glass, glass.position) assert glass.position == (row_index, column_index)
def test_glass_capacity__has_expected_default_value(): """ Test the default value for the amount of liquid a glass can hold. """ glass = moet.create_glass("A") assert glass.capacity == 250