// Pruebas de regions.c. Agreguen las suyas, con estas como modelo.
#include <assert.h>
#include <stdio.h>

#include "image.h"
#include "regions.h"

// Crea una imagen desde números: rows tiene width * height valores, fila por fila.
static Image *image_from(int width, int height, const int rows[]) {
    Image *img = image_new(width, height, IMAGE_MAX_VALUE, 0);
    assert(img != NULL);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            image_set(img, x, y, rows[y * width + x]);
        }
    }
    return img;
}

static void test_fill_stops_at_the_border_of_the_region(void) {
    const int rows[] = {
        1, 1, 0,
        0, 1, 0,
        1, 0, 0,
    };
    Image *img = image_from(3, 3, rows);

    flood_fill(img, 0, 0, 9);

    assert(image_get(img, 0, 0) == 9);
    assert(image_get(img, 1, 0) == 9);
    assert(image_get(img, 1, 1) == 9);
    assert(image_get(img, 2, 0) == 0);
    assert(image_get(img, 0, 2) == 1); // solo toca a la región por una diagonal
    image_free(img);
}

static void test_count_regions_sees_diagonals_as_separate(void) {
    const int rows[] = {
        1, 0,
        0, 1,
    };
    Image *img = image_from(2, 2, rows);

    assert(count_regions(img) == 4);
    image_free(img);
}

int main(void) {
    test_fill_stops_at_the_border_of_the_region();
    test_count_regions_sees_diagonals_as_separate();
    printf("pruebas de regiones: ok\n");
    return 0;
}
