source: trunk/misc/tools/pytools/test_pytools.py @ 8813

Last change on this file since 8813 was 7276, checked in by ole, 15 years ago

Merged numpy branch back into the trunk.

In ~/sandpit/anuga/anuga_core/source
svn merge -r 6246:HEAD ../../branches/numpy .

In ~/sandpit/anuga/anuga_validation
svn merge -r 6417:HEAD ../branches/numpy_anuga_validation .

In ~/sandpit/anuga/misc
svn merge -r 6809:HEAD ../branches/numpy_misc .

For all merges, I used numpy version where conflicts existed

The suites test_all.py (in source/anuga) and validate_all.py passed using Python2.5 with numpy on my Ubuntu Linux box.

File size: 1.8 KB
Line 
1import unittest
2import numpy as num
3from combinatorics import bitvector
4from numtools import expand
5
6#-------------------------------------------------------------
7
8class TestCase(unittest.TestCase):
9
10    def setUp(self):
11        pass
12
13    def test_bitvector(self):
14
15        d = 4
16        assert num.allclose(bitvector(0, d), num.array([0,0,0,0]))
17        assert num.allclose(bitvector(1, d), num.array([1,0,0,0]))
18        assert num.allclose(bitvector(2, d), num.array([0,1,0,0]))
19        assert num.allclose(bitvector(3, d), num.array([1,1,0,0]))
20        assert num.allclose(bitvector(4, d), num.array([0,0,1,0]))
21        assert num.allclose(bitvector(5, d), num.array([1,0,1,0]))
22        assert num.allclose(bitvector(6, d), num.array([0,1,1,0]))
23        assert num.allclose(bitvector(7, d), num.array([1,1,1,0]))
24        assert num.allclose(bitvector(8, d), num.array([0,0,0,1]))
25        assert num.allclose(bitvector(9, d), num.array([1,0,0,1]))
26        assert num.allclose(bitvector(10, d), num.array([0,1,0,1]))
27        assert num.allclose(bitvector(11, d), num.array([1,1,0,1]))
28        assert num.allclose(bitvector(12, d), num.array([0,0,1,1]))
29        assert num.allclose(bitvector(13, d), num.array([1,0,1,1]))
30        assert num.allclose(bitvector(14, d), num.array([0,1,1,1]))
31        assert num.allclose(bitvector(15, d), num.array([1,1,1,1]))
32       
33
34    def test_expand(self):
35
36        d = 4
37        mask = num.array([0,1,1,0,1])
38        v = num.array([2,3,4])
39
40        assert num.allclose(expand(v, mask), num.array([0,2,3,0,4]))
41
42
43       
44           
45                         
46#-------------------------------------------------------------
47if __name__ == "__main__":
48
49    mysuite = unittest.makeSuite(TestCase,'test')
50    runner = unittest.TextTestRunner()
51    runner.run(mysuite)
52
Note: See TracBrowser for help on using the repository browser.