source: branches/numpy/pypar-numeric/mandelbrot_example/test_calculate_point.py @ 6883

Last change on this file since 6883 was 5779, checked in by steve, 16 years ago

Added the old version of pypar which works with Numeric. Necessary for parallel code until we move anuga to numpy (and then we can use pypar as distribute via sourceforge).

File size: 2.1 KB
Line 
1"""
2  Test of calculate_point within mandelbrot.py
3"""
4
5import unittest
6import Numeric
7from mandelbrot import calculate_point
8#from mandel_ext import calculate_point
9
10
11#-------------------------------------------------------------
12
13class TestCase(unittest.TestCase):
14
15    def setUp(self):
16        pass
17
18       
19    def test_basic(self):
20        """Test that c==0 always returns kmax
21        """
22
23        c = complex(0, 0)
24       
25        for kmax in [0,1,2,3,4,10, 20, 33, 45, 100]:
26            count = calculate_point(c, kmax)   
27            assert count == kmax       
28
29           
30    def test_points_clearly_outside_set(self): 
31   
32        for kmax in [1,2,3,5,10,20,100]:
33            for c in [complex(5, 4), complex(2,1), complex(-2,1),
34                      complex(2,-1), complex(-2,-1)]:
35                count = calculate_point(c, kmax)
36                assert count == 1
37       
38               
39    def test_arbitrary_points(self):
40        for kmax in [10,20,100]:           
41            c = complex(1, 1.5)
42            count = calculate_point(c, kmax)
43            assert count == 2   
44           
45            c = complex(-1, 1.5)
46            count = calculate_point(c, kmax)
47            assert count == 2               
48           
49            c = complex(-1, -1.5)
50            count = calculate_point(c, kmax)
51            assert count == 2                       
52           
53            c = complex(1, -1.5)
54            count = calculate_point(c, kmax)
55            assert count == 2                               
56           
57            c = complex(1, 0)
58            count = calculate_point(c, kmax)
59            assert count == 3                                       
60           
61            c = complex(0.2, 1)
62            count = calculate_point(c, kmax)
63            assert count == 4                                               
64           
65            c = complex(0.2, 0.7)
66            count = calculate_point(c, kmax)
67            assert count == 6                                                       
68           
69            c = complex(-0.2, 0.9)
70            count = calculate_point(c, kmax)
71            assert count == 9
72           
73
74    def test_another_known_point(self):
75        c = complex(0.5, 0.5)
76        count = calculate_point(c, 256)
77        assert count == 5       
78
79#-------------------------------------------------------------
80if __name__ == "__main__":
81
82    mysuite = unittest.makeSuite(TestCase,'test')
83    runner = unittest.TextTestRunner()
84    runner.run(mysuite)
Note: See TracBrowser for help on using the repository browser.