source: inundation/pypar_dist/mandelbrot_example/test_calculate_region.py @ 2152

Last change on this file since 2152 was 1852, checked in by ole, 19 years ago

Added prerequisites for mandelbrot_example

File size: 1.8 KB
Line 
1"""
2  Test of calculate_region within mandelbrot.py
3"""
4
5import unittest
6import Numeric
7from mandelbrot import calculate_region
8
9
10#-------------------------------------------------------------
11
12class TestCase(unittest.TestCase):
13
14    def setUp(self):
15        pass
16
17       
18    def test1(self):
19        kmax = 16
20        M = N = 5
21       
22        real_min = -2.0
23        real_max =  1.0
24        imag_min = -1.5
25        imag_max =  1.5
26        A = calculate_region(real_min, real_max, 
27                imag_min, imag_max, kmax, M, N)
28
29        assert Numeric.allclose(A,             
30        [[ 1,  1,  1,  1,  1],
31        [ 1,  3,  5,  5,  3],
32        [ 2,  4,  9,  9,  4],
33        [ 2,  9, 16, 16,  9],
34        [ 2,  3, 15, 15,  3]])
35
36
37    def test2(self):
38        kmax = 32
39        M = N = 5
40       
41        real_min = -2.0
42        real_max =  1.0
43        imag_min = -1.5
44        imag_max =  1.5
45        A = calculate_region(real_min, real_max, 
46                imag_min, imag_max, kmax, M, N)
47
48        assert Numeric.allclose(A,             
49        [[ 1,  1,  1,  1,  1],
50        [ 1,  3,  5,  5,  3],
51        [ 2,  4,  9,  9,  4],
52        [ 2,  9, 32, 32,  9],
53        [ 2,  3, 15, 15,  3]])
54       
55
56    def test3(self):
57        kmax = 32
58        M = N = 100
59       
60        real_min = -2.0
61        real_max =  1.0
62        imag_min = -1.5
63        imag_max =  1.5
64        A = calculate_region(real_min, real_max, 
65                imag_min, imag_max, kmax, M, N)
66
67        assert Numeric.allclose(A[:, 50], 
68        [32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 
69         32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
70         32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 
71         32, 32, 32, 32, 32, 32, 32, 32,
72         32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 
73         32, 32, 32, 32, 32, 32, 32, 32,
74         32, 32, 16, 11,  9,  7,  7,  6,  5,  5,  5,  4,  4,  4,  4,  4, 
75         3, 3,  3,  3,  3,  3,  3,  3, 3,  3])
76
77       
78#-------------------------------------------------------------
79if __name__ == "__main__":
80
81    mysuite = unittest.makeSuite(TestCase,'test')
82    runner = unittest.TextTestRunner()
83    runner.run(mysuite)
Note: See TracBrowser for help on using the repository browser.