-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cc6465
commit 3d89d5f
Showing
1 changed file
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import pytest | ||
import json | ||
import compas | ||
from random import random | ||
|
||
from compas.geometry import Quaternion | ||
from compas.geometry import close | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"x,y,z,w", | ||
[ | ||
(0.0, 0.0, 0.0, 0.0), | ||
(0.0, 0.0, 0.0, 1.0), | ||
(1.0, 0.0, 0.0, 0.0), | ||
(1.0, 0.0, 0.0, 1.0), | ||
(0.0, 1.0, 0.0, 0.0), | ||
(0.0, 1.0, 0.0, 1.0), | ||
(0.0, 0.0, 1.0, 0.0), | ||
(0.0, 0.0, 1.0, 1.0), | ||
(1.0, 1.0, 1.0, 0.0), | ||
(1.0, 1.0, 1.0, 1.0), | ||
(random(), random(), random(), random()), | ||
], | ||
) | ||
def test_quaternion(w, x, y, z): | ||
quaternion = Quaternion(w, x, y, z) | ||
|
||
assert quaternion.w == w | ||
assert quaternion.x == x | ||
assert quaternion.y == y | ||
assert quaternion.z == z | ||
|
||
other = eval(repr(quaternion)) | ||
|
||
assert close(quaternion.w, other.w, tol=1e-12) | ||
assert close(quaternion.x, other.x, tol=1e-12) | ||
assert close(quaternion.y, other.y, tol=1e-12) | ||
assert close(quaternion.z, other.z, tol=1e-12) | ||
|
||
|
||
# ============================================================================= | ||
# Data | ||
# ============================================================================= | ||
|
||
|
||
def test_quaternion_data(): | ||
x = random() | ||
y = random() | ||
z = random() | ||
w = random() | ||
|
||
quaternion = Quaternion(w, x, y, z) | ||
other = Quaternion.from_data(json.loads(json.dumps(quaternion.data))) | ||
|
||
assert quaternion.w == other.w | ||
assert quaternion.x == other.x | ||
assert quaternion.y == other.y | ||
assert quaternion.z == other.z | ||
|
||
if not compas.IPY: | ||
assert Quaternion.validate_data(quaternion.data) | ||
assert Quaternion.validate_data(other.data) | ||
|
||
|
||
# ============================================================================= | ||
# Constructors | ||
# ============================================================================= | ||
|
||
# ============================================================================= | ||
# Properties and Geometry | ||
# ============================================================================= | ||
|
||
# ============================================================================= | ||
# Accessors | ||
# ============================================================================= | ||
|
||
# ============================================================================= | ||
# Comparison | ||
# ============================================================================= | ||
|
||
# ============================================================================= | ||
# Other Methods | ||
# ============================================================================= |