Example #1
0
def test_get_edges__for_root__returns_expected():
    """
    Test getting the parent/child glasses for the top most glass in the tower.

    This test is used to verify that the root glass (the top most
    point in the tower) has no parents and two children.
    """
    #        (A)       <------- glass (A) has no parents and two
    #        / \                children (B) and (C)
    #      (B) (C)
    #      / \ / \
    #    (D) (E) (F)
    #    / \ / \ / \
    #  (G) (H) (I) (J)

    tower = moet.create_tower(4)
    glass = tower.get_glass("A")

    # Check parents
    parents = tower.get_parents(glass)
    assert not list(parents)

    # Check children
    children = tower.get_children(glass)
    assert [c.uid for c in children] == ["B", "C"]
Example #2
0
def test_get_parents__for_middle__returns_two_parents():
    """
    Test getting the parent glasses for a glass in the middle of row.

    This test is used to verify that a glass in the middle of a row
    has the correct parents and children.
    """
    #        (A)
    #        / \
    #      (B) (C)
    #      / \ / \
    #    (D) (E) (F)   <------- glass (E) has two parents (B) and (C)
    #    / \ / \ / \            and two children (H) and (I)
    #  (G) (H) (I) (J)

    tower = moet.create_tower(4)
    glass = tower.get_glass("E")

    # Check parents
    parents = tower.get_parents(glass)
    assert [p.uid for p in parents] == ["B", "C"]

    # Check children
    children = tower.get_children(glass)
    assert [c.uid for c in children] == ["H", "I"]
Example #3
0
def test_get_edges__for_column_right__returns_expected():
    """
    Test getting the parent/child glasses for a glass on the right edge.

    This test is used to verify that a glass on the right side of a
    row in the tower, has the correct parents and children.
    """
    #        (A)
    #        / \
    #      (B) (C)
    #      / \ / \
    #    (D) (E) (F)   <------- glass (F) has one parent (C) and two
    #    / \ / \ / \            children (I) and (J)
    #  (G) (H) (I) (J)

    tower = moet.create_tower(4)
    glass = tower.get_glass("F")

    # Check parents
    parents = tower.get_parents(glass)
    assert [p.uid for p in parents] == ["C"]

    # Check children
    children = tower.get_children(glass)
    assert [c.uid for c in children] == ["I", "J"]
Example #4
0
def test_get_glass__that_does_not_exist__returns_none():
    """
    Test getting a glass from a tower of glasses.

    This test demonstrates the behaviour when trying to get a glass
    that does not exist within a tower.
    """
    tower = moet.create_tower(4)
    glass = tower.get_glass("Z")
    assert glass is None
Example #5
0
def test_fill_tower__250_millilitres__returns_expected_liquid_in_glasses():
    """
    Test pouring 250 millilitres of liquid into a tower of glasses.
    """
    tower = moet.create_tower(rows=4)

    overflow = tower.fill(250)
    assert not overflow
    assert tower.get_glass("A").quantity == 250.0
    assert set(gls.quantity for gls in tower.glasses[1:]) == set([0.0])
Example #6
0
def test_get_edges__for_nonexistent_glass__raises_value_error():
    """
    Test getting the child/parent glasses for a glass that doesn't exist.
    """
    tower = moet.create_tower(4)

    # Check parents
    with pytest.raises(ValueError):
        tower.get_parents("Z")

    # Check children
    with pytest.raises(ValueError):
        tower.get_children("Z")
Example #7
0
def test_fill_tower__1000_millilitres__returns_expected_liquid_in_glasses():
    """
    Test pouring 1000 millilitres of liquid into a tower of glasses.
    """
    tower = moet.create_tower(rows=4)

    overflow = tower.fill(1000)
    assert not overflow
    assert tower.get_glass("A").quantity == 250.0
    assert tower.get_glass("B").quantity == 250.0
    assert tower.get_glass("C").quantity == 250.0
    assert tower.get_glass("D").quantity == 62.5
    assert tower.get_glass("E").quantity == 125.0
    assert tower.get_glass("F").quantity == 62.5
    assert set(gls.quantity for gls in tower.glasses[6:]) == set([0.0])
Example #8
0
def test_fill_tower__3750_millilitres__returns_expected_liquid_in_glasses():
    """
    Test pouring 3750 millilitres of liquid into a tower of glasses.
    """
    tower = moet.create_tower(rows=4)

    overflow = tower.fill(3750)
    assert overflow == 1250.0
    assert tower.get_glass("A").quantity == 250.0
    assert tower.get_glass("B").quantity == 250.0
    assert tower.get_glass("C").quantity == 250.0
    assert tower.get_glass("D").quantity == 250.0
    assert tower.get_glass("E").quantity == 250.0
    assert tower.get_glass("F").quantity == 250.0
    assert tower.get_glass("G").quantity == 250.0
    assert tower.get_glass("H").quantity == 250.0
    assert tower.get_glass("I").quantity == 250.0
    assert tower.get_glass("J").quantity == 250.0