
// g++ --std=c++11 test.cpp


#include "fl/gfx/splat.h"
#include "test.h"
#include "fl/math/geometry.h"
#include "fl/gfx/tile2x2.h"

FL_TEST_CASE("splat simple test") {
    // Define a simple input coordinate
    fl::vec2f input(0, 0);

    // Call the splat function
    fl::Tile2x2_u8 result = fl::splat(input);

    FL_REQUIRE(result.bounds().mMin.x == 0);
    FL_REQUIRE(result.bounds().mMin.y == 0);
    FL_REQUIRE(result.bounds().mMax.x == 2);
    FL_REQUIRE(result.bounds().mMax.y == 2);


    // Verify the output
    FL_REQUIRE_EQ(result.lower_left(), 255);  // Expected intensity for lower-left
    FL_REQUIRE_EQ(result.lower_right(), 0); // Expected intensity for lower-right
    FL_REQUIRE_EQ(result.upper_left(), 0);  // Expected intensity for upper-left
    FL_REQUIRE_EQ(result.upper_right(), 0); // Expected intensity for upper-right
}

FL_TEST_CASE("splat test for input (0.0, 0.5)") {
    // Define the input coordinate
    fl::vec2f input(0.0f, 0.5f);

    // Call the splat function
    fl::Tile2x2_u8 result = fl::splat(input);

    // Verify the bounds of the tile
    FL_REQUIRE(result.bounds().mMin.x == 0);
    FL_REQUIRE(result.bounds().mMin.y == 0);
    FL_REQUIRE(result.bounds().mMax.x == 2);
    FL_REQUIRE(result.bounds().mMax.y == 2);

    // Verify the output intensities
    FL_REQUIRE_EQ(result.lower_left(), 128);  // Expected intensity for lower-left
    FL_REQUIRE_EQ(result.lower_right(), 0);   // Expected intensity for lower-right
    FL_REQUIRE_EQ(result.upper_left(), 128);  // Expected intensity for upper-left
    FL_REQUIRE_EQ(result.upper_right(), 0);   // Expected intensity for upper-right
}

FL_TEST_CASE("splat test for input (0.0, 0.99)") {
    // Define the input coordinate
    fl::vec2f input(0.0f, 0.99f);

    // Call the splat function
    fl::Tile2x2_u8 result = fl::splat(input);

    // Verify the bounds of the tile
    FL_REQUIRE(result.bounds().mMin.x == 0);
    FL_REQUIRE(result.bounds().mMin.y == 0);
    FL_REQUIRE(result.bounds().mMax.x == 2);
    FL_REQUIRE(result.bounds().mMax.y == 2);

    // Verify the output intensities
    FL_REQUIRE_EQ(result.lower_left(), 3);    // Expected intensity for lower-left
    FL_REQUIRE_EQ(result.lower_right(), 0);   // Expected intensity for lower-right
    FL_REQUIRE_EQ(result.upper_left(), 252);  // Expected intensity for upper-left
    FL_REQUIRE_EQ(result.upper_right(), 0);   // Expected intensity for upper-right
}

FL_TEST_CASE("splat test for input (0.0, 1.0)") {
    // Define the input coordinate
    fl::vec2f input(0.0f, 1.0f);

    // Call the splat function
    fl::Tile2x2_u8 result = fl::splat(input);

    // Verify the bounds of the tile
    FL_REQUIRE(result.bounds().mMin.x == 0);
    FL_REQUIRE(result.bounds().mMin.y == 1);
    FL_REQUIRE(result.bounds().mMax.x == 2);
    FL_REQUIRE(result.bounds().mMax.y == 3);

    // Verify the output intensities
    FL_REQUIRE_EQ(result.lower_left(), 255);    // Expected intensity for lower-left
    FL_REQUIRE_EQ(result.lower_right(), 0);   // Expected intensity for lower-right
    FL_REQUIRE_EQ(result.upper_left(), 0);   // Expected intensity for upper-left
    FL_REQUIRE_EQ(result.upper_right(), 0);   // Expected intensity for upper-right
}

FL_TEST_CASE("splat test for input (0.5, 0.0)") {
    // Define the input coordinate
    fl::vec2f input(0.5f, 0.0f);

    // Call the splat function
    fl::Tile2x2_u8 result = fl::splat(input);

    // Verify the bounds of the tile
    FL_REQUIRE(result.bounds().mMin.x == 0);
    FL_REQUIRE(result.bounds().mMin.y == 0);
    FL_REQUIRE(result.bounds().mMax.x == 2);
    FL_REQUIRE(result.bounds().mMax.y == 2);

    // Verify the output intensities
    FL_REQUIRE_EQ(result.lower_left(), 128);  // Expected intensity for lower-left
    FL_REQUIRE_EQ(result.lower_right(), 128); // Expected intensity for lower-right
    FL_REQUIRE_EQ(result.upper_left(), 0);    // Expected intensity for upper-left
    FL_REQUIRE_EQ(result.upper_right(), 0);   // Expected intensity for upper-right
}

FL_TEST_CASE("splat test for input (0.99, 0.0)") {
    // Define the input coordinate
    fl::vec2f input(0.99f, 0.0f);

    // Call the splat function
    fl::Tile2x2_u8 result = fl::splat(input);

    // Verify the bounds of the tile
    FL_REQUIRE(result.bounds().mMin.x == 0);
    FL_REQUIRE(result.bounds().mMin.y == 0);
    FL_REQUIRE(result.bounds().mMax.x == 2);
    FL_REQUIRE(result.bounds().mMax.y == 2);

    // Verify the output intensities
    FL_REQUIRE_EQ(result.lower_left(), 3);    // Expected intensity for lower-left
    FL_REQUIRE_EQ(result.lower_right(), 252); // Expected intensity for lower-right
    FL_REQUIRE_EQ(result.upper_left(), 0);    // Expected intensity for upper-left
    FL_REQUIRE_EQ(result.upper_right(), 0);   // Expected intensity for upper-right
}

FL_TEST_CASE("splat test for input (1.0, 0.0)") {
    // Define the input coordinate
    fl::vec2f input(1.0f, 0.0f);

    // Call the splat function
    fl::Tile2x2_u8 result = fl::splat(input);

    // Verify the bounds of the tile
    FL_REQUIRE(result.bounds().mMin.x == 1);
    FL_REQUIRE(result.bounds().mMin.y == 0);
    FL_REQUIRE(result.bounds().mMax.x == 3);
    FL_REQUIRE(result.bounds().mMax.y == 2);

    // Verify the output intensities
    FL_REQUIRE_EQ(result.lower_left(), 255);    // Expected intensity for lower-left
    FL_REQUIRE_EQ(result.lower_right(), 0); // Expected intensity for lower-right
    FL_REQUIRE_EQ(result.upper_left(), 0);    // Expected intensity for upper-left
    FL_REQUIRE_EQ(result.upper_right(), 0);   // Expected intensity for upper-right
}
