From 92af48d754b11c44efb913f2b890245892c24d75 Mon Sep 17 00:00:00 2001 From: physsi07 Date: Mon, 7 Oct 2019 00:10:27 -0400 Subject: [PATCH 1/9] Issue #82: Preparing to test the functions, reading docs --- .gitignore | 3 ++- geodepy/tests/test_statistics.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 geodepy/tests/test_statistics.py diff --git a/.gitignore b/.gitignore index 3a7f4c6..c316c15 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +env .idea __pycache__ @@ -12,4 +13,4 @@ __pycache__ # Ignore test-related files /coverage.data -/coverage/ \ No newline at end of file +/coverage/ diff --git a/geodepy/tests/test_statistics.py b/geodepy/tests/test_statistics.py new file mode 100644 index 0000000..082dda4 --- /dev/null +++ b/geodepy/tests/test_statistics.py @@ -0,0 +1,22 @@ +def test_rotation_matrix(): + pass + + +def test_vcv_cart2local(): + pass + + +def test_vcv_local2cart2(): + pass + + +def test_error_ellipse(): + pass + + +def test_circ_hz_pu(): + pass + + +def test_k_val95(): + pass From 5325f40df56e36d1800aa8682532a94920bf6489 Mon Sep 17 00:00:00 2001 From: physsi07 Date: Tue, 8 Oct 2019 21:18:10 -0400 Subject: [PATCH 2/9] issue #82: Test for rotation_matrix() --- .gitignore | 4 +++ geodepy/tests/test_statistics.py | 50 ++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index c316c15..293ef77 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,7 @@ __pycache__ # Ignore test-related files /coverage.data /coverage/ +.coverage +htmlcov/ +.vscode + diff --git a/geodepy/tests/test_statistics.py b/geodepy/tests/test_statistics.py index 082dda4..eb52fcd 100644 --- a/geodepy/tests/test_statistics.py +++ b/geodepy/tests/test_statistics.py @@ -1,22 +1,48 @@ -def test_rotation_matrix(): - pass +import sys +sys.path.append("../geodepy") +import unittest +from geodepy import statistics +from geodepy.statistics import np +from math import radians, sin, cos, sqrt, atan2, degrees -def test_vcv_cart2local(): - pass +class TestStatistics(unittest.TestCase): + def test_rotation_matrix(self): + + lat = 19.4792 + lon = 70.6931 -def test_vcv_local2cart2(): - pass + expected_result = np.array([ + [-0.94376114, -0.11025276, 0.31170376], + [0.33062805, -0.31471096, 0.88974272], + [0.0 , 0.94276261, 0.33346463] + ]) + + result = statistics.rotation_matrix(lat, lon) + + np.array_equal(result, expected_result) + self.assertEqual(type(result), np.ndarray) -def test_error_ellipse(): - pass + def test_vcv_cart2local(self): + pass -def test_circ_hz_pu(): - pass + def test_vcv_local2cart2(self): + pass -def test_k_val95(): - pass + def test_error_ellipse(self): + pass + + + def test_circ_hz_pu(self): + pass + + + def test_k_val95(self): + pass + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 5c473b2a8c49927bc6525b82ce70d15223a34227 Mon Sep 17 00:00:00 2001 From: physsi07 Date: Wed, 9 Oct 2019 02:26:07 -0400 Subject: [PATCH 3/9] issue #82: Test for vcv_cart2local() & vcv_local2cart() --- geodepy/statistics.py | 2 + geodepy/tests/test_statistics.py | 77 +++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/geodepy/statistics.py b/geodepy/statistics.py index 81c2b6d..469a19e 100644 --- a/geodepy/statistics.py +++ b/geodepy/statistics.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import sys +sys.path.append('./env/lib/python3.7/site-packages') from math import radians, sin, cos, sqrt, atan2, degrees import numpy as np diff --git a/geodepy/tests/test_statistics.py b/geodepy/tests/test_statistics.py index eb52fcd..7b93028 100644 --- a/geodepy/tests/test_statistics.py +++ b/geodepy/tests/test_statistics.py @@ -21,12 +21,78 @@ def test_rotation_matrix(self): result = statistics.rotation_matrix(lat, lon) - np.array_equal(result, expected_result) - self.assertEqual(type(result), np.ndarray) + np.array_equal(expected_result, result) + self.assertEqual(type(expected_result), type(result)) - def test_vcv_cart2local(self): - pass + def test_vcv_cart2local_3X3(self): + + lat = 19.4792 + lon = 70.6931 + v_cart = np.array([ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0] + ]) + + expected_result = np.array([ + [ 0.10931491, -0.10405227, 0.2941739 ], + [-0.10405227, 1.87664567, 0.34874419], + [ 0.2941739, 0.34874419, 1.01403942] + ]) + + result = statistics.vcv_cart2local(v_cart, lat, lon) + + np.array_equal(expected_result, result) + self.assertEqual(type(expected_result), type(result)) + + def test_vcv_cart2local_3X2(self): + + lat = 0.0 + lon = 0.0 + v_cart = np.array([ + [0.0, 0.0], + [0.0, 0.0], + [0.0, 0.0] + ]) + + with self.assertRaises(SystemExit): + statistics.vcv_cart2local(v_cart, lat, lon) + + + def test_vcv_cart2local_2X3(self): + + lat = 0.0 + lon = 0.0 + v_cart = np.array([ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ]) + + with self.assertRaises(SystemExit): + statistics.vcv_cart2local(v_cart, lat, lon) + + + def test_vcv_cart2local_1X3(self): + + lat = 0.0 + lon = 0.0 + v_cart = np.array([ + [0.0], + [0.0], + [0.0] + ]) + + expected_result = np.array([ + [0.0, 0.0, 0.0,], + [0.0, 0.0, 0.0,], + [0.0, 0.0, 0.0,] + ]) + + result = statistics.vcv_cart2local(v_cart, lat, lon) + + np.array_equal(expected_result, result) + self.assertEqual(type(expected_result), type(result)) def test_vcv_local2cart2(self): @@ -44,5 +110,6 @@ def test_circ_hz_pu(self): def test_k_val95(self): pass + if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() From c00a8951145c13bb0952a4f61042abda88305073 Mon Sep 17 00:00:00 2001 From: physsi07 Date: Wed, 9 Oct 2019 02:44:12 -0400 Subject: [PATCH 4/9] issue #82: removing bad code commit --- geodepy/statistics.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/geodepy/statistics.py b/geodepy/statistics.py index 469a19e..81c2b6d 100644 --- a/geodepy/statistics.py +++ b/geodepy/statistics.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -import sys -sys.path.append('./env/lib/python3.7/site-packages') from math import radians, sin, cos, sqrt, atan2, degrees import numpy as np From f50682eb759af0ee34cbe0a83d6104c31af1de9d Mon Sep 17 00:00:00 2001 From: physsi07 Date: Wed, 9 Oct 2019 02:50:26 -0400 Subject: [PATCH 5/9] issue #82: health check --- .gitignore | 2 +- geodepy/statistics.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 293ef77..891e1db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -env .idea __pycache__ @@ -17,4 +16,5 @@ __pycache__ .coverage htmlcov/ .vscode +env diff --git a/geodepy/statistics.py b/geodepy/statistics.py index 81c2b6d..469a19e 100644 --- a/geodepy/statistics.py +++ b/geodepy/statistics.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import sys +sys.path.append('./env/lib/python3.7/site-packages') from math import radians, sin, cos, sqrt, atan2, degrees import numpy as np From e1c1f591216f6cba90b10798c4b8818a7438c954 Mon Sep 17 00:00:00 2001 From: physsi07 Date: Wed, 9 Oct 2019 18:03:44 -0400 Subject: [PATCH 6/9] Issue #82: finished tests for all the methods --- geodepy/tests/test_statistics.py | 128 ++++++++++++++++++++----------- 1 file changed, 83 insertions(+), 45 deletions(-) diff --git a/geodepy/tests/test_statistics.py b/geodepy/tests/test_statistics.py index 7b93028..1c280d5 100644 --- a/geodepy/tests/test_statistics.py +++ b/geodepy/tests/test_statistics.py @@ -4,64 +4,62 @@ import unittest from geodepy import statistics from geodepy.statistics import np -from math import radians, sin, cos, sqrt, atan2, degrees class TestStatistics(unittest.TestCase): def test_rotation_matrix(self): - lat = 19.4792 - lon = 70.6931 + lon = 70.6931 expected_result = np.array([ [-0.94376114, -0.11025276, 0.31170376], [0.33062805, -0.31471096, 0.88974272], - [0.0 , 0.94276261, 0.33346463] + [0.0, 0.94276261, 0.33346463], ]) - - result = statistics.rotation_matrix(lat, lon) - + + result = statistics.rotation_matrix(lat, lon) + np.array_equal(expected_result, result) self.assertEqual(type(expected_result), type(result)) - - def test_vcv_cart2local_3X3(self): - - lat = 19.4792 - lon = 70.6931 + def test_vcv_cart2local_and_vcv_local2cart2_3X3(self): + lat = 19.4792453 + lon = 70.69315634 v_cart = np.array([ [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], - [0.0, 0.0, 0.0] + [0.0, 0.0, 0.0], ]) - expected_result = np.array([ - [ 0.10931491, -0.10405227, 0.2941739 ], - [-0.10405227, 1.87664567, 0.34874419], - [ 0.2941739, 0.34874419, 1.01403942] + [0., 0., 0.], + [0., 0., 0.], + [0., 0., 0.], ]) - - result = statistics.vcv_cart2local(v_cart, lat, lon) - np.array_equal(expected_result, result) - self.assertEqual(type(expected_result), type(result)) + result_cart2local = statistics.vcv_cart2local(v_cart, lat, lon) + result_local2cart = statistics.vcv_local2cart(v_cart, lat, lon) + + np.testing.assert_array_equal(expected_result, result_cart2local) + np.testing.assert_array_equal(expected_result, result_local2cart) + self.assertEqual(type(expected_result), type(result_cart2local)) + self.assertEqual(type(expected_result), type(result_local2cart)) - def test_vcv_cart2local_3X2(self): - + def test_vcv_cart2local_and_vcv_local2cart2_3X2(self): lat = 0.0 lon = 0.0 v_cart = np.array([ [0.0, 0.0], [0.0, 0.0], - [0.0, 0.0] + [0.0, 0.0], ]) with self.assertRaises(SystemExit): statistics.vcv_cart2local(v_cart, lat, lon) + with self.assertRaises(SystemExit): + statistics.vcv_local2cart(v_cart, lat, lon) - def test_vcv_cart2local_2X3(self): - + def test_vcv_cart2local_and_vcv_local2cart2_2X3(self): lat = 0.0 lon = 0.0 v_cart = np.array([ @@ -72,43 +70,83 @@ def test_vcv_cart2local_2X3(self): with self.assertRaises(SystemExit): statistics.vcv_cart2local(v_cart, lat, lon) + with self.assertRaises(SystemExit): + statistics.vcv_local2cart(v_cart, lat, lon) - def test_vcv_cart2local_1X3(self): - + def test_vcv_cart2local_and_vcv_local2cart2_1X3(self): lat = 0.0 lon = 0.0 v_cart = np.array([ [0.0], [0.0], - [0.0] + [0.0], ]) - expected_result = np.array([ - [0.0, 0.0, 0.0,], - [0.0, 0.0, 0.0,], - [0.0, 0.0, 0.0,] + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], ]) - - result = statistics.vcv_cart2local(v_cart, lat, lon) - - np.array_equal(expected_result, result) - self.assertEqual(type(expected_result), type(result)) + result_cart2local = statistics.vcv_cart2local(v_cart, lat, lon) + result_local2cart = statistics.vcv_local2cart(v_cart, lat, lon) - def test_vcv_local2cart2(self): - pass - + np.testing.assert_array_equal(expected_result, result_cart2local) + np.testing.assert_array_equal(expected_result, result_local2cart) + self.assertEqual(type(expected_result), type(result_cart2local)) + self.assertEqual(type(expected_result), type(result_local2cart)) def test_error_ellipse(self): - pass + vcv = np.array([ + [90, 0, 0], + [0, 90, 0], + [0, 0, 90], + ]) + expected_result = (9.486832980505138, 9.486832980505138, 90.0) + result = statistics.error_ellipse(vcv) + + self.assertEqual(expected_result, result) + self.assertEqual(type(expected_result), type(result)) def test_circ_hz_pu(self): - pass + a = 1 + b = 0 + + expeted_result = 1.96079 + + result = statistics.circ_hz_pu(a, b) + self.assertEqual(expeted_result, result) + + def test_k_val95_typeError(self): + dof = [[], {}, ""] + + for item in dof: + with self.assertRaises(TypeError): + statistics.k_val95(dof) + + def test_k_val95_less_1(self): + dof = -1 + + expected_result = statistics.ttable_p95[0] + + result = statistics.k_val95(dof) + self.assertEqual(expected_result, result) + + def test_k_val95_greater_120(self): + dof = 121 + + expected_result = 1.96 + + result = statistics.k_val95(dof) + self.assertEqual(expected_result, result) + + def test_k_val95_between_1_and_120(self): + dof = 100 + expected_result = statistics.ttable_p95[dof - 1] - def test_k_val95(self): - pass + result = statistics.k_val95(dof) + self.assertEqual(expected_result, result) if __name__ == '__main__': From b384ac9a423b81d119cd694650a34b5f73f3c9aa Mon Sep 17 00:00:00 2001 From: physsi07 Date: Fri, 18 Oct 2019 21:58:18 -0400 Subject: [PATCH 7/9] . --- geodepy/tests/test_statistics.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/geodepy/tests/test_statistics.py b/geodepy/tests/test_statistics.py index 1c280d5..a0bbfd4 100644 --- a/geodepy/tests/test_statistics.py +++ b/geodepy/tests/test_statistics.py @@ -1,6 +1,3 @@ -import sys -sys.path.append("../geodepy") - import unittest from geodepy import statistics from geodepy.statistics import np From 1836c7660cac5e1ba21b46ec3802a10af628a6b0 Mon Sep 17 00:00:00 2001 From: physsi07 Date: Fri, 18 Oct 2019 22:06:40 -0400 Subject: [PATCH 8/9] issue #83: DONE --- README.md | 2 +- geodepy/statistics.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cdd074..8abea48 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ NumPy ### Testing -Run: `python -m unittest discover geodepy/tests/` +Run: `python -m unittest discover geodepy/tests/ --verbose` ### Tutorials diff --git a/geodepy/statistics.py b/geodepy/statistics.py index 469a19e..89f4bbd 100644 --- a/geodepy/statistics.py +++ b/geodepy/statistics.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import sys -sys.path.append('./env/lib/python3.7/site-packages') from math import radians, sin, cos, sqrt, atan2, degrees import numpy as np From 64d74ed5130928578bcc5a1df56ae0f97d5f91d3 Mon Sep 17 00:00:00 2001 From: physsi07 Date: Fri, 18 Oct 2019 22:14:00 -0400 Subject: [PATCH 9/9] issue #83: fixing .gitignore --- .gitignore | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 891e1db..b61b2b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.idea __pycache__ # Compiled python modules. @@ -6,6 +5,7 @@ __pycache__ # Setuptools distribution folder. /dist/ +env # Python egg metadata, regenerated from source files by setuptools. /*.egg-info @@ -13,8 +13,8 @@ __pycache__ # Ignore test-related files /coverage.data /coverage/ -.coverage -htmlcov/ + +# IDEs .vscode -env +.idea