-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from yupidevs/develop
New version
- Loading branch information
Showing
11 changed files
with
378 additions
and
136 deletions.
There are no files selected for viewing
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,82 @@ | ||
import pytest | ||
from yupi import Trajectory | ||
|
||
|
||
def test_creation_by_xyz(): | ||
Trajectory(x=[1, 2]) | ||
Trajectory(x=[1, 2], y=[2, 3]) | ||
Trajectory(x=[1, 2], y=[2, 3], z=[1, 4]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(x=[1, 2], y=[2]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(x=[1, 2], y=[2], z=[2, 5]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(x=[1, 2], y=[2, 6], z=[5]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(x=[2], y=[2, 6], z=[5, 8]) | ||
|
||
|
||
def test_creation_by_dimensions(): | ||
Trajectory(dimensions=[[1, 2]]) | ||
Trajectory(dimensions=[[1, 2], [2, 3]]) | ||
Trajectory(dimensions=[[1, 2], [2, 3], [1, 4]]) | ||
Trajectory(dimensions=[[1, 2], [2, 3], [1, 4], [7, 8]]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(dimensions=[[1, 2], [2]]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(dimensions=[[1, 2], [2], [2, 5]]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(dimensions=[[1, 2], [2, 6], [5]]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(dimensions=[[2], [2, 6], [5, 8]]) | ||
|
||
|
||
def test_creation_by_points(): | ||
Trajectory(points=[[1, 2]]) | ||
Trajectory(points=[[1, 2], [2, 3]]) | ||
Trajectory(points=[[1, 2, 4], [2, 3, 2], [1, 4, 8]]) | ||
Trajectory(points=[[1, 2, 7, 3], [2, 3, 5, 3]]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(points=[[1, 2], [2]]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(points=[[1, 2], [2], [2, 5]]) | ||
|
||
|
||
def test_creation_with_time(): | ||
Trajectory(x=[1, 2], y=[2, 3], t=[0, 0.1]) | ||
Trajectory(x=[1, 2], y=[2, 3], dt=0.1) | ||
Trajectory(x=[1, 2], y=[2, 3], t=[0, 0.1], dt=0.1) | ||
Trajectory(x=[1, 2], y=[2, 3], t=[0.4, 0.5], dt=0.1, t0=0.4) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(x=[1, 2], y=[2, 3], t=[0]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(x=[1, 2], y=[2, 3], t=[0, 0.1], dt=0.2) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(x=[1, 2], y=[2, 3], t=[0.4, 0.5], dt=0.1) | ||
|
||
def test_creation_with_ang(): | ||
Trajectory(x=[1, 2], y=[2, 3], ang=[0, 0.1]) | ||
|
||
with pytest.raises(ValueError): | ||
Trajectory(x=[1, 2], y=[2, 3], ang=[0.1]) | ||
|
||
|
||
def test_creation_general(): | ||
Trajectory(x=[1, 2], y=[2, 3], t=[0, 1], ang=[0, 0], traj_id='test') | ||
Trajectory(x=[1, 2], y=[2, 3], dt=0.5, ang=[0, 1.2], traj_id='test') | ||
Trajectory(points=[[1, 2], [2, 3]], dt=0.5, ang=[0, 1.2], traj_id='test') | ||
Trajectory(dimensions=[[1, 2], [2, 3]], dt=0.5, t=[1, 1.5], t0=1, | ||
traj_id='test') |
This file contains 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,37 @@ | ||
import os | ||
import numpy as np | ||
import pytest | ||
from yupi import Trajectory | ||
|
||
|
||
def test_save(): | ||
t1 = Trajectory(x=[1,2,3], y=[4,5,6]) | ||
|
||
# Wrong trajectory file extension at saving | ||
with pytest.raises(ValueError): | ||
t1.save('t1', file_type='abc') | ||
|
||
# Saving json | ||
t1.save('t1', file_type='json') | ||
|
||
# Saving csv | ||
t1.save('t1', file_type='csv') | ||
|
||
|
||
def test_load(): | ||
# Wrong trajectory file extension at loading | ||
with pytest.raises(ValueError): | ||
t1 = Trajectory.load('t1.abc') | ||
|
||
# Loading json | ||
t1 = Trajectory.load('t1.json') | ||
for tp, point in zip(t1, [[1,4], [2,5], [3,6]]): | ||
assert (np.array(point) == tp.r).all() | ||
|
||
# Loading csv | ||
t1 = Trajectory.load('t1.csv') | ||
for tp, point in zip(t1, [[1,4], [2,5], [3,6]]): | ||
assert (np.array(point) == tp.r).all() | ||
|
||
os.remove('t1.json') | ||
os.remove('t1.csv') |
This file contains 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,122 @@ | ||
import numpy as np | ||
from pytest import approx, fixture | ||
import pytest | ||
from yupi import Trajectory | ||
|
||
APPROX_REL_TOLERANCE = 1e-12 | ||
|
||
@fixture | ||
def points(): | ||
return np.array([[1, 2], [4, 3], [4, 1]], dtype=float) | ||
|
||
|
||
@fixture | ||
def angles(): | ||
return np.array([0, 1, 2], dtype=float) | ||
|
||
|
||
@fixture | ||
def traj(points, angles): | ||
return Trajectory(points=points, ang=angles) | ||
|
||
|
||
def test_length(traj): | ||
assert len(traj) == 3 | ||
|
||
|
||
def test_copy(traj): | ||
copy_traj = traj.copy() | ||
|
||
assert traj.r == approx(copy_traj.r, APPROX_REL_TOLERANCE) | ||
assert traj.dt == approx(copy_traj.dt, APPROX_REL_TOLERANCE) | ||
assert traj.t == approx(copy_traj.t, APPROX_REL_TOLERANCE) | ||
assert traj.v == approx(copy_traj.v, APPROX_REL_TOLERANCE) | ||
assert traj.ang == approx(copy_traj.ang, APPROX_REL_TOLERANCE) | ||
|
||
|
||
def test_iteration(points, angles, traj): | ||
time = traj.t | ||
|
||
for i, tp in enumerate(traj): | ||
point = points[i] | ||
ang = angles[i] | ||
t = time[i] | ||
|
||
assert point == approx(tp.r, APPROX_REL_TOLERANCE) # Position | ||
assert t == approx(tp.t, APPROX_REL_TOLERANCE) # Time | ||
assert ang == approx(tp.ang, APPROX_REL_TOLERANCE) # Angle | ||
|
||
|
||
def test_constant_addition(points, traj): | ||
new_traj = traj + 10 | ||
new_points = points + 10 | ||
|
||
for true_point, point in zip(new_points, new_traj.r): | ||
assert true_point == approx(point, APPROX_REL_TOLERANCE) | ||
|
||
|
||
def test_point_addition(points, traj): | ||
new_traj = traj + (1, 3) | ||
new_points = points + (1, 3) | ||
|
||
for true_point, point in zip(new_points, new_traj.r): | ||
assert true_point == approx(point, APPROX_REL_TOLERANCE) | ||
|
||
|
||
def test_traj_addition(points, traj): | ||
other_traj = traj.copy() | ||
new_traj = traj + other_traj | ||
new_points = points + points | ||
|
||
for true_point, point in zip(new_points, new_traj.r): | ||
assert true_point == approx(point, APPROX_REL_TOLERANCE) | ||
|
||
|
||
def test_wrong_addition(traj): | ||
with pytest.raises(TypeError): | ||
traj += 'wrong' | ||
|
||
|
||
def test_constant_substraction(points, traj): | ||
new_traj = traj - 10 | ||
new_points = points - 10 | ||
|
||
for true_point, point in zip(new_points, new_traj.r): | ||
assert true_point == approx(point, APPROX_REL_TOLERANCE) | ||
|
||
|
||
def test_point_substraction(points, traj): | ||
new_traj = traj - (1, 3) | ||
new_points = points - (1, 3) | ||
|
||
for true_point, point in zip(new_points, new_traj.r): | ||
assert true_point == approx(point, APPROX_REL_TOLERANCE) | ||
|
||
|
||
def test_traj_substraction(points, traj): | ||
other_traj = traj.copy() | ||
new_traj = traj - other_traj | ||
new_points = points - points | ||
|
||
for true_point, point in zip(new_points, new_traj.r): | ||
assert true_point == approx(point, APPROX_REL_TOLERANCE) | ||
|
||
|
||
def test_wrong_substraction(traj): | ||
with pytest.raises(TypeError): | ||
traj -= 'wrong' | ||
|
||
|
||
def test_constant_multiplication(points, traj): | ||
new_traj = traj * 3 | ||
new_points = points * 3 | ||
|
||
for true_point, point in zip(new_points, new_traj.r): | ||
assert true_point == approx(point, APPROX_REL_TOLERANCE) | ||
|
||
|
||
def test_wrong_multiplication(traj): | ||
with pytest.raises(TypeError): | ||
traj *= 'wrong' | ||
with pytest.raises(TypeError): | ||
traj *= [1, 2] |
This file contains 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 |
---|---|---|
|
@@ -27,4 +27,4 @@ | |
'Vector' | ||
] | ||
|
||
__version__ = '0.5.0' | ||
__version__ = '0.5.1' |
This file contains 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
Oops, something went wrong.