LCOV - code coverage report
Current view: top level - test - sphere.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 52 52
Test Date: 2026-04-03 02:26:39 Functions: 100.0 % 2 2

            Line data    Source code
       1              : #include "catch.hpp"
       2              : #include "Sphere.h"
       3              : #include "Vector.h"
       4              : 
       5            5 : SCENARIO( "Sphere", "[Sphere]" ) {
       6            5 :   GIVEN( "Default sphere" ) {
       7            1 :     Sphere s;
       8            1 :     Vector o;
       9            1 :     s.getOriginVector(o);
      10              : 
      11            2 :     THEN( "origin and radius are zero" ) {
      12            1 :       REQUIRE(o.x == Approx(0.0f));
      13            1 :       REQUIRE(o.y == Approx(0.0f));
      14            1 :       REQUIRE(o.z == Approx(0.0f));
      15            1 :       REQUIRE(s.getRadius() == Approx(0.0f));
      16            1 :     }
      17            1 :   }
      18              : 
      19            5 :   GIVEN( "Sphere set via setSphere" ) {
      20            1 :     Sphere s;
      21            1 :     s.setSphere(1.0f, -2.0f, 3.5f, 4.25f);
      22            1 :     Vector o;
      23            1 :     s.getOriginVector(o);
      24              : 
      25            2 :     THEN( "origin and radius match" ) {
      26            1 :       REQUIRE(o.x == Approx(1.0f));
      27            1 :       REQUIRE(o.y == Approx(-2.0f));
      28            1 :       REQUIRE(o.z == Approx(3.5f));
      29            1 :       REQUIRE(s.getRadius() == Approx(4.25f));
      30            1 :     }
      31            1 :   }
      32              : 
      33            5 :   GIVEN( "setOriginVector from Vector" ) {
      34            1 :     Sphere s;
      35            1 :     Vector v(9.0f, 8.0f, 7.0f);
      36            1 :     s.setOriginVector(v);
      37            1 :     Vector o;
      38            1 :     s.getOriginVector(o);
      39              : 
      40            2 :     THEN( "origin copies vector and radius remains zero" ) {
      41            1 :       REQUIRE(o.x == Approx(9.0f));
      42            1 :       REQUIRE(o.y == Approx(8.0f));
      43            1 :       REQUIRE(o.z == Approx(7.0f));
      44            1 :       REQUIRE(s.getRadius() == Approx(0.0f));
      45            1 :     }
      46            1 :   }
      47              : 
      48              :   // ModelGameObject sets a radius via setSphere during model load, then
      49              :   // updates position via setOriginVector each frame. Radius must survive
      50              :   // the position update or Frustum::testSphere will use a stale value.
      51            5 :   GIVEN( "setSphere followed by setOriginVector" ) {
      52            1 :     Sphere s;
      53            1 :     s.setSphere(0.0f, 0.0f, 0.0f, 5.0f);
      54            1 :     Vector v(1.0f, 2.0f, 3.0f);
      55            1 :     s.setOriginVector(v);
      56            1 :     Vector o;
      57            1 :     s.getOriginVector(o);
      58              : 
      59            2 :     THEN( "origin is updated and radius is preserved" ) {
      60            1 :       REQUIRE(o.x == Approx(1.0f));
      61            1 :       REQUIRE(o.y == Approx(2.0f));
      62            1 :       REQUIRE(o.z == Approx(3.0f));
      63            1 :       REQUIRE(s.getRadius() == Approx(5.0f));
      64            1 :     }
      65            1 :   }
      66            4 : }
        

Generated by: LCOV version 2.4-0