Coverage for tests/test_Mq3cPixelization.py : 18%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# LSST Data Management System
3# See COPYRIGHT file at the top of the source tree.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <https://www.lsstcorp.org/LegalNotices/>.
21#
23import pickle
24import unittest
26from lsst.sphgeom import (Angle, Circle, Mq3cPixelization, RangeSet,
27 UnitVector3d)
30class Mq3cPixelizationTestCase(unittest.TestCase):
32 def test_construction(self):
33 with self.assertRaises(ValueError):
34 Mq3cPixelization(-1)
35 with self.assertRaises(ValueError):
36 Mq3cPixelization(Mq3cPixelization.MAX_LEVEL + 1)
37 m1 = Mq3cPixelization(0)
38 self.assertEqual(m1.getLevel(), 0)
39 m2 = Mq3cPixelization(1)
40 m3 = Mq3cPixelization(m2)
41 self.assertNotEqual(m1, m2)
42 self.assertEqual(m2, m3)
44 def test_indexing(self):
45 pixelization = Mq3cPixelization(1)
46 self.assertEqual(pixelization.index(UnitVector3d(0.5, -0.5, 1.0)), 53)
48 def test_level(self):
49 self.assertEqual(Mq3cPixelization.level(0), -1)
50 for level in range(Mq3cPixelization.MAX_LEVEL + 1):
51 for root in range(8, 10):
52 index = root * 4**level
53 self.assertEqual(Mq3cPixelization.level(index), -1)
54 for root in range(10, 16):
55 index = root * 4**level
56 self.assertEqual(Mq3cPixelization.level(index), level)
58 def test_envelope_and_interior(self):
59 pixelization = Mq3cPixelization(1)
60 c = Circle(UnitVector3d(1.0, -0.5, -0.5), Angle.fromDegrees(0.1))
61 rs = pixelization.envelope(c)
62 self.assertTrue(rs == RangeSet(44))
63 rs = pixelization.envelope(c, 1)
64 self.assertTrue(rs == RangeSet(44))
65 self.assertTrue(rs.isWithin(pixelization.universe()))
66 rs = pixelization.interior(c)
67 self.assertTrue(rs.empty())
69 def test_index_to_string(self):
70 strings = ['+X', '+Y', '+Z', '-X', '-Y', '-Z']
71 for i in range(6):
72 s0 = strings[i]
73 components = [0.0]*3
74 components[i % 3] = 1.0 if i < 3 else -1.0
75 v = UnitVector3d(*components)
76 f = Mq3cPixelization(0).index(v)
77 self.assertEqual(Mq3cPixelization.asString(f), s0)
78 self.assertEqual(Mq3cPixelization(0).toString(f), s0)
79 for j in range(4):
80 s1 = s0 + str(j)
81 self.assertEqual(Mq3cPixelization.asString(f*4 + j), s1)
82 self.assertEqual(Mq3cPixelization(1).toString(f*4 + j), s1)
84 def test_string(self):
85 p = Mq3cPixelization(3)
86 self.assertEqual(str(p), 'Mq3cPixelization(3)')
87 self.assertEqual(str(p), repr(p))
88 self.assertEqual(
89 p, eval(repr(p), dict(Mq3cPixelization=Mq3cPixelization)))
91 def test_pickle(self):
92 a = Mq3cPixelization(20)
93 b = pickle.loads(pickle.dumps(a))
94 self.assertEqual(a, b)
97if __name__ == '__main__': 97 ↛ 98line 97 didn't jump to line 98, because the condition on line 97 was never true
98 unittest.main()