stl_containers.py 1.14 KB
Newer Older
John Parent's avatar
John Parent committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import os, sys
import unittest

sys.path.append(os.getcwd())

from stl_container import (
    VectorInt,
    VectorDouble,
    Int2String,
    Int2Double,
)


class TestStlBinders(unittest.TestCase):
John Parent's avatar
John Parent committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    def test_vectorInt(self):
        vi = VectorInt()
        vi.append(1)
        vi.append(2)
        sum_ = 0
        for x in vi:
            sum_ += x
        self.assertEqual(sum_, 3)
        method_list = [
            "pop",
            "remove",
            "insert",
            "extend",
            "count",
            "clear",
            "append",
        ]
        for method in method_list:
            self.assertIn(method, dir(VectorInt))

    def test_VectorDouble(self):
        vd = VectorDouble()
        vd.push_back(1)
        vd.push_back(2)
        self.assertEqual(vd.size(), 2)
        self.assertEqual(vd.at(1), 2)
        vd.assign(10, 1)
        for x in range(10):
            self.assertEqual(vd[x], 1)

    def test_Int2String(self):
        i2s = Int2String()

    def test_Int2Double(self):
        i2d = Int2Double()
        i2d[1] = 2.2
John Parent's avatar
John Parent committed
51
        self.assertEqual(i2d[1], 2.2)
John Parent's avatar
John Parent committed
52

John Parent's avatar
John Parent committed
53
54
55

if __name__ == "__main__":
    unittest.main()