-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'merge' into upstream-master
* merge: Add one more name to Contributors. adjust whitespace, add multiple value tests add Vector2.truncate unit tests added tests for scale method add test for vector normalize Create test_vector2_equality.py Updated test using pytest Create test_vector2_truncate.py Closes #13 Closes #14 Closes #15 Closes #16
- Loading branch information
Showing
5 changed files
with
110 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import ppb_vector | ||
|
||
def test_equal(): | ||
test_vector_1 = ppb_vector.Vector2(50, 800) | ||
test_vector_2 = ppb_vector.Vector2(50, 800) | ||
|
||
assert test_vector_1 == test_vector_2 | ||
|
||
def test_not_equal(): | ||
test_vector_1 = ppb_vector.Vector2(800, 800) | ||
test_vector_2 = ppb_vector.Vector2(50, 800) | ||
|
||
assert test_vector_1 != test_vector_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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
|
||
import ppb_vector | ||
|
||
|
||
@pytest.mark.parametrize("x, y, expected", [ | ||
(3, 4, 1), | ||
(6, 8, 1), | ||
(0, 1, 1), | ||
(1, 0, 1), | ||
(0, 0, 0) | ||
]) | ||
def test_normalize(x, y, expected): | ||
vector = ppb_vector.Vector2(x, y).normalize() | ||
assert vector.length == expected |
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,27 @@ | ||
import pytest | ||
from math import hypot | ||
|
||
from ppb_vector import Vector2 | ||
|
||
|
||
@pytest.fixture() | ||
def vector(): | ||
return Vector2(10, 20) | ||
|
||
|
||
def test_calculate_scale(vector): | ||
x, y = 10, 20 | ||
length = hypot(x, y) | ||
scale = 4 | ||
vector_scale_calculated = vector * (scale / length) | ||
assert vector.scale(scale) == vector_scale_calculated | ||
|
||
|
||
def test_scale_is_equivalent_to_truncate(): | ||
""" | ||
Vector2.scale is equivalent to Vector2.truncate | ||
when scalar is less than length | ||
""" | ||
vector_scale = Vector2(3, 4).scale(4) | ||
vector_truncate = Vector2(3, 4).truncate(4) | ||
assert vector_scale == vector_truncate |
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,45 @@ | ||
import pytest | ||
|
||
from ppb_vector import Vector2 | ||
|
||
|
||
def test_truncate(): | ||
test_vector = Vector2(700, 500) | ||
test_vector_truncated = test_vector.truncate(5) | ||
print(test_vector_truncated) | ||
assert test_vector_truncated == Vector2(4.068667356033675, 2.906190968595482) | ||
|
||
|
||
def test_truncate_larger_max_length(): | ||
vector = Vector2(3, 5) | ||
truncated = vector.truncate(10) | ||
assert vector == truncated | ||
|
||
|
||
def test_truncate_equal_max_length(): | ||
vector = Vector2(3, 4) | ||
truncated = vector.truncate(5) | ||
assert vector == truncated | ||
|
||
|
||
def test_truncate_lesser_max_length(): | ||
vector = Vector2(20, 30) | ||
truncated = vector.truncate(10) | ||
assert truncated == vector.scale(10) | ||
|
||
|
||
data = [ | ||
([Vector2(1, 2), 3], Vector2(1, 2)), | ||
([Vector2(5, 12), 6], Vector2(5, 12).scale(6)), | ||
([Vector2(92, 19), 61], Vector2(92, 19).scale(61)), | ||
([Vector2(22, 5), 41], Vector2(22, 5)), | ||
([Vector2(2212481, 189898), 129039], Vector2(2212481, 189898).scale(129039)), | ||
([Vector2(5, 12), 13], Vector2(5, 12)), | ||
([Vector2(438, 153), 464], Vector2(438, 153)), | ||
([Vector2(155, 155), 155], Vector2(155, 155).scale(155)) | ||
] | ||
|
||
|
||
@pytest.mark.parametrize('test_input, expected', data) | ||
def test_multiples_values(test_input, expected): | ||
assert test_input[0].truncate(test_input[1]) == expected |