def test_4(self): c = Calc() c.press("1") c.press("+") c.press("1") c.press("=") self.assertEqual(c.display, "2")
def test_5(self): c = Calc() c.press("1") # 1 c.press("+") # 1+ c.press("1") # 1+1 c.press("=") # 2 c.press("+") # 2 + c.press("1") # 2 + 1 c.press("=") # 3 self.assertEqual(c.display, "3")
def get_results(stype, slength): """ Takes a type of search, and the number of primes wanted, and returns a list of integers. """ # Give us an instance of the Calc class calc = Calc(slength) # The class will check for valid search type calc.run_method(stype) return {'error_msg': calc.errors, 'result': calc.result}
def test_6(self): """1+1+1+2=5""" c = Calc() c.press("1") c.press("+") c.press("1") c.press("+") c.press("1") c.press("+") c.press("2") c.press("=") self.assertEqual(c.display, "5")
class TestCalc: """ test calculator's function """ def setup_class(self): print('开始计算') self.cc = Calc() def teardown_class(self): print('结束计算') @pytest.mark.parametrize('a,b,expect', [[1, 2, 3], [1, 0, 1], [100, 200, 300], [-1, -2, -3], [0.1, 1, 1.1], [0.3, 0.6, 0.9]]) def test_add(self, a, b, expect): result = self.cc.add(a, b) assert result == expect @pytest.mark.parametrize('a,b,expect', [(1, 2, -1), (1, 1, 0), (2, 1, 1), (-1, -1, 0)]) def test_minus(self, a, b, expect): result = self.cc.minus(a, b) assert result == expect @pytest.mark.parametrize('a,b,expect', [(1, 2, 2), (1, 1, 1), (0, 2, 0), (-1, -1, 1), (-10, 10, -100), (0.1, 0.2, 0.02)]) def test_multiple(self, a, b, expect): result = self.cc.multiple(a, b) assert result == expect @pytest.mark.parametrize('a,b,expect', [[1, 1, 1], [1, 2, 0.5], [4, 2, 2], [0, 4, 0]]) def test_divide(self, a, b, expect): result = self.cc.divide(a, b) assert result == expect def test_divide_divisor_is_zero(self, a=1, b=0): result = self.cc.divide(a, b) assert result == '除数不能为零'
def setup_class(self): print('开始计算') self.cc = Calc()
from calculator import Calc new1 = Calc() new1.control()
def test_mul(self): assert 100 == Calc.mul(10, 10) assert 50 == Calc.mul(5, 10)
def test_2(self): c = Calc() c.press("1") c.press("2") c.press("C") self.assertEqual(c.display, "")
def test_3(self): c = Calc() c.press("1") self.assertEqual(c.display, "1")
#!/usr/bin/env python3 from calculator import Calc def isEven(value): return value % 2 == 0 def exampleExtract(value): if isEven(value): print("even") else: print("odd") def printIsEven(value): exampleExtract(value) calculator = Calc() print("1 + 2 = ", calculator.summary(1, 2)) print("2 x 2 = ", calculator.multiply(2, 2)) print("2 is = ", ) printIsEven(2) print("3 is = ", ) printIsEven(3)
def test_sub(self): assert 4 == Calc.sub(6, 2) assert 5 == Calc.sub(10, 5)
def test_add(self): assert 4 == Calc.add(2, 2) assert 10 == Calc.add(4, 6)
def test_add_newline_returns_sum() -> None: assert Calc.ADD("1\n2,3") == 6
def test_add_morenumbers_returns_sum() -> None: assert Calc.ADD("1,2,3,4,5") == 15
def test_add_twonumbers_returns_sum() -> None: assert Calc.ADD("1,2") == 3
def calc(): return Calc()
def test_7(self): """1+1+1+2=5""" c = Calc() c.press("1") c.press("+") c.press("1") c.press("=") c.press("C") c.press("1") c.press("+") c.press("3") c.press("=") self.assertEqual(c.display, "4")
def test_sub(self): assert 5 == Calc.sub(6, 1) assert 10 == Calc.sub(20, 10)
def test_add(self): assert 4 == Calc.add(2, 2) assert 4 == Calc.add(1, 3)
async def calc(ctx, *, calculation): await ctx.send("Math Result: " + str(Calc.evaluate(calculation)))
def setUp(self): self.calc = Calc()
def test_add_1_returns_1() -> None: assert Calc.ADD("1") == 1
# тестируем калькулятор здесь from calculator import Calc calc = Calc() print("load registy testing...") calc.add("123.456", "789.01") calc.add("333.0") print("stack testing 1... Check: проверяем алгоритм LIFO") calc._Calc__stackPush(1) calc._Calc__stackPush(2) calc._Calc__stackPush(3) print(calc._Calc__stackPop()) print(calc._Calc__stackPop()) print(calc._Calc__stackPop()) print("stack testing 2... Check: проверяем очистку стека") calc._Calc__stackPush(1) calc._Calc__stackPush(2) calc._Calc__stackPush(3) calc._Calc__stackClear() print(calc._Calc__stackPop()) print("stack testing 3... Check: проверяем частичную очистку стека") calc._Calc__stackPush(1) calc._Calc__stackPush(2) calc._Calc__stackPush(3)
def test_add_greater1000_returns_sum() -> None: assert Calc.ADD("1001,2") == 2
def test_add_negative_returns_error() -> None: assert Calc.ADD("2,-4,3,-5") == "Negatives not allowed: -4,-5"
def test_add_empty_returns_zero() -> None: assert Calc.ADD("") == 0
def test_1(self): c = Calc() self.assertEqual(c.display, "")
def test_sub(self): assert 10 == Calc.sub(20, 10) assert 100 == Calc.sub(100, 0)