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
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,18 @@ src/shader_utils.o: src/shader_utils.c include/shader_utils.h
src/controls.o: src/controls.c include/controls.h include/particle.h
$(CC) $(CFLAGS) -c -o $@ $<

TEST_OBJ = tests/test_quadtree.o src/quadtree.o
TEST_BIN = tests/test_quadtree
TEST_LDFLAGS = -lm

$(TEST_BIN): $(TEST_OBJ)
$(CC) -o $@ $(TEST_OBJ) $(TEST_LDFLAGS)

tests/test_quadtree.o: tests/test_quadtree.c include/quadtree.h include/particle_struct.h
$(CC) $(CFLAGS) -c -o $@ $<

test: $(TEST_BIN)
./$(TEST_BIN)

clean:
rm -f src/*.o gravity_simulation
rm -f src/*.o $(OBJ) gravity_simulation $(TEST_BIN) tests/*.o
21 changes: 21 additions & 0 deletions tests/test_quadtree.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "quadtree.h"
#include <stdio.h>

int main() {
QuadNode* root = createNode(0.0f, 0.0f, 1.0f, 1.0f);
if (!root) {
fprintf(stderr, "Failed to create root node\n");
return 1;
}
if (root->minX != 0.0f || root->minY != 0.0f || root->maxX != 1.0f || root->maxY != 1.0f) {
fprintf(stderr, "Node bounds incorrect\n");
return 1;
}
if (root->centerX != 0.5f || root->centerY != 0.5f) {
fprintf(stderr, "Node center incorrect\n");
return 1;
}
freeQuadtree(root);
printf("test_quadtree passed\n");
return 0;
}
Loading