This commit is contained in:
Will McGugan
2021-07-05 20:37:54 +01:00
parent c8e14859e5
commit e52af23f0f
5 changed files with 100 additions and 0 deletions

0
tests/__init__.py Normal file
View File

36
tests/test_geometry.py Normal file
View File

@@ -0,0 +1,36 @@
import pytest
from textual.geometry import clamp, Point, Dimensions, Region
def test_clamp():
assert clamp(5, 0, 10) == 5
assert clamp(-1, 0, 10) == 0
assert clamp(11, 0, 10) == 10
assert clamp(0, 0, 10) == 0
assert clamp(10, 0, 10) == 10
def test_point_is_origin():
assert Point(0, 0).is_origin
assert not Point(1, 0).is_origin
def test_point_add():
assert Point(1, 1) + Point(2, 2) == Point(3, 3)
assert Point(1, 2) + Point(3, 4) == Point(4, 6)
with pytest.raises(TypeError):
Point(1, 1) + "foo"
def test_point_sub():
assert Point(1, 1) - Point(2, 2) == Point(-1, -1)
assert Point(3, 4) - Point(2, 1) == Point(1, 3)
with pytest.raises(TypeError):
Point(1, 1) - "foo"
def test_point_blend():
assert Point(1, 2).blend(Point(3, 4), 0) == Point(1, 2)
assert Point(1, 2).blend(Point(3, 4), 1) == Point(3, 4)
assert Point(1, 2).blend(Point(3, 4), 0.5) == Point(2, 3)