Skip to content

Commit

Permalink
Merge branch 'merge' into upstream-master
Browse files Browse the repository at this point in the history
* 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
pathunstrom committed Oct 10, 2018
2 parents 8ee8129 + 9c75d2f commit 29d0590
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 7 deletions.
17 changes: 10 additions & 7 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ Thank you everyone below for your contributions **(No matter how big or small)!*

| Name | Email | Twitter |
| ---- | ----- | ------- |
| [Amber Phair](https://github.com/Maowse) |
| [Jeronimo Martinez Sanchez](https://github.com/jms) |
| [AJ Khan](https://github.com/ak9999) |
| [Rodrigo Prado](https://github.com/royopa) |
| [Jamie Bliss](https://github.com/astronouth7303) |
| [Devesh Kailay](https://github.com/deveshd2k) |
| [Vitaly Khabarov](https://github.com/vitkhab) |
| [Amber Phair](https://github.com/Maowse) |||
| [Jeronimo Martinez Sanchez](https://github.com/jms) |||
| [AJ Khan](https://github.com/ak9999) |||
| [Rodrigo Prado](https://github.com/royopa) |||
| [Jamie Bliss](https://github.com/astronouth7303) |||
| [Devesh Kailay](https://github.com/deveshd2k) |||
| [Vitaly Khabarov](https://github.com/vitkhab) |||
| [Ricky Putra](kurokochin) |||
| [Maybeking](https://github.com/Maybeking) |||
| [Henry](https://github.com/hphu) |||
13 changes: 13 additions & 0 deletions tests/test_vector2_equality.py
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
15 changes: 15 additions & 0 deletions tests/test_vector2_normalize.py
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
27 changes: 27 additions & 0 deletions tests/test_vector2_scale.py
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
45 changes: 45 additions & 0 deletions tests/test_vector2_truncate.py
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

0 comments on commit 29d0590

Please sign in to comment.