Skip to content

Commit

Permalink
Merge pull request #108 from labuzm/tests
Browse files Browse the repository at this point in the history
initial setup for tests
  • Loading branch information
maniek2332 committed Jan 7, 2021
2 parents c53ce49 + 476f4d5 commit 1815aeb
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .ci/az-pipelines/templates/common_prepare_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ steps:
- script: |
python --version
python -m pip install --upgrade pip
python -m pip install Cython==0.29.21 scikit-build==0.11.1 cymove==1.0.0
python -m pip install -r requirements/build.txt
displayName: 'Prepare Python $(python.version)'
3 changes: 2 additions & 1 deletion .ci/az-pipelines/templates/common_test_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ steps:
python -m venv venv_test_$(python.version)
./venv_test_$(python.version)/${PYTHON} -m pip install --upgrade pip
./venv_test_$(python.version)/${PYTHON} -m pip install --upgrade ../wheelhouse/*.whl
./venv_test_$(python.version)/${PYTHON} -c "import kaa._kaa"
./venv_test_$(python.version)/${PYTHON} -m pip install -r ../requirements/test.txt
./venv_test_$(python.version)/${PYTHON} -m pytest
displayName: 'Testing wheel (import)'
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ addons:
- g++
- freeglut3-dev

install: python3 -m pip install -vvv -e .
script: python3 -c 'import kaa._kaa'
install:
- python3 -m pip install -vvv -e .
- python3 -m pip install -r requirements/test.txt
script: pytest || travis_terminate 1
1 change: 0 additions & 1 deletion requirements-dev.txt → requirements/build.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake>=3.13.1
ninja==1.9.0.post1
Cython==0.29.21
scikit-build==0.11.1
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmake>=3.13.1
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==6.2.1
Empty file added tests/__init__.py
Empty file.
44 changes: 44 additions & 0 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import math

import pytest

from kaa.geometry import Vector


def test_vector():
v1 = Vector.xy(1.)
assert v1.x == 1. and v1.y == 1.
v2 = Vector(2., 2.)
assert v2.x == 2. and v2.y == 2.
assert v1 == Vector(1., 1.)
assert v2 == Vector(2., 2.)

zero = Vector(0, 0)
assert not zero
assert zero.is_zero()

assert v1 + v2 == Vector.xy(3)
assert Vector.xy(3.) - v2 == v1
assert v1 * 10 == Vector.xy(10.)
assert Vector.xy(10.) / 10 == v1
assert -v1 == Vector.xy(-1.)

rotated_vector = Vector(1, 0).rotate_angle_degrees(90)
assert pytest.approx(rotated_vector.x) == 0
assert pytest.approx(rotated_vector.y) == 1.

v = Vector.from_angle_degrees(90)
assert pytest.approx(rotated_vector.x) == 0
assert pytest.approx(rotated_vector.y) == 1.
assert v.to_angle_degrees() == 90
assert Vector(1., 0).angle_between_degrees(Vector(0, 1.)) == 90

assert Vector(1., 0).normalize().dot(Vector(1, 1.).normalize()) > 0
assert Vector(1., 0).normalize().dot(Vector(0, 1.).normalize()) == 0
assert Vector(1., 0).normalize().dot(Vector(-1, 1.).normalize()) < 0

assert Vector(0, 0).distance(Vector(10., 0)) == 10.

v = Vector(10., 10.)
assert v.normalize() == v / v.length()
assert v.length() == math.sqrt(v.x ** 2 + v.y ** 2)

0 comments on commit 1815aeb

Please sign in to comment.