コード例 #1
0
def test_shouldRaiseExceptionWhenZeroColumnGiven():
    numberOfRows = 1
    quantity = 1
    stack = StackOfGlasses(numberOfRows)
    stack.pour(quantity)
    with pytest.raises(ValueError):
        assert stack.getAmountAt(1, 0)
コード例 #2
0
def test_shouldReturnAmountInGlassInSecondRow():
    numberOfRows = 2
    quantity = 0.45
    stack = StackOfGlasses(numberOfRows)
    stack.pour(quantity)
    assert stack.getAmountAt(2, 1) == pytest.approx(0.1)
    assert stack.getAmountAt(2, 2) == pytest.approx(0.1)
コード例 #3
0
def test_shouldFillTotalCapacityFirstGlassAndOverflowDistributedEqually():
    numberOfRows = 2
    quantity = 0.35
    stack = StackOfGlasses(numberOfRows)
    stack.pour(quantity)
    assert stack.stack[0][0].volume == stack.stack[0][0].capacity
    assert stack.stack[1][0].volume == pytest.approx(0.05)
    assert stack.stack[1][1].volume == pytest.approx(0.05)
コード例 #4
0
def test_shouldCreateStackWith10Rows():
    numberOfRows = 10
    stack = StackOfGlasses(numberOfRows)
    assert len(stack.stack) == numberOfRows
    for row in range(numberOfRows):
        numberOfColumns = row + 1
        assert len(stack.stack[row]) == numberOfColumns
コード例 #5
0
def test_shouldFillMultipleRows():
    numberOfRows = 5
    quantity = 3
    stack = StackOfGlasses(numberOfRows)
    stack.pour(quantity)
    assert stack.stack[0][0].volume == stack.stack[0][0].capacity
    assert stack.stack[1][0].volume == stack.stack[0][0].capacity
    assert stack.stack[1][1].volume == stack.stack[0][0].capacity
    assert stack.stack[2][0].volume == stack.stack[0][0].capacity
    assert stack.stack[2][1].volume == stack.stack[0][0].capacity
    assert stack.stack[2][2].volume == stack.stack[0][0].capacity
    assert stack.stack[3][0].volume == stack.stack[0][0].capacity
    assert stack.stack[3][1].volume == stack.stack[0][0].capacity
    assert stack.stack[3][2].volume == stack.stack[0][0].capacity
    assert stack.stack[3][3].volume == stack.stack[0][0].capacity
    assert stack.stack[4][0].volume == pytest.approx(0.1)
    assert stack.stack[4][1].volume == pytest.approx(0.1)
    assert stack.stack[4][2].volume == pytest.approx(0.1)
    assert stack.stack[4][3].volume == pytest.approx(0.1)
    assert stack.stack[4][4].volume == pytest.approx(0.1)
コード例 #6
0
def test_shouldReturnAmountInGlassInThirdRow():
    numberOfRows = 3
    quantity = 0.45
    stack = StackOfGlasses(numberOfRows)
    stack.pour(quantity)
    assert stack.getAmountAt(3, 1) == 0
    assert stack.getAmountAt(3, 2) == 0
    assert stack.getAmountAt(3, 3) == 0
コード例 #7
0
def test_shouldFillFirstGlass():
    numberOfRows = 2
    quantity = 0.1
    stack = StackOfGlasses(numberOfRows)
    stack.pour(quantity)
    assert stack.stack[0][0].volume == quantity
コード例 #8
0
def test_shouldRaiseExceptionWhenPouringZeroQuantity():
    numberOfRows = 1
    quantity = 0
    stack = StackOfGlasses(numberOfRows)
    with pytest.raises(ValueError):
        stack.pour(quantity)
コード例 #9
0
def test_shouldRaiseExceptionWhenZeroRowsGiven():
    numberOfRows = 0
    with pytest.raises(ValueError):
        assert StackOfGlasses(numberOfRows)
コード例 #10
0
def test_shouldCreateStackWith1Row():
    numberOfRows = 1
    stack = StackOfGlasses(numberOfRows)
    assert len(stack.stack) == numberOfRows
コード例 #11
0
def test_shouldRaiseExceptionWhenNonIntegerRowsGiven():
    numberOfRows = 1.1
    with pytest.raises(ValueError):
        assert StackOfGlasses(numberOfRows)
コード例 #12
0
def test_shouldReturnAmountInGlassInFirstRow():
    numberOfRows = 1
    quantity = 0.1
    stack = StackOfGlasses(numberOfRows)
    stack.pour(quantity)
    assert stack.getAmountAt(1, 1) == pytest.approx(0.1)
コード例 #13
0
def test_shouldReturnZeroAmount():
    numberOfRows = 1
    stack = StackOfGlasses(numberOfRows)
    assert stack.getAmountAt(1, 1) == 0
コード例 #14
0
def test_shouldRaiseExceptionWhenGlassDoesntExist():
    numberOfRows = 1
    stack = StackOfGlasses(numberOfRows)
    with pytest.raises(ValueError):
        assert stack.getAmountAt(2, 1)
コード例 #15
0
import sys
from stackOfGlasses import StackOfGlasses

if __name__ == "__main__":
    try:
        row = int(sys.argv[1])
        column = int(sys.argv[2])
        amount = float(sys.argv[3])

        stack = StackOfGlasses(row)
        stack.pour(amount)
        
        amountInGlass = stack.getAmountAt(row, column)
        print("The amount in row %i, column %i is: %f" % (row, column, amountInGlass))
        
    except ValueError as err:
        print("Error: {0}".format(err))
    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise