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"
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)
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"
Esempio n. 4
0
def test_addition(answer):
    calculator = Calculator()
    assert calculator.add(2, 2) == answer
Esempio n. 5
0
def test_raise_by_power():
    calculator = Calculator()
    assert calculator.power(10, 2) == 100
Esempio n. 6
0
def test_division(answer):
    calculator = Calculator()
    assert calculator.divide(8, 2) == answer
Esempio n. 7
0
def test_multiplication(answer):
    calculator = Calculator()
    assert calculator.multiply(2, 2) == answer
Esempio n. 8
0
def test_sbustraction_wrong_value():
    calculator = Calculator()
    with pytest.raises(Exception):
        assert calculator.substract("test", 2) == 0
Esempio n. 9
0
def test_substraction(answer):
    calculator = Calculator()
    assert calculator.substract(6, 2) == answer
Esempio n. 10
0
def test_addition_with_char_exception():
    calculator = Calculator()
    with pytest.raises(Exception):
        assert calculator.add("three", 2)
Esempio 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)
Esempio n. 12
0
def test_calculator_meter_and_integer_only():
    calculator = Calculator()
    result = calculator.sum("3 Meters", "5 Meters")
    assert result == "8 Meters"
Esempio 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"