54 lines
1.2 KiB
C
54 lines
1.2 KiB
C
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
#include "canvas.h"
|
|
#include "runner.h"
|
|
|
|
static bool canvas_test_0(const char ** scenario)
|
|
{
|
|
*scenario = "Creating a canvas";
|
|
|
|
struct canvas c = canvas(10, 20);
|
|
bool zeroized = true;
|
|
for (int i = 0; i < c.width * c.height; i++) {
|
|
zeroized &= tuple_equal(c.pixels[i], color(0.0f, 0.0f, 0.0f));
|
|
}
|
|
return
|
|
c.width == 10 &&
|
|
c.height == 20 &&
|
|
zeroized;
|
|
}
|
|
|
|
static bool canvas_test_1(const char ** scenario)
|
|
{
|
|
*scenario = "Writing pixels to the screen";
|
|
|
|
struct canvas c = canvas(10, 20);
|
|
struct tuple red = color(1.0f, 0.0f, 0.0f);
|
|
canvas_write_pixel(&c, 2, 3, red);
|
|
return tuple_equal(canvas_pixel_at(&c, 2, 3), red);
|
|
}
|
|
|
|
static bool canvas_test_2(const char ** scenario)
|
|
{
|
|
*scenario = "PPM image";
|
|
|
|
struct canvas c = canvas(5, 3);
|
|
struct tuple c1 = color(1.5f, 0.0f, 0.0f);
|
|
struct tuple c2 = color(0.0f, 0.5f, 0.0f);
|
|
struct tuple c3 = color(-0.5f, 0.0f, 1.0f);
|
|
canvas_write_pixel(&c, 0, 0, c1);
|
|
canvas_write_pixel(&c, 2, 1, c2);
|
|
canvas_write_pixel(&c, 4, 2, c3);
|
|
canvas_to_ppm(&c, "canvas_test_2.ppm");
|
|
return true;
|
|
}
|
|
|
|
test_t canvas_tests[] = {
|
|
canvas_test_0,
|
|
canvas_test_1,
|
|
canvas_test_2,
|
|
};
|
|
|
|
RUNNER(canvas_tests)
|