fix: Update test files to use current API patterns
Migrates test suite to current API:
- Frame(x, y, w, h) → Frame(pos=(x, y), size=(w, h))
- Caption("text", x, y) → Caption(pos=(x, y), text="text")
- caption.size → caption.font_size
- Entity(x, y, ...) → Entity((x, y), ...)
- Grid(w, h, ...) → Grid(grid_size=(w, h), ...)
- cell.color → ColorLayer system
Tests now serve as valid API usage examples.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c025cd7da3
commit
9f481a2e4a
53 changed files with 614 additions and 586 deletions
|
|
@ -8,6 +8,10 @@ while small grids use the original flat storage. Verifies that:
|
|||
2. Large grids work correctly with chunks
|
||||
3. Cell access (read/write) works for both modes
|
||||
4. Rendering displays correctly for both modes
|
||||
|
||||
NOTE: This test uses ColorLayer for color operations since cell.color
|
||||
is no longer supported. The chunk system affects internal storage, which
|
||||
ColorLayer also uses.
|
||||
"""
|
||||
|
||||
import mcrfpy
|
||||
|
|
@ -19,22 +23,21 @@ def test_small_grid():
|
|||
|
||||
# Small grid should use flat storage
|
||||
grid = mcrfpy.Grid(grid_size=(50, 50), pos=(10, 10), size=(400, 400))
|
||||
color_layer = grid.add_layer("color", z_index=-1)
|
||||
|
||||
# Set some cells
|
||||
for y in range(50):
|
||||
for x in range(50):
|
||||
cell = grid.at(x, y)
|
||||
cell.color = mcrfpy.Color((x * 5) % 256, (y * 5) % 256, 128, 255)
|
||||
color_layer.set(x, y, mcrfpy.Color((x * 5) % 256, (y * 5) % 256, 128, 255))
|
||||
cell.tilesprite = -1
|
||||
|
||||
# Verify cells
|
||||
cell = grid.at(25, 25)
|
||||
expected_r = (25 * 5) % 256
|
||||
expected_g = (25 * 5) % 256
|
||||
color = cell.color
|
||||
r, g = color[0], color[1]
|
||||
if r != expected_r or g != expected_g:
|
||||
print(f"FAIL: Small grid cell color mismatch. Expected ({expected_r}, {expected_g}), got ({r}, {g})")
|
||||
color = color_layer.at(25, 25)
|
||||
if color.r != expected_r or color.g != expected_g:
|
||||
print(f"FAIL: Small grid cell color mismatch. Expected ({expected_r}, {expected_g}), got ({color.r}, {color.g})")
|
||||
return False
|
||||
|
||||
print(" Small grid: PASS")
|
||||
|
|
@ -46,6 +49,7 @@ def test_large_grid():
|
|||
|
||||
# Large grid should use chunk storage (100 > 64)
|
||||
grid = mcrfpy.Grid(grid_size=(100, 100), pos=(10, 10), size=(400, 400))
|
||||
color_layer = grid.add_layer("color", z_index=-1)
|
||||
|
||||
# Set cells across multiple chunks
|
||||
# Chunks are 64x64, so a 100x100 grid has 2x2 = 4 chunks
|
||||
|
|
@ -61,15 +65,14 @@ def test_large_grid():
|
|||
|
||||
for x, y in test_points:
|
||||
cell = grid.at(x, y)
|
||||
cell.color = mcrfpy.Color(x, y, 100, 255)
|
||||
color_layer.set(x, y, mcrfpy.Color(x, y, 100, 255))
|
||||
cell.tilesprite = -1
|
||||
|
||||
# Verify cells
|
||||
for x, y in test_points:
|
||||
cell = grid.at(x, y)
|
||||
color = cell.color
|
||||
if color[0] != x or color[1] != y:
|
||||
print(f"FAIL: Large grid cell ({x},{y}) color mismatch. Expected ({x}, {y}), got ({color[0]}, {color[1]})")
|
||||
color = color_layer.at(x, y)
|
||||
if color.r != x or color.g != y:
|
||||
print(f"FAIL: Large grid cell ({x},{y}) color mismatch. Expected ({x}, {y}), got ({color.r}, {color.g})")
|
||||
return False
|
||||
|
||||
print(" Large grid cell access: PASS")
|
||||
|
|
@ -81,6 +84,7 @@ def test_very_large_grid():
|
|||
|
||||
# 500x500 = 250,000 cells, should use ~64 chunks (8x8)
|
||||
grid = mcrfpy.Grid(grid_size=(500, 500), pos=(10, 10), size=(400, 400))
|
||||
color_layer = grid.add_layer("color", z_index=-1)
|
||||
|
||||
# Set some cells at various positions
|
||||
test_points = [
|
||||
|
|
@ -94,14 +98,12 @@ def test_very_large_grid():
|
|||
]
|
||||
|
||||
for x, y in test_points:
|
||||
cell = grid.at(x, y)
|
||||
cell.color = mcrfpy.Color(x % 256, y % 256, 200, 255)
|
||||
color_layer.set(x, y, mcrfpy.Color(x % 256, y % 256, 200, 255))
|
||||
|
||||
# Verify
|
||||
for x, y in test_points:
|
||||
cell = grid.at(x, y)
|
||||
color = cell.color
|
||||
if color[0] != (x % 256) or color[1] != (y % 256):
|
||||
color = color_layer.at(x, y)
|
||||
if color.r != (x % 256) or color.g != (y % 256):
|
||||
print(f"FAIL: Very large grid cell ({x},{y}) color mismatch")
|
||||
return False
|
||||
|
||||
|
|
@ -114,20 +116,20 @@ def test_boundary_case():
|
|||
|
||||
# 64x64 should use flat storage (not exceeding threshold)
|
||||
grid_64 = mcrfpy.Grid(grid_size=(64, 64), pos=(10, 10), size=(400, 400))
|
||||
cell = grid_64.at(63, 63)
|
||||
cell.color = mcrfpy.Color(255, 0, 0, 255)
|
||||
color = grid_64.at(63, 63).color
|
||||
if color[0] != 255:
|
||||
print(f"FAIL: 64x64 grid boundary cell not set correctly, got r={color[0]}")
|
||||
color_layer_64 = grid_64.add_layer("color", z_index=-1)
|
||||
color_layer_64.set(63, 63, mcrfpy.Color(255, 0, 0, 255))
|
||||
color = color_layer_64.at(63, 63)
|
||||
if color.r != 255:
|
||||
print(f"FAIL: 64x64 grid boundary cell not set correctly, got r={color.r}")
|
||||
return False
|
||||
|
||||
# 65x65 should use chunk storage (exceeding threshold)
|
||||
grid_65 = mcrfpy.Grid(grid_size=(65, 65), pos=(10, 10), size=(400, 400))
|
||||
cell = grid_65.at(64, 64)
|
||||
cell.color = mcrfpy.Color(0, 255, 0, 255)
|
||||
color = grid_65.at(64, 64).color
|
||||
if color[1] != 255:
|
||||
print(f"FAIL: 65x65 grid cell not set correctly, got g={color[1]}")
|
||||
color_layer_65 = grid_65.add_layer("color", z_index=-1)
|
||||
color_layer_65.set(64, 64, mcrfpy.Color(0, 255, 0, 255))
|
||||
color = color_layer_65.at(64, 64)
|
||||
if color.g != 255:
|
||||
print(f"FAIL: 65x65 grid cell not set correctly, got g={color.g}")
|
||||
return False
|
||||
|
||||
print(" Boundary cases: PASS")
|
||||
|
|
@ -139,19 +141,18 @@ def test_edge_cases():
|
|||
|
||||
# Create 100x100 grid
|
||||
grid = mcrfpy.Grid(grid_size=(100, 100), pos=(10, 10), size=(400, 400))
|
||||
color_layer = grid.add_layer("color", z_index=-1)
|
||||
|
||||
# Test all corners
|
||||
corners = [(0, 0), (99, 0), (0, 99), (99, 99)]
|
||||
for i, (x, y) in enumerate(corners):
|
||||
cell = grid.at(x, y)
|
||||
cell.color = mcrfpy.Color(i * 60, i * 60, i * 60, 255)
|
||||
color_layer.set(x, y, mcrfpy.Color(i * 60, i * 60, i * 60, 255))
|
||||
|
||||
for i, (x, y) in enumerate(corners):
|
||||
cell = grid.at(x, y)
|
||||
expected = i * 60
|
||||
color = cell.color
|
||||
if color[0] != expected:
|
||||
print(f"FAIL: Corner ({x},{y}) color mismatch, expected {expected}, got {color[0]}")
|
||||
color = color_layer.at(x, y)
|
||||
if color.r != expected:
|
||||
print(f"FAIL: Corner ({x},{y}) color mismatch, expected {expected}, got {color.r}")
|
||||
return False
|
||||
|
||||
print(" Edge cases: PASS")
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ import sys
|
|||
|
||||
# Create a derived Entity class
|
||||
class CustomEntity(mcrfpy.Entity):
|
||||
def __init__(self, x, y):
|
||||
super().__init__(x, y)
|
||||
def __init__(self, pos):
|
||||
super().__init__(pos)
|
||||
self.custom_attribute = "I am custom!"
|
||||
|
||||
|
||||
def custom_method(self):
|
||||
return "Custom method called"
|
||||
|
||||
|
|
@ -21,11 +21,11 @@ def run_test(runtime):
|
|||
"""Test that derived entity classes maintain their type in collections"""
|
||||
try:
|
||||
# Create a grid
|
||||
grid = mcrfpy.Grid(10, 10)
|
||||
|
||||
grid = mcrfpy.Grid(grid_size=(10, 10))
|
||||
|
||||
# Create instances of base and derived entities
|
||||
base_entity = mcrfpy.Entity(1, 1)
|
||||
custom_entity = CustomEntity(2, 2)
|
||||
base_entity = mcrfpy.Entity((1, 1))
|
||||
custom_entity = CustomEntity((2, 2))
|
||||
|
||||
# Add them to the grid's entity collection
|
||||
grid.entities.append(base_entity)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue