Skip to content

Add test cases to unit_test_sprites.cpp#164

Open
kyriesk wants to merge 2 commits intothoth-tech:mainfrom
kyriesk:unit-test/sprite-collision
Open

Add test cases to unit_test_sprites.cpp#164
kyriesk wants to merge 2 commits intothoth-tech:mainfrom
kyriesk:unit-test/sprite-collision

Conversation

@kyriesk
Copy link
Copy Markdown

@kyriesk kyriesk commented May 1, 2026

Description

This pull request adds comprehensive unit tests for three collision-related functions in the sprite module that were previously untested in the unit test suite. The tests adapt test scenarios from test_sprites.cpp (sktest) into proper unit tests using the Catch2 framework.

The new tests ensure that:

  • calculate_collision_direction correctly determines the direction of collision between sprites and geometric shapes
  • resolve_collision properly resolves collisions by moving objects out of collision states
  • sprite_ray_collision accurately detects when sprites intersect with rays

Fixes #(issue related to missing collision tests)

Type of change

  • New feature (non-breaking change which adds functionality)

Changes Made

  • Added 5 new test cases to coresdk/src/test/unit_tests/unit_test_sprites.cpp:

    1. collision direction between sprites (6 sub-tests)

      • No collision detection
      • Collision detected in multiple directions (left, right, top, bottom)
    2. collision direction between sprite and rectangle (2 sub-tests)

      • No collision detection
      • Collision detected
    3. collision resolution between sprites (3 sub-tests)

      • Successful collision resolution
      • No resolution when sprites don't collide
      • No resolution with zero direction vector
    4. collision resolution between sprite and rectangle (2 sub-tests)

      • Successful collision resolution
      • No resolution when sprite and rectangle don't collide
    5. sprite ray collision detection (6 sub-tests)

      • Ray intersects sprite
      • Ray misses sprite
      • Ray origin at sprite center
      • Different ray directions
      • Ray pointing away from sprite
      • Multiple sprites along same ray
  • Added required headers: collisions.h and geometry.h

How Has This Been Tested?

The tests have been written following the existing patterns in unit_test_sprites.cpp and use:

  • Catch2 TEST_CASE and SECTION macros
  • Standard sprite creation and manipulation functions
  • Position-based collision scenarios with known outcomes
  • Assertions using REQUIRE and REQUIRE_FALSE macros

All tests use existing resources (rocket_sprt.png, background.png, frog.png) that are already available in the test resources directory.

All tests were run and verified to pass:

cd projects/cmake
cmake --preset Linux
cmake --build build/
cd ../../bin
./skunit_tests "[collision]"

Testing Checklist

  • Tested with skunit_tests

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented test scenarios with descriptive names
  • Tests follow existing unit test patterns in the codebase
  • My changes generate no new warnings
  • Tests are isolated and properly clean up resources (free sprites)
  • I have requested a review from ... on the Pull Request

Additional Notes

  • All collision direction tests verify both vector magnitude and direction (when collisions occur)
  • All collision resolution tests verify position changes before and after resolution
  • Ray collision tests cover edge cases including ray origin at sprite center and rays pointing away
  • Tests follow the pattern of setting up controlled sprite positions and verifying expected collision behaviors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant