Skip to content

feat: add invariant-based test suite (50+ uncheateable tests)#19

Merged
EricBorges2019 merged 2 commits intomainfrom
feat/strong-test-suite
Mar 10, 2026
Merged

feat: add invariant-based test suite (50+ uncheateable tests)#19
EricBorges2019 merged 2 commits intomainfrom
feat/strong-test-suite

Conversation

@EricBorges2019
Copy link
Owner

Summary

  • Add 3 new test files with 50+ tests covering math invariants, rasterizer correctness, and full pipeline integration
  • Tests use randomized inputs (deterministic PRNG) and verify mathematical properties rather than hardcoded values, making them robust against stub implementations
  • All 6 test suites pass (3 existing + 3 new)

Test files

  • test_math_invariants.cpp (27 tests): Vec3 cross/dot properties, Mat4 rotation/translation/scale invariants, perspective/ortho projection mapping, lookAt correctness
  • test_rasterizer.cpp (16 tests): Triangle coverage, depth occlusion, color/UV/normal interpolation, near-plane clipping, degenerate triangles, barycentric validity
  • test_pipeline_integration.cpp (17 tests): Vertex processor, fragment shader lighting/attenuation/specular, texture sampling, full renderer end-to-end (perspective foreshortening, draw ordering, resize)

Test plan

  • All tests compile without warnings
  • ctest --output-on-failure passes all 6 suites (0.83s total)
  • Verify CI passes on GitHub Actions

🤖 Generated with Claude Code

Add 50+ tests across 3 new test files that verify mathematical properties,
rasterization correctness, and full pipeline integration using randomized
inputs — designed to be robust against stub implementations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the testing infrastructure by introducing a comprehensive, invariant-based test suite. The new tests cover critical components of the rendering pipeline, including mathematical operations, rasterization logic, and full pipeline integration. By employing randomized inputs and verifying fundamental mathematical and graphical invariants, these tests provide a robust mechanism to ensure the correctness and stability of the renderer, making it resilient to future changes or stub implementations.

Highlights

  • New Test Files: Added three new test files (test_math_invariants.cpp, test_rasterizer.cpp, test_pipeline_integration.cpp) introducing over 50 new tests.
  • Invariant-Based Testing: Implemented invariant-based testing using deterministic pseudo-random number generation (PRNG) to verify mathematical properties rather than fixed values, enhancing test robustness.
  • Comprehensive Coverage: Ensured all six test suites (three existing, three new) pass, confirming the correctness of math, rasterization, and the full rendering pipeline.
Changelog
  • CMakeLists.txt
    • Added build targets and CTest entries for test_math_invariants, test_rasterizer, and test_pipeline_integration.
  • tests/test_math_invariants.cpp
    • Introduced a new test file for invariant-based mathematical property tests.
    • Included tests for Vec3 operations (cross product perpendicularity, magnitude, anti-commutativity, dot product properties, normalization, LERP, arithmetic identities, distributivity).
    • Included tests for Mat4 operations (rotation determinant, orthogonality, length preservation, composition, translation behavior, scaling, associativity, identity neutrality, matrix-vector distributivity, transpose properties).
    • Included tests for perspective and orthographic projection invariants (near/far plane mapping, center mapping, depth monotonicity).
    • Included tests for lookAt matrix invariants (eye to origin mapping, target on -Z axis).
    • Included tests for Vec4 perspective divide and dot product.
    • Included tests for combined transform chain consistency.
  • tests/test_pipeline_integration.cpp
    • Introduced a new test file for full rendering pipeline integration tests.
    • Included tests for VertexProcessor (identity, translation, batch processing, rotation preserving distance).
    • Included tests for FragmentShader (unlit albedo, lit brightness, light attenuation, specular highlight, output clamping).
    • Included tests for Texture (checkerboard pattern, bilinear continuity, UV wrapping, empty texture behavior).
    • Included tests for Renderer (basic draw, culling behind camera, perspective foreshortening, resize, beginFrame clearing, multiple draws).
    • Included tests for Framebuffer (depth test, pixel readback).
  • tests/test_rasterizer.cpp
    • Introduced a new test file for uncheatable rasterization tests.
    • Included tests for triangle coverage (full-screen, centered).
    • Included tests for color interpolation.
    • Included tests for depth buffer occlusion and value correctness.
    • Included tests for degenerate triangles (zero area).
    • Included tests for clipping (behind camera, near-plane).
    • Included tests for winding order.
    • Included tests for barycentric coordinate validity.
    • Included tests for fragment world position and normal interpolation.
    • Included tests for batch rasterization.
    • Included tests for pixel-precise coverage.
    • Included tests for UV interpolation.
    • Included tests for fragment screen coordinates.
