tests laufen
This commit is contained in:
1 parent
572ee41e6f
commit
ae46e0646c
11 files changed
+86
-8
No files matched your search
Generated
+1
@@ -2,6 +2,7 @@
|
|||||||
<module external.system.id="pyproject.toml" type="PYTHON_MODULE" version="4">
|
<module external.system.id="pyproject.toml" type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="~/PycharmProjects/MatrixMania/.venv" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="~/PycharmProjects/MatrixMania/.venv" jdkType="Python SDK" />
|
||||||
|
|||||||
@@ -2,3 +2,6 @@
|
|||||||
- Code nach PEP 8, Zeilenlänge maximal 88 Zeichen.
|
- Code nach PEP 8, Zeilenlänge maximal 88 Zeichen.
|
||||||
- Jede Funktion und Methode hat einen Docstring und Type Hints.
|
- Jede Funktion und Methode hat einen Docstring und Type Hints.
|
||||||
- Vor jedem Commit: `ruff check` und `ruff format`.
|
- Vor jedem Commit: `ruff check` und `ruff format`.
|
||||||
|
## Projektstruktur
|
||||||
|
- Quellcode liegt unter "src/matrixmania/", Tests unter "test/test_matrixmania/"
|
||||||
|
- Testpakete, Testdateien und Testfunktionen beginnen mit "test_"
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
from spiel.game import Game
|
|
||||||
|
|
||||||
|
|
||||||
def print_hi(name):
|
def print_hi(name):
|
||||||
# Use a breakpoint in the code line below to debug your script.
|
# Use a breakpoint in the code line below to debug your script.
|
||||||
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
||||||
|
|||||||
+4
-2
@@ -3,6 +3,8 @@ name = "matrixmania"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = ["pygame"]
|
dependencies = ["pygame"]
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
pythonpath = "src"
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev = ["pytest", "ruff",
|
dev = ["pytest", "ruff", "pytest-cov"]
|
||||||
0 ^, "pytest-cov"]
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
from .compute import matmul, transpose, rot_2D, rot_3D
|
||||||
File renamed without changes.
@@ -66,7 +66,26 @@ def rot_2D(theta: float) -> list[list[float]]:
|
|||||||
s = math.sin(theta)
|
s = math.sin(theta)
|
||||||
return [[c, -s], [s, c]]
|
return [[c, -s], [s, c]]
|
||||||
|
|
||||||
def rot3d(angle: float, axis: str) -> list[list[float]]:
|
def rot_3D(angle: float, axis: str) -> list[list[float]]:
|
||||||
|
"""Return a 3×3 rotation matrix for a rotation around *axis*.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
angle : float
|
||||||
|
Rotation angle in radians.
|
||||||
|
axis : str
|
||||||
|
Axis of rotation, one of "x", "y" or "z".
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
list[list[float]]
|
||||||
|
The 3×3 rotation matrix.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
ValueError
|
||||||
|
If *axis* is not one of "x", "y" or "z".
|
||||||
|
"""
|
||||||
c = math.cos(angle)
|
c = math.cos(angle)
|
||||||
s = math.sin(angle)
|
s = math.sin(angle)
|
||||||
if axis == "x":
|
if axis == "x":
|
||||||
File renamed without changes.
@@ -13,8 +13,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
from spiel.compute import rot_2D, matmul
|
from src.matrixmania.compute import rot_2D, matmul
|
||||||
from spiel.game import Game
|
from src.matrixmania.game import Game
|
||||||
|
|
||||||
|
|
||||||
EARTH_RADIUS = 30
|
EARTH_RADIUS = 30
|
||||||
File renamed without changes.
@@ -0,0 +1,55 @@
|
|||||||
|
import math
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from matrixmania import rot_2D, rot_3D
|
||||||
|
|
||||||
|
def test_rot2D(): # gibt Rotationsmatrix für 90 grad
|
||||||
|
# Arrange
|
||||||
|
theta = math.pi / 2 # 90 Grad in Radiant
|
||||||
|
erwartet = [[0.0, -1.0], [1.0, 0.0]]
|
||||||
|
|
||||||
|
# Act
|
||||||
|
ergebnis = rot_2D(theta)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert len(ergebnis) == 2
|
||||||
|
assert all(len(zeile) == 2 for zeile in ergebnis)
|
||||||
|
for zeile_ist, zeile_soll in zip(ergebnis, erwartet):
|
||||||
|
assert zeile_ist == pytest.approx(zeile_soll, abs=1e-9)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"axis, erwartet",
|
||||||
|
[
|
||||||
|
("x", [[1.0, 0.0, 0.0],
|
||||||
|
[0.0, 0.0, -1.0],
|
||||||
|
[0.0, 1.0, 0.0]]),
|
||||||
|
("y", [[ 0.0, 0.0, 1.0],
|
||||||
|
[ 0.0, 1.0, 0.0],
|
||||||
|
[-1.0, 0.0, 0.0]]),
|
||||||
|
("z", [[0.0, -1.0, 0.0],
|
||||||
|
[1.0, 0.0, 0.0],
|
||||||
|
[0.0, 0.0, 1.0]]),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_rot3D(axis, erwartet): # bei 90 Grad Rotation um jede Achse
|
||||||
|
# Arrange
|
||||||
|
angle = math.pi / 2 # 90 Grad in Radiant
|
||||||
|
|
||||||
|
# Act
|
||||||
|
ergebnis = rot_3D(angle, axis)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert len(ergebnis) == 3
|
||||||
|
assert all(len(zeile) == 3 for zeile in ergebnis)
|
||||||
|
for zeile_ist, zeile_soll in zip(ergebnis, erwartet):
|
||||||
|
assert zeile_ist == pytest.approx(zeile_soll, abs=1e-9)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rot3D_ungueltige_achse(): # wirft ValueError bei ungültiger Achse
|
||||||
|
# Arrange
|
||||||
|
angle = math.pi / 2
|
||||||
|
axis = "w"
|
||||||
|
|
||||||
|
# Act & Assert
|
||||||
|
with pytest.raises(ValueError, match="Unsupported rotation axis"):
|
||||||
|
rot_3D(angle, axis)
|
||||||
Reference in new issue
Block a user