def test_addition_equals_zero(self):
     assert 0 == calculator.add(2, -2)
 def test_addition_yields_positive_value(self):
     assert 4 == calculator.add(2, 2)
 def test_when_two_numbers_used_no_exception(self):
     calculator.add("1,2")
     assert 1
 def test_add_yields_negative_value(self):
     assert -3 == calculator.add(-5, 2)
 def test_when_empty_string_return_zero(self):
     assert calculator.add("") == 0
 def test_when_delimiter_is_three_characters_long(self):
     assert calculator.add("//,-%\n3,-%6,-%15") == 3 + 6 + 15
 def test_when_negative_number_is_used_throw_exception(self):
     with pytest.raises(ValueError):
         calculator.add("3,-6,15,18,46,33")
Beispiel #8
0
from calculator import calculator


class Hello:
    @staticmethod
    def hello():
        print("Hello World")


Hello.hello()

try:
    assert (calculator.add(5, 6) == 11)
    print("first function success")
except:
    print("ADD function failed")

try:
    assert (calculator.sub(15, 3) == 12)
    print("second function success")
except:
    print("SUB function failed")

try:
    assert (calculator.mul(20, 20) == 400)
    print("third function success")
except:
    print("MUL function failed")

try:
    assert (calculator.div(100, 5) == 20)
 def test_when_new_line_is_used_return_sum(self):
     assert calculator.add("3,6\n15") == 3 + 6 + 15
 def test_when_delimiter_is_specified_use_it(self):
     assert calculator.add("//;\n3;6;15") == 3 + 6 + 15
 def test_when_any_number_of_numbers_used_return_sum(self):
     assert calculator.add("3,6,15,18,46,33") == 3 + 6 + 15 + 18 + 46 + 33
 def test_when_two_numbers_used_return_sum(self):
     assert calculator.add("3,6") == 3 + 6
 def test_when_one_number_used_return_same_number(self):
     assert calculator.add("3") == 3
Beispiel #14
0
def test_add():
    assert calculator.add(1, 2) == 3
 def test_when_negative_numbers_are_used_throw_exception(self):
     with pytest.raises(ValueError) as excinfo:
         calculator.add("3,-6,15,-18,46,33")
     assert "Negatives not allowed: [-6, -18]" in str(excinfo.value)
Beispiel #16
0
def test_cases():
    assert (calculator.add(5, 6) == 11)
    assert (calculator.sub(15, 3) == 12)
    assert (calculator.mul(20, 20) == 400)
    assert (calculator.div(100, 5) == 20)
    assert (calculator.mod(4, 6) == 4)
 def test_when_delimiter_is_two_characters_long(self):
     assert calculator.add("//,-\n3,-6,-15") == 3 + 6 + 15
Beispiel #18
0
 def test_addition(self):
     assert 4 == calculator.add(2, 2)
 def test_when_non_number_used_throw_exception(self):
     with pytest.raises(ValueError):
         calculator.add("1,X")