ray-tracer-challenge/test/test_materials.c
2024-08-05 21:26:44 -05:00

106 lines
3.3 KiB
C

#include <stdbool.h>
#include <stdio.h>
#include "materials.h"
#include "runner.h"
#include "lights.h"
static bool materials_test_0(const char ** scenario)
{
*scenario = "The default material";
struct material m = material();
return
tuple_equal(m.color, color(1.0f, 1.0f, 1.0f)) &&
float_equal(m.ambient, 0.1f) &&
float_equal(m.diffuse, 0.9f) &&
float_equal(m.specular, 0.9f) &&
float_equal(m.shininess, 200.0f);
}
static bool materials_test_1(const char ** scenario)
{
*scenario = "Lighting with the eye between the light and the surface";
struct material m = material();
struct tuple position = point(0.0f, 0.0f, 0.0f);
struct tuple eyev = vector(0.0f, 0.0f, -1.0f);
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
struct light light = point_light(point(0.0f, 0.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
struct tuple result = lighting(m, light, position, eyev, normalv);
return tuple_equal(result, color(1.9f, 1.9f, 1.9f));
}
static bool materials_test_2(const char ** scenario)
{
*scenario = "Lighting with the eye between the light and surface, eye offset 45 degrees";
struct material m = material();
struct tuple position = point(0.0f, 0.0f, 0.0f);
struct tuple eyev = vector(0.0f, 0.7071067811865476, -0.7071067811865476);
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
struct light light = point_light(point(0.0f, 0.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
struct tuple result = lighting(m, light, position, eyev, normalv);
return tuple_equal(result, color(1.0f, 1.0f, 1.0f));
}
static bool materials_test_3(const char ** scenario)
{
*scenario = "Lighting with eye opposite surface, light offset 45 degress";
struct material m = material();
struct tuple position = point(0.0f, 0.0f, 0.0f);
struct tuple eyev = vector(0.0f, 0.0f, -1.0f);
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
struct light light = point_light(point(0.0f, 10.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
struct tuple result = lighting(m, light, position, eyev, normalv);
return tuple_equal(result, color(0.7364f, 0.7364f, 0.7364f));
}
static bool materials_test_4(const char ** scenario)
{
*scenario = "Lighting with eye in the path of the reflection vector";
struct material m = material();
struct tuple position = point(0.0f, 0.0f, 0.0f);
struct tuple eyev = vector(0.0f, -0.7071067811865476, -0.7071067811865476);
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
struct light light = point_light(point(0.0f, 10.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
struct tuple result = lighting(m, light, position, eyev, normalv);
return tuple_equal(result, color(1.63639, 1.63639, 1.63639));
}
static bool materials_test_5(const char ** scenario)
{
*scenario = "Lighting with the light behind the surface";
struct material m = material();
struct tuple position = point(0.0f, 0.0f, 0.0f);
struct tuple eyev = vector(0.0f, 0.0f, -1.0f);
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
struct light light = point_light(point(0.0f, 0.0f, 10.0f), color(1.0f, 1.0f, 1.0f));
struct tuple result = lighting(m, light, position, eyev, normalv);
return tuple_equal(result, color(0.1f, 0.1f, 0.1f));
}
test_t materials_tests[] = {
materials_test_0,
materials_test_1,
materials_test_2,
materials_test_3,
materials_test_4,
materials_test_5,
};
RUNNER(materials_tests)