Coverage for tests/test_Mq3cPixelization.py: 22%
71 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 02:22 -0700
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 02:22 -0700
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
24try:
25 import yaml
26except ImportError:
27 yaml = None
29import unittest
31from lsst.sphgeom import (Angle, Circle, Mq3cPixelization, RangeSet,
32 UnitVector3d)
35class Mq3cPixelizationTestCase(unittest.TestCase):
37 def test_construction(self):
38 with self.assertRaises(ValueError):
39 Mq3cPixelization(-1)
40 with self.assertRaises(ValueError):
41 Mq3cPixelization(Mq3cPixelization.MAX_LEVEL + 1)
42 m1 = Mq3cPixelization(0)
43 self.assertEqual(m1.getLevel(), 0)
44 m2 = Mq3cPixelization(1)
45 m3 = Mq3cPixelization(m2)
46 self.assertNotEqual(m1, m2)
47 self.assertEqual(m2, m3)
49 def test_indexing(self):
50 pixelization = Mq3cPixelization(1)
51 self.assertEqual(pixelization.index(UnitVector3d(0.5, -0.5, 1.0)), 53)
53 def test_level(self):
54 self.assertEqual(Mq3cPixelization.level(0), -1)
55 for level in range(Mq3cPixelization.MAX_LEVEL + 1):
56 for root in range(8, 10):
57 index = root * 4**level
58 self.assertEqual(Mq3cPixelization.level(index), -1)
59 for root in range(10, 16):
60 index = root * 4**level
61 self.assertEqual(Mq3cPixelization.level(index), level)
63 def test_envelope_and_interior(self):
64 pixelization = Mq3cPixelization(1)
65 c = Circle(UnitVector3d(1.0, -0.5, -0.5), Angle.fromDegrees(0.1))
66 rs = pixelization.envelope(c)
67 self.assertTrue(rs == RangeSet(44))
68 rs = pixelization.envelope(c, 1)
69 self.assertTrue(rs == RangeSet(44))
70 self.assertTrue(rs.isWithin(pixelization.universe()))
71 rs = pixelization.interior(c)
72 self.assertTrue(rs.empty())
74 def test_index_to_string(self):
75 strings = ['+X', '+Y', '+Z', '-X', '-Y', '-Z']
76 for i in range(6):
77 s0 = strings[i]
78 components = [0.0]*3
79 components[i % 3] = 1.0 if i < 3 else -1.0
80 v = UnitVector3d(*components)
81 f = Mq3cPixelization(0).index(v)
82 self.assertEqual(Mq3cPixelization.asString(f), s0)
83 self.assertEqual(Mq3cPixelization(0).toString(f), s0)
84 for j in range(4):
85 s1 = s0 + str(j)
86 self.assertEqual(Mq3cPixelization.asString(f*4 + j), s1)
87 self.assertEqual(Mq3cPixelization(1).toString(f*4 + j), s1)
89 def test_string(self):
90 p = Mq3cPixelization(3)
91 self.assertEqual(str(p), 'Mq3cPixelization(3)')
92 self.assertEqual(str(p), repr(p))
93 self.assertEqual(
94 p, eval(repr(p), dict(Mq3cPixelization=Mq3cPixelization)))
96 def test_pickle(self):
97 a = Mq3cPixelization(20)
98 b = pickle.loads(pickle.dumps(a))
99 self.assertEqual(a, b)
101 @unittest.skipIf(not yaml, "YAML module can not be imported")
102 def test_yaml(self):
103 a = Mq3cPixelization(20)
104 b = yaml.safe_load(yaml.dump(a))
105 self.assertEqual(a, b)
108if __name__ == '__main__': 108 ↛ 109line 108 didn't jump to line 109, because the condition on line 108 was never true
109 unittest.main()