Activity
  • The author confirmed that all tests compile without warnings.
  • The author confirmed that ctest --output-on-failure passes all six test suites in 0.83 seconds.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent pull request that adds a comprehensive and well-designed invariant-based test suite. The 50+ new tests for math, rasterizer, and pipeline integration will significantly improve the project's robustness and make future development safer. The strategy of testing mathematical properties rather than hardcoded values is particularly effective.

My review includes a couple of suggestions for improvement:

  • In CMakeLists.txt, I recommend refactoring the test setup to reduce code duplication.
  • Across the new test files, I've noticed that floating-point comparisons often use inconsistent and sometimes overly loose tolerances. Tightening these and using shared constants would make the tests more robust and precise.

Overall, this is a fantastic contribution. The new tests are a major asset to the project.

CMakeLists.txt Outdated
Comment on lines +132 to +142
add_executable(test_math_invariants tests/test_math_invariants.cpp)
target_link_libraries(test_math_invariants PRIVATE soft_render)
add_test(NAME test_math_invariants COMMAND test_math_invariants)

add_executable(test_rasterizer tests/test_rasterizer.cpp)
target_link_libraries(test_rasterizer PRIVATE soft_render)
add_test(NAME test_rasterizer COMMAND test_rasterizer)

add_executable(test_pipeline_integration tests/test_pipeline_integration.cpp)
target_link_libraries(test_pipeline_integration PRIVATE soft_render)
add_test(NAME test_pipeline_integration COMMAND test_pipeline_integration)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and reduce code duplication, you could refactor the logic for adding tests into a CMake function. This would make it easier to add more tests in the future.

function(add_soft_render_test test_name)
    add_executable(${test_name} tests/${test_name}.cpp)
    target_link_libraries(${test_name} PRIVATE soft_render)
    add_test(NAME ${test_name} COMMAND ${test_name})
endfunction()

add_soft_render_test(test_math_invariants)
add_soft_render_test(test_rasterizer)
add_soft_render_test(test_pipeline_integration)

Comment on lines +37 to +40
static bool approx(float a, float b, float eps = EPS) { return std::abs(a - b) < eps; }
static bool approxVec3(const Vec3& a, const Vec3& b, float eps = EPS) {
return approx(a.x, b.x, eps) && approx(a.y, b.y, eps) && approx(a.z, b.z, eps);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The approx functions are great helpers for floating-point comparisons. However, many of the assert statements throughout this file use hardcoded, and sometimes quite large, tolerance values (e.g., 0.1f, 0.05f, 0.01f) instead of the default EPS (1e-4f). This inconsistency can make tests less precise and might hide subtle bugs.

Consider using the EPS constant more consistently for these checks. If different levels of precision are needed for different tests, it would be clearer to define named constants for them (e.g., ROUGH_EPS, MEDIUM_EPS).

Comment on lines +361 to +368
auto checker = [&](const Fragment& f) -> Color {
++fragment_count;
// Barycentric coords should sum to ~1
float sum = f.w0 + f.w1 + f.w2;
if (std::abs(sum - 1.0f) > 0.02f) all_valid = false;
// Each should be non-negative
if (f.w0 < -0.01f || f.w1 < -0.01f || f.w2 < -0.01f) all_valid = false;
return {f.w0, f.w1, f.w2};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In this test, and others in this file, the tolerances for floating-point checks are quite loose (e.g., 0.02f for barycentric coordinate sum, -0.01f for non-negativity). While floating-point arithmetic has precision limits, these values seem overly generous and might allow incorrect implementations to pass.

For example, the sum of barycentric coordinates should be very close to 1.0. A tolerance closer to the machine epsilon for floats (like 1e-6f) would make this test more robust. Consistently using stricter tolerances across the test suite would improve confidence in the implementation's correctness.

…erances

- Extract shared helpers (approx, PRNG, framebuffer inspection) into
  test_helpers.hpp to eliminate duplication across test files
- Use sr_add_test() CMake function to reduce CMakeLists.txt boilerplate
- Standardize tolerances: EPS (1e-4) for single ops, EPS_LOOSE (1e-2)
  for chained transforms — no more ad-hoc magic numbers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@EricBorges2019 EricBorges2019 merged commit d49a5e1 into main Mar 10, 2026
1 check passed
@EricBorges2019 EricBorges2019 deleted the feat/strong-test-suite branch March 10, 2026 23:34
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