Skip to content

Commit

Permalink
add some tests functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yucongalicechen committed Apr 5, 2024
1 parent d028ae5 commit 49a514b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion diffpy/labpdfproc/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _get_entry_exit_coordinates(self, coordinate, angle):
xexit_root1, xexit_root2 = np.roots((1 + a**2, 2 * a * b, b**2 - self.radius**2))
yexit_root1 = a * xexit_root1 + b
yexit_root2 = a * xexit_root2 + b
if yexit_root2 >= ygrid: # We pick the point above
if yexit_root2 >= yexit_root1: # We pick the point above
exit_point = (xexit_root2, yexit_root2)
else:
exit_point = (xexit_root1, yexit_root1)
Expand Down
38 changes: 38 additions & 0 deletions diffpy/labpdfproc/tests/test_get_grid_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np
import pytest

from diffpy.labpdfproc.functions import Gridded_circle


def test_get_grid_points():
actual_gs = Gridded_circle(radius=1, n_points_on_diameter=3, mu=1)
expected_gs = Gridded_circle()
expected_gs.grid = {(0.0, -1.0), (0.0, 0.0), (-1.0, 0.0), (1.0, 0.0), (0.0, 1.0)}
expected_gs.total_points_in_grid = 5
assert actual_gs.grid == expected_gs.grid
assert actual_gs.total_points_in_grid == expected_gs.total_points_in_grid


"""
class TestGetGridPoints:
def setUp(self):
self.radius = 5
self.npoints = 10
self._get_grid_points()
#
self.radius = 0.5
self.grid = [(-0.026315789473684237, -0.4473684210526316),
(0.13157894736842102, -0.2368421052631579),
(0.18421052631578938, 0.02631578947368418),
(0.3421052631578947, 0.18421052631578938),
(0.02631578947368418, -0.4473684210526316),
(0.18421052631578938, -0.2368421052631579),
(0.2894736842105263, 0.07894736842105265),
(0.2894736842105263, 0.18421052631578938),
(-0.1842105263157895, -0.39473684210526316),
(0.23684210526315785, -0.2368421052631579),
(-0.2368421052631579, 0.07894736842105265),
(0.23684210526315785, 0.18421052631578938)]
#self.total_points_in_grid = len(self.grid)
"""
23 changes: 23 additions & 0 deletions diffpy/labpdfproc/tests/test_set_distances_at_angle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest

from diffpy.labpdfproc.functions import Gridded_circle


def test_set_distances_at_angle():
actual_gs = Gridded_circle(radius=1, n_points_on_diameter=3, mu=1)

# tests for acute angles
actual_gs.set_distances_at_angle(25)
actual_acute = actual_gs.distances
expected_acute = [0, 2, 1.81261557406, 2, 0.845236523481399]
assert actual_acute == pytest.approx(expected_acute, rel=1e-4, abs=1e-6)

actual_gs.set_distances_at_angle(90)
actual_right = actual_gs.distances
expected_right = [0, 2, 0, 2, 2]
assert actual_right == pytest.approx(expected_right, rel=1e-4, abs=1e-6)

actual_gs.set_distances_at_angle(140)
actual_obtuse = actual_gs.distances
expected_obtuse = [0, 2, 0, 3.5320888862379562, 1.2855752193730785]
assert actual_obtuse == pytest.approx(expected_obtuse, rel=1e-4, abs=1e-6)

0 comments on commit 49a514b

Please sign in to comment.