-
Notifications
You must be signed in to change notification settings - Fork 50
Issue #82: Unit Tests for statistics.py #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harry093
merged 9 commits into
GeoscienceAustralia:master
from
suv27:feat(test-statistics)
Oct 25, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
92af48d
Issue #82: Preparing to test the functions, reading docs
suv27 5325f40
issue #82: Test for rotation_matrix()
suv27 5c473b2
issue #82: Test for vcv_cart2local() & vcv_local2cart()
suv27 c00a895
issue #82: removing bad code commit
suv27 f50682e
issue #82: health check
suv27 e1c1f59
Issue #82: finished tests for all the methods
suv27 b384ac9
.
suv27 1836c76
issue #83: DONE
suv27 64d74ed
issue #83: fixing .gitignore
suv27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,20 @@ | ||
| .idea | ||
| __pycache__ | ||
|
|
||
| # Compiled python modules. | ||
| *.pyc | ||
|
|
||
| # Setuptools distribution folder. | ||
| /dist/ | ||
| env | ||
|
|
||
| # Python egg metadata, regenerated from source files by setuptools. | ||
| /*.egg-info | ||
|
|
||
| # Ignore test-related files | ||
| /coverage.data | ||
| /coverage/ | ||
| /coverage/ | ||
|
|
||
| # IDEs | ||
| .vscode | ||
| .idea | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import sys | ||
| from math import radians, sin, cos, sqrt, atan2, degrees | ||
| import numpy as np | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import unittest | ||
| from geodepy import statistics | ||
| from geodepy.statistics import np | ||
|
|
||
|
|
||
| class TestStatistics(unittest.TestCase): | ||
| def test_rotation_matrix(self): | ||
| lat = 19.4792 | ||
| 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], | ||
| ]) | ||
|
|
||
| result = statistics.rotation_matrix(lat, lon) | ||
|
|
||
| np.array_equal(expected_result, result) | ||
suv27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.assertEqual(type(expected_result), type(result)) | ||
|
|
||
| def test_vcv_cart2local_and_vcv_local2cart2_3X3(self): | ||
suv27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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], | ||
| ]) | ||
| expected_result = np.array([ | ||
| [0., 0., 0.], | ||
| [0., 0., 0.], | ||
| [0., 0., 0.], | ||
| ]) | ||
|
|
||
| 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) | ||
suv27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.assertEqual(type(expected_result), type(result_cart2local)) | ||
| self.assertEqual(type(expected_result), type(result_local2cart)) | ||
|
|
||
| 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], | ||
| ]) | ||
|
|
||
| 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_and_vcv_local2cart2_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) | ||
|
|
||
| with self.assertRaises(SystemExit): | ||
| statistics.vcv_local2cart(v_cart, lat, lon) | ||
suv27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def test_vcv_cart2local_and_vcv_local2cart2_1X3(self): | ||
harry093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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_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) | ||
harry093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.assertEqual(type(expected_result), type(result_cart2local)) | ||
| self.assertEqual(type(expected_result), type(result_local2cart)) | ||
|
|
||
| def test_error_ellipse(self): | ||
| vcv = np.array([ | ||
harry093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [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): | ||
| 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] | ||
|
|
||
| result = statistics.k_val95(dof) | ||
| self.assertEqual(expected_result, result) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.