Exemplo n.º 1
0
def test_calculator_with_custom_output_unit():
    calculator = Calculator()
    result = calculator.sum("3 Meters", "5 Meters", "Milimeters")
    assert result == "8000 Milimeters"

    result = calculator.sum("1 Kilometers", "5 Meters", "Milimeters")
    assert result == "1005000 Milimeters"
Exemplo n.º 2
0
def test_calculator_with_invalid_units():
    calculator = Calculator()
    with pytest.raises(UnitException) as ex:
        result = calculator.sum("3 AlienMeter", "5 Meters", "Milimeters")
    assert "AlienMeter" in str(ex.value)
    with pytest.raises(NonNumerical) as ex:
        result = calculator.sum("X Meters", "5 Meters", "Milimeters")
    assert "X" in str(ex.value)
Exemplo n.º 3
0
def test_calculator_different_input_unit():
    calculator = Calculator()
    result = calculator.sum(
        "3 Decimeters",
        "5 Meters",
    )
    assert result == "5.3 Meters"

    result = calculator.sum(
        "3 Milimeters",
        "5 Meters",
    )
    assert result == "5.003 Meters"

    result = calculator.sum(
        "3 Milimeters",
        "5 Milimeters",
    )
    assert result == "0.008 Meters"

    result = calculator.sum(
        "1 Kilometers",
        "1 Meters",
    )
    assert result == "1001 Meters"
Exemplo n.º 4
0
def test_addition(answer):
    calculator = Calculator()
    assert calculator.add(2, 2) == answer
Exemplo n.º 5
0
def test_raise_by_power():
    calculator = Calculator()
    assert calculator.power(10, 2) == 100
Exemplo n.º 6
0
def test_division(answer):
    calculator = Calculator()
    assert calculator.divide(8, 2) == answer
Exemplo n.º 7
0
def test_multiplication(answer):
    calculator = Calculator()
    assert calculator.multiply(2, 2) == answer
Exemplo n.º 8
0
def test_sbustraction_wrong_value():
    calculator = Calculator()
    with pytest.raises(Exception):
        assert calculator.substract("test", 2) == 0
Exemplo n.º 9
0
def test_substraction(answer):
    calculator = Calculator()
    assert calculator.substract(6, 2) == answer
Exemplo n.º 10
0
def test_addition_with_char_exception():
    calculator = Calculator()
    with pytest.raises(Exception):
        assert calculator.add("three", 2)
Exemplo n.º 11
0
def test_calculator_with_invalid_units():
    calculator = Calculator()
    with pytest.raises(FormatException) as ex:
        result = calculator.sum("1", "Meter")
    assert "Expecting 'Value Unit'" in str(ex.value)
Exemplo n.º 12
0
def test_calculator_meter_and_integer_only():
    calculator = Calculator()
    result = calculator.sum("3 Meters", "5 Meters")
    assert result == "8 Meters"
Exemplo n.º 13
0
def test_calculator_meter_and_float_values():
    calculator = Calculator()
    result = calculator.sum("3.2 Meters", "5.7 Meters")
    assert result == "8.9 Meters"