antikythera/test/test_entity.py
2025-09-29 13:08:50 -04:00

49 lines
1.1 KiB
Python

#!/usr/bin/env python3
import numpy as np
from numpy.typing import NDArray
from typing import List, Tuple, Optional
import math
import pytest
from antikythera.engine.entity import Entity
class TestEntityUpdate:
@pytest.fixture
def entity(self):
return Entity(np.array([0,0]))
# x,y velocities
@pytest.mark.parametrize("x,y", [
(0,0),
(1,0),
(0,1),
(1,1),
(-1,0),
(0,-1),
(-1,-1),
(100,100),
])
def test_entity_update(self, x, y):
"""testing that updating entity returns correct pos"""
e = Entity(np.array([0,0], dtype=np.float32))
e.setVelocity(np.array([x,y]))
# checking starting position
assert e.pos[0] == 0
assert e.pos[1] == 0
startingPos = np.array([0,0], dtype=np.float32)
dt = 1/30 # 1 sec / 30 frames
e.update(dt)
exp_X = x * dt + startingPos[0]
exp_Y = y * dt + startingPos[1]
# checking ending location
assert e.pos[0] == exp_X
assert e.pos[1] == exp_Y