def test_add(): # GIVEN two numbers # WHEN I invoke the method # THEN I get the addition of two numbers assert demo.add(3, 4) == 7 assert demo.add(1, 9) == 10 assert demo.add(2, 4) == 6
def test_add(): # GIVEN two numbers # WHEN I invoke the method # THEN I get the addition of two numbers add_result = demo.add(3,4) assert add_result == 7 assert demo.add(1,10) == 11 assert demo.add(2,4) == 6
def test_monkeypatch(self, monkeypatch): def fake_add(a, b): return 42 """ Monkeypatch add in demo to use fake_add for this test """ monkeypatch.setattr(demo, "add", fake_add) assert demo.add(2, 4) == 42
import demo a = demo.add(1,2) print(a) b = demo.add(-100,28) print(b)
def testAdd_05(self): """测试a>0 and b=0""" expected = -6 result = demo.add(6, 0) self.assertEqual(expected, result)
def test_add(self): """Test method add(a, b)""" self.assertEqual(3, add(1, 2)) self.assertNotEqual(3, add(2, 2))
def testAdd_07(self): """测试a=0 and b>0""" expected = -2 result = demo.add(-1, 3) self.assertEqual(expected, result)
def test_add(self): for i in range(10): assert demo.add(i, 2) == i + 2
def test_error(self): with pytest.raises(demo.MysteryError): assert demo.add(99, 1) == 100
def test2(self) -> None: z = demo.add(5, 4) self.assertEqual(z, 8)
def test_error(self): """ Ex of using the pytest context manager for errors """ with pytest.raises(demo.DemoError): assert demo.add(99, 1) == 100
""" Example code for demostrating the demo Python C module. """ import demo print("Hello from demo") print("add: ", demo.add(3, 4)) print(demo.add(23, "234"))
def test_add(self): assert demo.add(1, 2) == 3
def testAdd_01(self): """测试a>0 and b>0""" expected = 5 result = demo.add(2, 3) self.assertEqual(expected, result)
def testAdd_09(self): """测试a>0 and b<0""" expected = 2 result = demo.add(1, -3) self.assertEqual(expected, result)
def testAdd_08(self): """测试a<0 and b<0""" expected = 4 result = demo.add(-1, -3) self.assertEqual(expected, result)
def test_add(): print("In add test") added = demo.add("hej ", "hopp") test.assert_equal("hej hopp", added) test.assert_not_equal("hej", added)
def test1(self) -> None: z = demo.add(3, 4) self.assertEqual(z, 7)
demo.print_global() print("----- STRUCT -----") a = demo.Point() print((a.x, a.y)) a.x, a.y = 100, 200 print((demo._demo.Point_x_get(a))) print("----- CLASS -----") p = demo.CPoint() p.x, p.y = 3, 4 print((p.power())) print("----- FUNCTION -----") print((demo.add_mult(3, 4))) print((demo.add(4, 5))) print((demo.inc(4))) print("----- FUNCTION POINTER -----") print((demo.reciprocal(10))) print((demo.reciprocal, demo.cb_reciprocal)) print((demo.sum_func(demo.cb_reciprocal, 1, 100))) print("----- CALLBACK ------") class SumReciprocal(demo.Sum): def Func(self, x): return 1.0 / x
def test_with_param(self, a, b, expected): assert demo.add(a, b) == expected
from demo import add print add(1, 2)
def test_monkeypatch(monkeypatch): def fake_add(a, b): return 42 monkeypatch.setattr(demo, "add", fake_add) assert demo.add(2, 3) == 42
from time import time from demo import add s = time() for i in range(1, 10000000): r = add(i, i) print(time() - s)
def test_add(): assert demo.add(1, 2) == 3
def testAdd_06(self): """测试a<0 and b=0""" expected = 6 result = demo.add(-6, 0) self.assertEqual(expected, result)
def test_add(): assert add(2, 2) == 4
def test_add_more(): for i in range(10): assert demo.add(1, i) == i + 2 assert demo.add(1, 100) == 101
## # @file # Python script that calls C++ classes and functions from demo module. # # Import module created. import demo # Calling basic function. print("1 + 2 = " + str(demo.add(1, 2))) print("5 + 6 = " + str(demo.add(5, 6))) print("") # Creating Dog class that inherits Pet properties. d = demo.Dog("Molly") # Calling Pet functions on Dog object. print("My dog's name is " + d.getName()) d.setName("Charlie") print("My dog's name is now " + d.getName()) # Calling overridden sound function. print("My dog goes " + d.sound()) print("") # Creating Cat class that inherits Pet properties. c = demo.Cat("Tom") # Calling Pet functions on Cat object. print("My cat's name is " + c.getName()) c.setName("Jerry")
def test_add_1_and_1_should_equal_2(self): self.assertEquals(2, add(1, 1))
print demo.cvar.global_test demo.cvar.global_test *= 3 demo.print_global() print "----- STRUCT -----" a = demo.Point() print a.x, a.y a.x, a.y = 100, 200 print demo._demo.Point_x_get(a) print "----- CLASS -----" p = demo.CPoint() p.x, p.y = 3, 4 print p.power() print "----- FUNCTION -----" print demo.add_mult(3,4) print demo.add(4,5) print demo.inc(4) print "----- FUNCTION POINTER -----" print demo.reciprocal(10) print demo.reciprocal, demo.cb_reciprocal print demo.sum_func(demo.cb_reciprocal, 1, 100) print "----- CALLBACK ------" class SumReciprocal(demo.Sum): def Func(self, x): return 1.0/x print SumReciprocal().Cal(1, 100)
def testAdd_03(self): """测试a=0 and b<0""" expected = 3 result = demo.add(0, -3) self.assertEqual(expected, result)