Skip to content

Commit

Permalink
quaternion data tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Aug 15, 2023
1 parent 0cc6465 commit 3d89d5f
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tests/compas/geometry/test_quaternion.py
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
# =============================================================================

0 comments on commit 3d89d5f

Please sign in to comment.