|
26 | 26 | from climada.entity.impact_funcs.base import ImpactFunc |
27 | 27 |
|
28 | 28 |
|
| 29 | +class TestEquality(unittest.TestCase): |
| 30 | + """Test equality method""" |
| 31 | + |
| 32 | + def setUp(self): |
| 33 | + self.impf1 = ImpactFunc( |
| 34 | + haz_type="TC", |
| 35 | + id=1, |
| 36 | + intensity=np.array([1, 2, 3]), |
| 37 | + mdd=np.array([0.1, 0.2, 0.3]), |
| 38 | + paa=np.array([0.4, 0.5, 0.6]), |
| 39 | + intensity_unit="m/s", |
| 40 | + name="Test Impact", |
| 41 | + ) |
| 42 | + self.impf2 = ImpactFunc( |
| 43 | + haz_type="TC", |
| 44 | + id=1, |
| 45 | + intensity=np.array([1, 2, 3]), |
| 46 | + mdd=np.array([0.1, 0.2, 0.3]), |
| 47 | + paa=np.array([0.4, 0.5, 0.6]), |
| 48 | + intensity_unit="m/s", |
| 49 | + name="Test Impact", |
| 50 | + ) |
| 51 | + self.impf3 = ImpactFunc( |
| 52 | + haz_type="FL", |
| 53 | + id=2, |
| 54 | + intensity=np.array([4, 5, 6]), |
| 55 | + mdd=np.array([0.7, 0.8, 0.9]), |
| 56 | + paa=np.array([0.1, 0.2, 0.3]), |
| 57 | + intensity_unit="m", |
| 58 | + name="Another Impact", |
| 59 | + ) |
| 60 | + |
| 61 | + def test_reflexivity(self): |
| 62 | + self.assertEqual(self.impf1, self.impf1) |
| 63 | + |
| 64 | + def test_symmetry(self): |
| 65 | + self.assertEqual(self.impf1, self.impf2) |
| 66 | + self.assertEqual(self.impf2, self.impf1) |
| 67 | + |
| 68 | + def test_transitivity(self): |
| 69 | + impf4 = ImpactFunc( |
| 70 | + haz_type="TC", |
| 71 | + id=1, |
| 72 | + intensity=np.array([1, 2, 3]), |
| 73 | + mdd=np.array([0.1, 0.2, 0.3]), |
| 74 | + paa=np.array([0.4, 0.5, 0.6]), |
| 75 | + intensity_unit="m/s", |
| 76 | + name="Test Impact", |
| 77 | + ) |
| 78 | + self.assertEqual(self.impf1, self.impf2) |
| 79 | + self.assertEqual(self.impf2, impf4) |
| 80 | + self.assertEqual(self.impf1, impf4) |
| 81 | + |
| 82 | + def test_consistency(self): |
| 83 | + self.assertEqual(self.impf1, self.impf2) |
| 84 | + self.assertEqual(self.impf1, self.impf2) |
| 85 | + |
| 86 | + def test_comparison_with_none(self): |
| 87 | + self.assertNotEqual(self.impf1, None) |
| 88 | + |
| 89 | + def test_different_types(self): |
| 90 | + self.assertNotEqual(self.impf1, "Not an ImpactFunc") |
| 91 | + |
| 92 | + def test_inequality(self): |
| 93 | + self.assertNotEqual(self.impf1, self.impf3) |
| 94 | + self.assertTrue(self.impf1 != self.impf3) |
| 95 | + |
| 96 | + |
29 | 97 | class TestInterpolation(unittest.TestCase): |
30 | 98 | """Impact function interpolation test""" |
31 | 99 |
|
@@ -139,5 +207,8 @@ def test_aux_vars(impf): |
139 | 207 |
|
140 | 208 | # Execute Tests |
141 | 209 | if __name__ == "__main__": |
142 | | - TESTS = unittest.TestLoader().loadTestsFromTestCase(TestInterpolation) |
143 | | - unittest.TextTestRunner(verbosity=2).run(TESTS) |
| 210 | + equality_tests = unittest.TestLoader().loadTestsFromTestCase(TestEquality) |
| 211 | + interpolation_tests = unittest.TestLoader().loadTestsFromTestCase(TestInterpolation) |
| 212 | + unittest.TextTestRunner(verbosity=2).run( |
| 213 | + unittest.TestSuite([equality_tests, interpolation_tests]) |
| 214 | + ) |
0 commit comments