Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions tests/test_framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include "soft_render/core/framebuffer.hpp"
#include "soft_render/math/vec3.hpp"

using std::cout;
using std::endl;
using namespace sr::core;
using namespace sr::math;

void test_framebuffer_clear() {
std::cout << "Running test_framebuffer_clear..." << std::endl;
cout << "Running test_framebuffer_clear..." << endl;

int width = 10;
int height = 10;
Expand All @@ -26,7 +28,7 @@ void test_framebuffer_clear() {
assert(pixels[i].a == 255);
assert(depth[i] == std::numeric_limits<float>::infinity());
}
std::cout << " Default clear passed" << std::endl;
cout << " Default clear passed" << endl;

// Test clear with custom color
Color customColor(1.0f, 0.5f, 0.25f);
Expand All @@ -39,7 +41,7 @@ void test_framebuffer_clear() {
assert(pixels[i].a == 255);
assert(depth[i] == std::numeric_limits<float>::infinity());
}
std::cout << " Custom color clear passed" << std::endl;
cout << " Custom color clear passed" << endl;

// Test clear with out-of-bounds color values
Color outOfBoundsColor(1.5f, -0.5f, 2.0f);
Expand All @@ -52,20 +54,20 @@ void test_framebuffer_clear() {
assert(pixels[i].a == 255);
assert(depth[i] == std::numeric_limits<float>::infinity());
}
std::cout << " Out-of-bounds color clear passed" << std::endl;
cout << " Out-of-bounds color clear passed" << endl;

// Test depth test modifying depth, then clear
fb.depthTest(0, 0, 0.5f);
assert(fb.getDepth(0, 0) == 0.5f);
fb.clear();
assert(fb.getDepth(0, 0) == std::numeric_limits<float>::infinity());
std::cout << " Depth buffer reset passed" << std::endl;
cout << " Depth buffer reset passed" << endl;

std::cout << "test_framebuffer_clear passed!" << std::endl;
cout << "test_framebuffer_clear passed!" << endl;
}

int main() {
test_framebuffer_clear();
std::cout << "All tests passed!" << std::endl;
cout << "All tests passed!" << endl;
return 0;
}
26 changes: 14 additions & 12 deletions tests/test_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include <cassert>
#include <cmath>

using std::cout;
using std::endl;
using namespace sr::math;

void test_vec4_perspective() {
std::cout << "Running test_vec4_perspective..." << std::endl;
cout << "Running test_vec4_perspective..." << endl;

// Case 1: w = 1.0 (Identity)
{
Expand All @@ -16,7 +18,7 @@ void test_vec4_perspective() {
assert(p.x == 1.0f);
assert(p.y == 2.0f);
assert(p.z == 3.0f);
std::cout << " w=1.0 passed" << std::endl;
cout << " w=1.0 passed" << endl;
}

// Case 2: w = 2.0 (Divide by 2)
Expand All @@ -26,7 +28,7 @@ void test_vec4_perspective() {
assert(p.x == 0.5f);
assert(p.y == 1.0f);
assert(p.z == 2.0f);
std::cout << " w=2.0 passed" << std::endl;
cout << " w=2.0 passed" << endl;
}

// Case 3: w = -1.0 (Negative w)
Expand All @@ -36,7 +38,7 @@ void test_vec4_perspective() {
assert(p.x == -1.0f);
assert(p.y == 2.0f);
assert(p.z == -3.0f);
std::cout << " w=-1.0 passed" << std::endl;
cout << " w=-1.0 passed" << endl;
}

// Case 4: w = 0.0 (Division by zero - should result in inf/nan)
Expand All @@ -46,14 +48,14 @@ void test_vec4_perspective() {
assert(std::isinf(p.x) || std::isnan(p.x));
assert(std::isinf(p.y) || std::isnan(p.y));
assert(std::isinf(p.z) || std::isnan(p.z));
std::cout << " w=0.0 passed (inf/nan handled)" << std::endl;
cout << " w=0.0 passed (inf/nan handled)" << endl;
}

std::cout << "test_vec4_perspective passed!" << std::endl;
cout << "test_vec4_perspective passed!" << endl;
}

void test_mat4_multiplication() {
std::cout << "Running test_mat4_multiplication..." << std::endl;
cout << "Running test_mat4_multiplication..." << endl;

// Case 1: Identity * A = A
{
Expand All @@ -70,7 +72,7 @@ void test_mat4_multiplication() {
assert(std::abs(result(i, j) - A(i, j)) < 1e-5f);
}
}
std::cout << " Identity * A passed" << std::endl;
cout << " Identity * A passed" << endl;
}

// Case 2: A * Identity = A
Expand All @@ -88,7 +90,7 @@ void test_mat4_multiplication() {
assert(std::abs(result(i, j) - A(i, j)) < 1e-5f);
}
}
std::cout << " A * Identity passed" << std::endl;
cout << " A * Identity passed" << endl;
}

// Case 3: A * B
Expand Down Expand Up @@ -118,15 +120,15 @@ void test_mat4_multiplication() {
assert(std::abs(result(i, j) - expected(i, j)) < 1e-5f);
}
}
std::cout << " A * B passed" << std::endl;
cout << " A * B passed" << endl;
}

std::cout << "test_mat4_multiplication passed!" << std::endl;
cout << "test_mat4_multiplication passed!" << endl;
}

int main() {
test_vec4_perspective();
test_mat4_multiplication();
std::cout << "All tests passed!" << std::endl;
cout << "All tests passed!" << endl;
return 0;
}
4 changes: 3 additions & 1 deletion tests/test_vec3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <iostream>
#include "soft_render/math/vec3.hpp"

using std::cout;
using std::endl;
using namespace sr::math;

void test_vec3_cross() {
Expand Down Expand Up @@ -34,7 +36,7 @@ void test_vec3_cross() {
Vec3 a_cross_b = a.cross(b);
assert(a_cross_b.x == -3 && a_cross_b.y == 6 && a_cross_b.z == -3);

std::cout << "All Vec3 cross tests passed!" << std::endl;
cout << "All Vec3 cross tests passed!" << endl;
}

int main() {
Expand Down