Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/pyste/tests/basicUT.py @ 47

Last change on this file since 47 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.3 KB
Line 
1# Copyright Bruno da Silva de Oliveira 2003. Use, modification and
2# distribution is subject to the Boost Software License, Version 1.0.
3# (See accompanying file LICENSE_1_0.txt or copy at
4# http:#www.boost.org/LICENSE_1_0.txt)
5import unittest
6from _basic import *
7
8class BasicExampleTest(unittest.TestCase):
9
10    def testIt(self):
11
12        # test virtual functions
13        class D(C):
14            def f(self, x=10):
15                return x+1
16
17        d = D()
18        c = C()
19
20        self.assertEqual(c.f(), 20)
21        self.assertEqual(c.f(3), 6)
22        self.assertEqual(d.f(), 11)
23        self.assertEqual(d.f(3), 4)
24        self.assertEqual(call_f(c), 20)
25        self.assertEqual(call_f(c, 4), 8)
26        self.assertEqual(call_f(d), 11)
27        self.assertEqual(call_f(d, 3), 4)
28       
29        # test data members
30        def testValue(value):
31            self.assertEqual(c.value, value)
32            self.assertEqual(d.value, value) 
33            self.assertEqual(get_value(c), value)
34            self.assertEqual(get_value(d), value)
35        testValue(1)
36        c.value = 30
37        d.value = 30
38        testValue(30)
39        self.assertEqual(c.const_value, 0)
40        self.assertEqual(d.const_value, 0)
41        def set_const_value():
42            c.const_value = 12
43        self.assertRaises(AttributeError, set_const_value)
44       
45        # test static data-members
46        def testStatic(value):
47            self.assertEqual(C.static_value, value)
48            self.assertEqual(c.static_value, value)
49            self.assertEqual(D.static_value, value)
50            self.assertEqual(d.static_value, value)
51            self.assertEqual(get_static(), value)
52        testStatic(3)
53        C.static_value = 10
54        testStatic(10)
55        self.assertEqual(C.const_static_value, 100)
56        def set_const_static():
57            C.const_static_value = 1
58        self.assertRaises(AttributeError, set_const_static)
59
60        # test static function
61        def test_mul(result, *args):
62            self.assertEqual(C.mul(*args), result)
63            self.assertEqual(c.mul(*args), result)
64        test_mul(16, 8, 2)
65        test_mul(6.0, 2.0, 3.0)
66        self.assertEqual(C.square(), 4)
67        self.assertEqual(c.square(), 4)
68        self.assertEqual(C.square(3), 9)
69        self.assertEqual(c.square(3), 9)
70
71
72if __name__ == '__main__':
73    unittest.main()
Note: See TracBrowser for help on using the repository browser.