Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
    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
Esempio n. 4
0
import demo

a = demo.add(1,2)
print(a)
b = demo.add(-100,28)
print(b)
Esempio n. 5
0
    def testAdd_05(self):
        """测试a>0 and b=0"""

        expected = -6
        result = demo.add(6, 0)
        self.assertEqual(expected, result)
Esempio n. 6
0
 def test_add(self):
     """Test method add(a, b)"""
     self.assertEqual(3, add(1, 2))
     self.assertNotEqual(3, add(2, 2))
Esempio n. 7
0
    def testAdd_07(self):
        """测试a=0 and b>0"""

        expected = -2
        result = demo.add(-1, 3)
        self.assertEqual(expected, result)
Esempio n. 8
0
 def test_add(self):
     for i in range(10):
         assert demo.add(i, 2) == i + 2
Esempio n. 9
0
 def test_error(self):
     with pytest.raises(demo.MysteryError):
         assert demo.add(99, 1) == 100
Esempio n. 10
0
 def test2(self) -> None:
     z = demo.add(5, 4)
     self.assertEqual(z, 8)
Esempio n. 11
0
 def test_error(self):
     """ Ex of using the pytest context manager for errors """
     with pytest.raises(demo.DemoError):
         assert demo.add(99, 1) == 100
Esempio n. 12
0
"""
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"))
Esempio n. 13
0
 def test_add(self):
     assert demo.add(1, 2) == 3
Esempio n. 14
0
 def testAdd_01(self):
     """测试a>0 and b>0"""
     expected = 5
     result = demo.add(2, 3)
     self.assertEqual(expected, result)
Esempio n. 15
0
    def testAdd_09(self):
        """测试a>0 and b<0"""

        expected = 2
        result = demo.add(1, -3)
        self.assertEqual(expected, result)
Esempio n. 16
0
    def testAdd_08(self):
        """测试a<0 and b<0"""

        expected = 4
        result = demo.add(-1, -3)
        self.assertEqual(expected, result)
Esempio n. 17
0
def test_add():
    print("In add test")
    added = demo.add("hej ", "hopp")
    test.assert_equal("hej hopp", added)
    test.assert_not_equal("hej", added)
Esempio n. 18
0
def test_add():
    print("In add test")
    added = demo.add("hej ", "hopp")
    test.assert_equal("hej hopp", added)
    test.assert_not_equal("hej", added)
Esempio n. 19
0
 def test1(self) -> None:
     z = demo.add(3, 4)
     self.assertEqual(z, 7)
Esempio n. 20
0
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

Esempio n. 21
0
 def test_with_param(self, a, b, expected):
     assert demo.add(a, b) == expected
Esempio n. 22
0
from demo import add

print add(1, 2)
Esempio n. 23
0
def test_monkeypatch(monkeypatch):
    def fake_add(a, b):
        return 42

    monkeypatch.setattr(demo, "add", fake_add)
    assert demo.add(2, 3) == 42
Esempio n. 24
0
from time import time
from demo import add

s = time()
for i in range(1, 10000000):
    r = add(i, i)
print(time() - s)
Esempio n. 25
0
def test_add():
    assert demo.add(1, 2) == 3
Esempio n. 26
0
    def testAdd_06(self):
        """测试a<0 and b=0"""

        expected = 6
        result = demo.add(-6, 0)
        self.assertEqual(expected, result)
Esempio n. 27
0
def test_add():
    assert add(2, 2) == 4
Esempio n. 28
0
def test_add_more():
    for i in range(10):
        assert demo.add(1, i) == i + 2
    assert demo.add(1, 100) == 101
Esempio n. 29
0
##
# @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")
Esempio n. 30
0
 def test_add_1_and_1_should_equal_2(self):
     self.assertEquals(2, add(1, 1))
Esempio n. 31
0
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)  
Esempio n. 32
0
    def testAdd_03(self):
        """测试a=0 and b<0"""

        expected = 3
        result = demo.add(0, -3)
        self.assertEqual(expected, result)