Coverage for tests/test_utils.py: 26%

53 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-25 01:13 -0700

1#!/usr/bin/env python 

2 

3# 

4# LSST Data Management System 

5# 

6# Copyright 2008-2017 AURA/LSST. 

7# 

8# This product includes software developed by the 

9# LSST Project (http://www.lsst.org/). 

10# 

11# This program is free software: you can redistribute it and/or modify 

12# it under the terms of the GNU General Public License as published by 

13# the Free Software Foundation, either version 3 of the License, or 

14# (at your option) any later version. 

15# 

16# This program is distributed in the hope that it will be useful, 

17# but WITHOUT ANY WARRANTY; without even the implied warranty of 

18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

19# GNU General Public License for more details. 

20# 

21# You should have received a copy of the LSST License Statement and 

22# the GNU General Public License along with this program. If not, 

23# see <https://www.lsstcorp.org/LegalNotices/>. 

24# 

25"""Test cases for atmospec.""" 

26 

27import unittest 

28import itertools 

29import numpy as np 

30 

31import lsst.utils 

32import lsst.utils.tests 

33from lsst.atmospec.utils import argMaxNd, getSamplePoints 

34 

35 

36class AtmospecUtilsTestCase(lsst.utils.tests.TestCase): 

37 """A test case for atmospec.""" 

38 

39 def testImport(self): 

40 import lsst.atmospec.utils as utils # noqa: F401 

41 

42 def test_argMaxNd(self): 

43 data = np.ones((10, 10)) 

44 

45 data[2, 3] = 100 

46 data[1, 2] = -200 

47 maxLocation = argMaxNd(data) 

48 self.assertTrue(maxLocation == (2, 3)) 

49 

50 data3d = np.ones((10, 20, 15)) 

51 data3d[3, 4, 5] = 2 

52 data3d[1, 2, 3] = -10 

53 maxLocation3d = argMaxNd(data3d) 

54 self.assertTrue(maxLocation3d == (3, 4, 5)) 

55 

56 def test_getSamplePoints(self): 

57 points = getSamplePoints(0, 100, 3, includeEndpoints=False, integers=False) 

58 self.assertEqual(points, [16.666666666666668, 50.0, 83.33333333333334]) 

59 

60 points = getSamplePoints(0, 100, 3, includeEndpoints=False, integers=True) 

61 self.assertEqual(points, [17, 50, 83]) 

62 

63 points = getSamplePoints(0, 100, 3, includeEndpoints=True, integers=False) 

64 self.assertEqual(points, [0, 50, 100]) 

65 

66 points = getSamplePoints(0, 100, 4, includeEndpoints=True, integers=False) 

67 self.assertEqual(points, [0, 33.333333333333336, 66.66666666666667, 100.0]) 

68 

69 points = getSamplePoints(0, 100, 4, includeEndpoints=False, integers=False) 

70 self.assertEqual(points, [12.5, 37.5, 62.5, 87.5]) 

71 

72 points = getSamplePoints(0, 100, 5, includeEndpoints=False, integers=False) 

73 self.assertEqual(points, [10.0, 30.0, 50.0, 70.0, 90.0]) 

74 

75 points = getSamplePoints(0, 100, 5, includeEndpoints=True, integers=False) 

76 self.assertEqual(points, [0, 25.0, 50.0, 75.0, 100.0]) 

77 

78 points = getSamplePoints(0, 100.1, 5, includeEndpoints=True, integers=False) 

79 self.assertEqual(points[-1], 100.1) 

80 

81 points = getSamplePoints(0, 100.1, 5, includeEndpoints=True, integers=True) 

82 self.assertNotEqual(points[-1], 100.1) 

83 

84 for ints in (True, False): 

85 with self.assertRaises(RuntimeError): 

86 getSamplePoints(0, 100, 1, includeEndpoints=True, integers=ints) 

87 

88 for start, end in itertools.product((-1.5, -1, 0, 2.3), (0, 3.14, -1e9)): 

89 points = getSamplePoints(start, end, 2, includeEndpoints=True, integers=False) 

90 self.assertEqual(points, [start, end]) 

91 

92 

93class TestMemory(lsst.utils.tests.MemoryTestCase): 

94 pass 

95 

96 

97def setup_module(module): 

98 lsst.utils.tests.init() 

99 

100 

101if __name__ == "__main__": 101 ↛ 102line 101 didn't jump to line 102, because the condition on line 101 was never true

102 lsst.utils.tests.init() 

103 unittest.main()