<commit_before>#include "../third_party/catch/catch.hpp"
#include "../vis/image.hpp"

SCENARIO ("An image with illegal width or height")
{
    GIVEN ("An image with illegal width")
    {
        WHEN ("Calling the constructor")
        {
            THEN ("An exception should be thrown")
            {
                REQUIRE_THROWS_AS(vis::Image i (0, 200), std::length_error);
            }
        }
    }

    GIVEN ("An image with illegal height")
    {
        WHEN ("Calling the constructor")
        {
            THEN ("An exception should be thrown")
            {
                REQUIRE_THROWS_AS(vis::Image i (200, 0), std::length_error);
            }
        }
    }

    GIVEN ("An image with illegal width and height")
    {
        WHEN ("Calling the constructor")
        {
            THEN ("An exception should be thrown")
            {
                REQUIRE_THROWS_AS(vis::Image i (0, 0), std::length_error);
            }
        }
    }
}

SCENARIO ("An image with legal width and height")
{
    GIVEN ("An image with legal width and height")
    {
        vis::Image img (200, 300);

        WHEN ("Accessing its width")
        {
            size_t const w = img.getWidth();
            THEN ("the correct value should be returned")
            {
                REQUIRE(w == 200);
            }
        }

        WHEN ("Accessing its height")
        {
            size_t const h = img.getHeight();
            THEN ("the correct value should be returned")
            {
                REQUIRE(h == 300);
            }
        }

        WHEN ("No values have been written yet")
        {
            THEN ("All values should be zero (black)")
            {
                bool allZero = true;
                for (size_t x = 0; x < img.getWidth(); ++x)
                {
                    for (size_t y = 0; y < img.getHeight(); ++y)
                    {
                        vis::color const c = img(x,y);
                        if (c.R != 0 || c.G != 0 || c.B != 0)
                        {
                            allZero = false;
                        }
                    }
                }
                REQUIRE(allZero);
            }
        }

        WHEN ("Having written one value")
        {
            vis::color c;
            c.R = 255;
            c.B = 0;
            c.G = 127;
            img(100, 150) = c;

            THEN ("This value should be correct")<commit_msg>Added test for one parameter Image ctor<commit_after>#include "../third_party/catch/catch.hpp"
#include "../vis/image.hpp"

SCENARIO ("An image with illegal width or height")
{
    GIVEN ("An image with illegal width")
    {
        WHEN ("Calling the constructor")
        {
            THEN ("An exception should be thrown")
            {
                REQUIRE_THROWS_AS(vis::Image i (0, 200), std::length_error);
            }
        }
    }

    GIVEN ("An image with illegal height")
    {
        WHEN ("Calling the constructor")
        {
            THEN ("An exception should be thrown")
            {
                REQUIRE_THROWS_AS(vis::Image i (200, 0), std::length_error);
            }
        }
    }

    GIVEN ("An image with illegal width and height")
    {
        WHEN ("Calling the one parameter constructor")
        {
            THEN ("An exception should be thrown")
            {
                REQUIRE_THROWS_AS(vis::Image i (0), std::length_error);
            }
        }
    }

    GIVEN ("An image with illegal width and height")
    {
        WHEN ("Calling the two parameter constructor")
        {
            THEN ("An exception should be thrown")
            {
                REQUIRE_THROWS_AS(vis::Image i (0, 0), std::length_error);
            }
        }
    }
}

SCENARIO ("An image with legal width and height")
{
    GIVEN ("An image with legal width and height")
    {
        vis::Image img (200, 300);

        WHEN ("Accessing its width")
        {
            size_t const w = img.getWidth();
            THEN ("the correct value should be returned")
            {
                REQUIRE(w == 200);
            }
        }

        WHEN ("Accessing its height")
        {
            size_t const h = img.getHeight();
            THEN ("the correct value should be returned")
            {
                REQUIRE(h == 300);
            }
        }

        WHEN ("No values have been written yet")
        {
            THEN ("All values should be zero (black)")
            {
                bool allZero = true;
                for (size_t x = 0; x < img.getWidth(); ++x)
                {
                    for (size_t y = 0; y < img.getHeight(); ++y)
                    {
                        vis::color const c = img(x,y);
                        if (c.R != 0 || c.G != 0 || c.B != 0)
                        {
                            allZero = false;
                        }
                    }
                }
                REQUIRE(allZero);
            }
        }

        WHEN ("Having written one value")
        {
            vis::color c (255, 0, 127);
            img(100, 150) = c;

            THEN ("This value should be correct")
{'fraction_non_alphanumeric': 0.10900290416263311, 'fraction_numerical': 0.01568247821878025, 'mean_word_length': 1.1569937369519834, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4592565', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1411, 'n_words': 424}