Conghao97's picture tcftrees's picture
ProgramGen release
d086025
Raw History Blame Contribute Delete
12.3 kB
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/test_distributions.py b/tests/test_distributions.py
new file mode 100644
--- /dev/null
+++ b/tests/test_distributions.py
@@ -0,0 +1,155 @@
+import unittest
+
+import numpy as np
+
+import evapy_4s.distributions as dist
+
+
+class Test_rayleigh_gen(unittest.TestCase):
+ def setUp(self):
+ self.dist = dist._distns.rayleigh_gen()
+
+ def tearDown(self):
+ pass
+
+ def test_cdf(self):
+ calculated = self.dist.cdf(2.5, loc=0.5, scale=np.sqrt(2.0))
+ expected = -np.expm1(-1.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_pdf(self):
+ calculated = self.dist.pdf(2.5, loc=0.5, scale=np.sqrt(2.0))
+ expected = np.exp(-1.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_ppf(self):
+ calculated = self.dist.ppf(0.5, loc=0.5, scale=np.sqrt(2.0))
+ expected = 2.0 * np.sqrt(np.log(2.0)) + 0.5
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_instance_rayleigh(self):
+ calculated = dist.rayleigh.cdf(2.5, loc=0.5, scale=np.sqrt(2.0))
+ expected = -np.expm1(-1.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+
+class Test_frechet_r_gen(unittest.TestCase):
+ def setUp(self):
+ self.dist = dist._distns.frechet_r_gen()
+
+ def tearDown(self):
+ pass
+
+ def test_cdf(self):
+ calculated = self.dist.cdf(2.5, 2.0, loc=0.5, scale=2.0)
+ expected = -np.expm1(-1.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_pdf(self):
+ calculated = self.dist.pdf(2.5, 2.0, loc=0.5, scale=2.0)
+ expected = np.exp(-1.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_ppf(self):
+ calculated = self.dist.ppf(0.5, 2.0, loc=0.5, scale=2.0)
+ expected = 2.0 * np.sqrt(np.log(2.0)) + 0.5
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_instance_weibull(self):
+ calculated = dist.weibull.cdf(2.5, 2.0, loc=0.5, scale=2.0)
+ expected = self.dist.cdf(2.5, 2.0, loc=0.5, scale=2.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_instance_weibull_min(self):
+ calculated = dist.weibull_min.cdf(2.5, 2.0, loc=0.5, scale=2.0)
+ expected = self.dist.cdf(2.5, 2.0, loc=0.5, scale=2.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+
+class Test_gumbel_r_gen(unittest.TestCase):
+ def setUp(self):
+ self.dist = dist._distns.gumbel_r_gen()
+
+ def tearDown(self):
+ pass
+
+ def test_cdf(self):
+ calculated = self.dist.cdf(3.0, loc=1.0, scale=2.0)
+ expected = np.exp(-np.exp(-1.0))
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_pdf(self):
+ calculated = self.dist.pdf(3.0, loc=1.0, scale=2.0)
+ expected = np.exp(-1.0 - np.exp(-1.0)) / 2.0
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_ppf(self):
+ calculated = self.dist.ppf(0.5, loc=1.0, scale=2.0)
+ expected = 1.0 - 2.0 * np.log(np.log(2))
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_instance_gumbel(self):
+ calculated = dist.gumbel.cdf(2.5, loc=0.5, scale=2.0)
+ expected = self.dist.cdf(2.5, loc=0.5, scale=2.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_instance_gumbel_max(self):
+ calculated = dist.gumbel_max.cdf(2.5, loc=0.5, scale=2.0)
+ expected = self.dist.cdf(2.5, loc=0.5, scale=2.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+
+class Test_gen_exp_tail_gen(unittest.TestCase):
+ def setUp(self):
+ self.dist = dist._distns.gen_exp_tail_gen()
+
+ def tearDown(self):
+ pass
+
+ def test_cdf(self):
+ calculated = self.dist.cdf(2.5, 2.0, 1.0, loc=0.5, scale=2.0)
+ expected = -np.expm1(-1.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_pdf(self):
+ calculated = self.dist.pdf(2.5, 2.0, 1.0, loc=0.5, scale=2.0)
+ expected = np.exp(-1.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_ppf(self):
+ calculated = self.dist.ppf(0.5, 2.0, 1.0, loc=0.5, scale=2.0)
+ expected = 2.0 * np.sqrt(np.log(2.0)) + 0.5
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_instance_gen_exp_tail(self):
+ calculated = dist.genexptail.cdf(2.5, 2.0, 1.0, loc=0.5, scale=2.0)
+ expected = self.dist.cdf(2.5, 2.0, 1.0, loc=0.5, scale=2.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+
+class Test_acer_o1_gen(unittest.TestCase):
+ def setUp(self):
+ self.dist = dist._distns.acer_o1_gen()
+
+ def tearDown(self):
+ pass
+
+ def test_cdf(self):
+ calculated = self.dist.cdf(3.0, 1.0, 1.0, loc=1.0, scale=2.0)
+ expected = np.exp(-np.exp(-1.0))
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_pdf(self):
+ calculated = self.dist.pdf(3.0, 1.0, 1.0, loc=1.0, scale=2.0)
+ expected = np.exp(-1.0 - np.exp(-1.0)) / 2.0
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_ppf(self):
+ calculated = self.dist.ppf(0.5, 1.0, 1.0, loc=1.0, scale=2.0)
+ expected = 1.0 - 2.0 * np.log(np.log(2))
+ self.assertAlmostEqual(calculated, expected, places=4)
+
+ def test_instance_acer_o1(self):
+ calculated = dist.acer_o1.cdf(2.5, 1.0, 1.0, loc=0.5, scale=2.0)
+ expected = self.dist.cdf(2.5, 1.0, 1.0, loc=0.5, scale=2.0)
+ self.assertAlmostEqual(calculated, expected, places=4)
diff --git a/tests/test_evstats.py b/tests/test_evstats.py
new file mode 100644
--- /dev/null
+++ b/tests/test_evstats.py
@@ -0,0 +1,188 @@
+import unittest
+
+import numpy as np
+
+from evapy_4s import evstats
+
+
+class Test__argrelmax(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_simple_find(self):
+ x = np.array([0.0, 1.0, 0.0, -1.0, 0.0, 2.0])
+ calculated = evstats._argrelmax(x)
+ expected = np.array([False, True, False, False, False, False])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_none(self):
+ x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
+ calculated = evstats._argrelmax(x)
+ expected = np.array([False, False, False, False, False, False])
+ np.testing.assert_array_equal(calculated, expected)
+
+
+class Test__argupcross(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_simple_find(self):
+ x = np.array([0.0, 1.0, -1.0, -2.0, -1.0, 1.0, 0.0])
+ calculated = evstats._argupcross(x, x_up=0.0)
+ expected = np.array([True, False, False, False, True, False, False])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_w_zero(self):
+ x = np.array([0.0, 1.0, 0.0, -1.0, -2.0, -1.0, 0.0, 1.0, 0.0])
+ calculated = evstats._argupcross(x, x_up=0.0)
+ expected = np.array(
+ [True, False, False, False, False, False, True, False, False]
+ )
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_w_other(self):
+ x = np.array([0.0, 1.0, 0.0, -1.0, -2.0, -1.0, 0.0, 1.0, 0.0]) + 2.0
+ calculated = evstats._argupcross(x, x_up=2.0)
+ expected = np.array(
+ [True, False, False, False, False, False, True, False, False]
+ )
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_none(self):
+ x = np.array([0.1, 1.0, 2.0, 3.0, 4.0, 5.0])
+ calculated = evstats._argupcross(x, x_up=0.0)
+ expected = np.array([False, False, False, False, False, False])
+ np.testing.assert_array_equal(calculated, expected)
+
+
+class Test_argrelmax(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_simple_find(self):
+ x = np.array([0.0, 1.0, 0.0, -1.0, 0.0, 2.0])
+ calculated = evstats.argrelmax(x)
+ expected = np.array([1])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_repeat(self):
+ x = np.array([0.0, 1.0, 1.0, 0.0, -1.0, 0.0, 2.0])
+ calculated = evstats.argrelmax(x)
+ expected = np.array([1])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_none(self):
+ x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
+ calculated = evstats.argrelmax(x)
+ expected = np.array([5])
+ np.testing.assert_array_equal(calculated, expected)
+
+
+class Test_argupcross(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_simple_find(self):
+ x = np.array([-1.0, 1.0, -1.0, -2.0, -1.0, 1.0, 0.0])
+ calculated = evstats.argupcross(x, x_up=0.0)
+ expected = np.array([0.0, 4])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_w_zero(self):
+ x = np.array([0.0, 1.0, 0.0, -1.0, -2.0, -1.0, 0.0, 1.0, 0.0, 1.0])
+ calculated = evstats.argupcross(x, x_up=0.0)
+ expected = np.array([0, 6, 8])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_touch_below(self):
+ x = np.array([0.0, -1.0, 0.0, -1.0])
+ calculated = evstats.argupcross(x, x_up=0.0)
+ expected = np.array([0])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_w_other(self):
+ x = np.array([0.0, 1.0, 0.0, -1.0, -2.0, -1.0, 0.0, 1.0, 0.0]) + 2.0
+ calculated = evstats.argupcross(x, x_up=2.0)
+ expected = np.array([0.0, 6.0])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_none(self):
+ x = np.array([0.1, 1.0, 2.0, 3.0, 4.0, 5.0])
+ calculated = evstats.argupcross(x, x_up=0.0)
+ expected = np.array([0.0])
+ np.testing.assert_array_equal(calculated, expected)
+
+
+class Test_argrelmax_decluster(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_simple_find(self):
+ x = np.array([0.0, 1.0, 0.0, -1.0, 0.0, 2.0])
+ calculated = evstats.argrelmax_decluster(x, x_up=0.0)
+ expected = np.array([1])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_2(self):
+ x = np.array([0.0, 1.0, 0.0, -1.0, 0.0, 2.0, 1.0, -1.0, 1.0])
+ calculated = evstats.argrelmax_decluster(x, x_up=0.0)
+ expected = np.array([1, 5])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_decluster(self):
+ x = np.array([0.0, 1.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0, 0.0, 2.0, -1.0, 1.0])
+ calculated = evstats.argrelmax_decluster(x, x_up=0.0)
+ expected = np.array([5, 9])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_simple_find_none(self):
+ x = np.array([0.1, 1.0, 2.0, 3.0, 4.0, 5.0])
+ calculated = evstats.argrelmax_decluster(x)
+ expected = np.array([5])
+ np.testing.assert_array_equal(calculated, expected)
+
+ def test_find_decluster_below_upcross(self):
+ x = np.array(
+ [
+ 0.0,
+ 1.0,
+ 2.0,
+ 1.0,
+ 2.0,
+ 3.0,
+ 2.0,
+ 1.0,
+ 0.0,
+ -1.0,
+ -2.0,
+ -1,
+ -2,
+ -1,
+ 0.0,
+ 1,
+ 0.0,
+ -1.0,
+ -2.0,
+ -1.0,
+ 0.0,
+ 1.0,
+ ]
+ )
+ calculated = evstats.argrelmax_decluster(x, x_up=0.0)
+ expected = np.array([5, 15.0])
+ np.testing.assert_array_equal(calculated, expected)