Commit 61e1268f662560fe2dc4b1b06b75396db606aa5d
1 parent
ef84d7cb
Add xspec module test.
Showing
2 changed files
with
131 additions
and
9 deletions
test/test_GXspec.py
0 → 100755
| 1 | +# ========================================================================== | |
| 2 | +# This module performs unit tests for the GammaLib xspec module. | |
| 3 | +# | |
| 4 | +# Copyright (C) 2013 Juergen Knoedlseder | |
| 5 | +# | |
| 6 | +# This program is free software: you can redistribute it and/or modify | |
| 7 | +# it under the terms of the GNU General Public License as published by | |
| 8 | +# the Free Software Foundation, either version 3 of the License, or | |
| 9 | +# (at your option) any later version. | |
| 10 | +# | |
| 11 | +# This program is distributed in the hope that it will be useful, | |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | +# GNU General Public License for more details. | |
| 15 | +# | |
| 16 | +# You should have received a copy of the GNU General Public License | |
| 17 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 18 | +# | |
| 19 | +# ========================================================================== | |
| 20 | +from gammalib import * | |
| 21 | +from math import * | |
| 22 | +import os | |
| 23 | + | |
| 24 | + | |
| 25 | +# ==================================== # | |
| 26 | +# Test class for GammaLib xspec module # | |
| 27 | +# ==================================== # | |
| 28 | +class Test(GPythonTestSuite): | |
| 29 | + """ | |
| 30 | + Test class for GammaLib xspec module. | |
| 31 | + """ | |
| 32 | + # Constructor | |
| 33 | + def __init__(self): | |
| 34 | + """ | |
| 35 | + Constructor. | |
| 36 | + """ | |
| 37 | + # Call base class constructor | |
| 38 | + GPythonTestSuite.__init__(self) | |
| 39 | + | |
| 40 | + # Return | |
| 41 | + return | |
| 42 | + | |
| 43 | + # Set test functions | |
| 44 | + def set(self): | |
| 45 | + """ | |
| 46 | + Set all test functions. | |
| 47 | + """ | |
| 48 | + # Set test name | |
| 49 | + self.name("xspec") | |
| 50 | + | |
| 51 | + # Append tests | |
| 52 | + self.append(self.test_pha, "Test GPha") | |
| 53 | + self.append(self.test_arf, "Test GArf") | |
| 54 | + self.append(self.test_rmf, "Test GRmf") | |
| 55 | + | |
| 56 | + # Return | |
| 57 | + return | |
| 58 | + | |
| 59 | + # Test GPha class | |
| 60 | + def test_pha(self): | |
| 61 | + """ | |
| 62 | + Test GPha class. | |
| 63 | + """ | |
| 64 | + # Allocate GPha object and check its size | |
| 65 | + nmeasured = 10 | |
| 66 | + emeasured = GEbounds(nmeasured, GEnergy(1.0, "TeV"), GEnergy(10.0, "TeV")) | |
| 67 | + pha = GPha(emeasured) | |
| 68 | + self.test_value(pha.size(), nmeasured) | |
| 69 | + | |
| 70 | + # Set and retrieve a value | |
| 71 | + value = 3.7 | |
| 72 | + pha[3] = value | |
| 73 | + self.test_value(pha[3], value) | |
| 74 | + | |
| 75 | + # Return | |
| 76 | + return | |
| 77 | + | |
| 78 | + # Test GArf class | |
| 79 | + def test_arf(self): | |
| 80 | + """ | |
| 81 | + Test GArf class. | |
| 82 | + """ | |
| 83 | + # Allocate GArf object and check its size | |
| 84 | + nmeasured = 10 | |
| 85 | + emeasured = GEbounds(nmeasured, GEnergy(1.0, "TeV"), GEnergy(10.0, "TeV")) | |
| 86 | + arf = GArf(emeasured) | |
| 87 | + self.test_value(arf.size(), nmeasured) | |
| 88 | + | |
| 89 | + # Set and retrieve a value | |
| 90 | + value = 3.7 | |
| 91 | + arf[3] = value | |
| 92 | + self.test_value(arf[3], value) | |
| 93 | + | |
| 94 | + # Return | |
| 95 | + return | |
| 96 | + | |
| 97 | + # Test GRmf class | |
| 98 | + def test_rmf(self): | |
| 99 | + """ | |
| 100 | + Test GRmf class. | |
| 101 | + """ | |
| 102 | + # Allocate GRmf object and check its size | |
| 103 | + ntrue = 20 | |
| 104 | + nmeasured = 10 | |
| 105 | + etrue = GEbounds(ntrue, GEnergy(1.0, "TeV"), GEnergy(10.0, "TeV")) | |
| 106 | + emeasured = GEbounds(nmeasured, GEnergy(1.0, "TeV"), GEnergy(10.0, "TeV")) | |
| 107 | + rmf = GRmf(etrue, emeasured) | |
| 108 | + self.test_value(rmf.size(), ntrue*nmeasured) | |
| 109 | + self.test_value(rmf.ntrue(), ntrue) | |
| 110 | + self.test_value(rmf.nmeasured(), nmeasured) | |
| 111 | + | |
| 112 | + # Set and retrieve a value | |
| 113 | + value = 3.7 | |
| 114 | + rmf[3,5] = value | |
| 115 | + self.test_value(rmf[3,5], value) | |
| 116 | + | |
| 117 | + # Return | |
| 118 | + return | ... | ... |
test/test_python.py
| ... | ... | @@ -32,6 +32,7 @@ import test_GSky |
| 32 | 32 | import test_GSupport |
| 33 | 33 | import test_GTest |
| 34 | 34 | import test_GXml |
| 35 | +import test_GXspec | |
| 35 | 36 | |
| 36 | 37 | # Try importing MWL tests |
| 37 | 38 | try: |
| ... | ... | @@ -73,17 +74,18 @@ if __name__ == '__main__': |
| 73 | 74 | suites = GTestSuites("Python interface testing") |
| 74 | 75 | |
| 75 | 76 | # Allocate test suites and append them to the container |
| 76 | - suite1 = test_GApplication.Test() | |
| 77 | - suite2 = test_GFits.Test() | |
| 78 | - suite3 = test_GLinalg.Test() | |
| 79 | - suite4 = test_GModel.Test() | |
| 80 | - suite5 = test_GNumerics.Test() | |
| 81 | - suite6 = test_GObservation.Test() | |
| 82 | - suite7 = test_GOptimizer.Test() | |
| 83 | - suite8 = test_GSky.Test() | |
| 84 | - suite9 = test_GSupport.Test() | |
| 77 | + suite1 = test_GApplication.Test() | |
| 78 | + suite2 = test_GFits.Test() | |
| 79 | + suite3 = test_GLinalg.Test() | |
| 80 | + suite4 = test_GModel.Test() | |
| 81 | + suite5 = test_GNumerics.Test() | |
| 82 | + suite6 = test_GObservation.Test() | |
| 83 | + suite7 = test_GOptimizer.Test() | |
| 84 | + suite8 = test_GSky.Test() | |
| 85 | + suite9 = test_GSupport.Test() | |
| 85 | 86 | suite10 = test_GTest.Test() |
| 86 | 87 | suite11 = test_GXml.Test() |
| 88 | + suite12 = test_GXspec.Test() | |
| 87 | 89 | |
| 88 | 90 | # Setup unit tests |
| 89 | 91 | suite1.set() |
| ... | ... | @@ -97,6 +99,7 @@ if __name__ == '__main__': |
| 97 | 99 | suite9.set() |
| 98 | 100 | suite10.set() |
| 99 | 101 | suite11.set() |
| 102 | + suite12.set() | |
| 100 | 103 | |
| 101 | 104 | # Append tests to container |
| 102 | 105 | suites.append(suite1) |
| ... | ... | @@ -110,6 +113,7 @@ if __name__ == '__main__': |
| 110 | 113 | suites.append(suite9) |
| 111 | 114 | suites.append(suite10) |
| 112 | 115 | suites.append(suite11) |
| 116 | + suites.append(suite12) | |
| 113 | 117 | |
| 114 | 118 | # Optionally handle MWL suite |
| 115 | 119 | if has_mwl: | ... | ... |