Compare commits

..

No commits in common. "2010faadd6c6134a6229beb84ca566d373ae0f68" and "6d885040f3cd4d45cf6094183917df819783c7f3" have entirely different histories.

5 changed files with 9 additions and 104 deletions

2
.gitignore vendored
View file

@ -5,5 +5,3 @@ docs
zig-out
zig-cache
.zig-cache
*.o
*.elf

View file

@ -1,20 +0,0 @@
when:
- event: push
branch: master
steps:
- name: build
image: debian
commands:
- apt update
- apt install libcmocka-dev -y
- apt install gcc -y
- apt install make -y
- make -j$(nproc) test/test.elf
- name: run-tests
image: debian
commands:
- apt update
- apt install libcmocka0 -y
- ./test/test.elf

View file

@ -1,10 +1,10 @@
# Compiler
CC ?= gcc
CC := gcc
GITHASH := $(shell git rev-parse --short HEAD)
# GITHASH := $(shell git rev-parse --short HEAD | echo "")
#
# Compiler flags
CFLAGS := -Wall -Wextra -Wpedantic -Wunused -std=c99 -Isrc
CFLAGS := -Wall -Wextra -Wpedantic -std=c2x
# Directories
SRC_DIR := src
@ -25,14 +25,6 @@ TARGET := $(BUILD_DIR)/CTree
# Default target
all: $(TARGET)
test/test.o: test/test.c
test/test.elf: test/test.o src/tree.o
$(CC) $(CFLAGS) $^ -o $@
test: test/test.elf
./test/test.elf
# Rule to build the target executable
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $^ -o $@
@ -49,17 +41,18 @@ run: $(TARGET)
fmt:
clang-format -i $(SRCS) $(HEADERS)
# Clean rule
clean:
rm -rf $(BUILD_DIR) $(TARGET) test/test.o tester docs
rm -rf $(BUILD_DIR) $(TARGET)
docs:
PROJECT_NUMBER=git-$(GITHASH) doxygen Doxyfile
cppcheck:
cppcheck --enable=all --inconclusive --std=c99 --language=c --platform=unix64 --suppress=missingIncludeSystem $(SRCS) test/test.c
cppcheck --enable=all --inconclusive --std=c11 --language=c --platform=unix64 --suppress=missingIncludeSystem $(SRCS)
valgrind: $(TARGET)
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(TARGET)
# Mark rules as phony
.PHONY: all run clean docs docs test
.PHONY: all run clean docs docs

View file

@ -56,4 +56,4 @@ bool tree_contains(Node *node, int data);
// Print the tree in order
void tree_inorder(Node *node);
#endif // TREE_H
#endif // TREE_H

View file

@ -1,66 +0,0 @@
#include "tree.h"
// Function prototypes for helper functions
void test_insert(Tree *tree);
void test_remove(Tree *tree);
void test_contains(Tree *tree);
void test_inorder(Tree *tree);
int main() {
Tree tree = { .root = NULL };
printf("\n-- Testing Insert --\n");
test_insert(&tree);
printf("\n-- Testing Contains --\n");
test_contains(&tree);
printf("\n-- Testing Inorder Traversal --\n");
test_inorder(&tree);
printf("\n-- Testing Remove --\n");
test_remove(&tree);
printf("\n-- Clearing Tree --\n");
tree_clear(&tree);
printf("Tree cleared.\n");
return 0;
}
void test_insert(Tree *tree) {
int values[] = {10, 5, 15, 3, 7, 12, 18};
for (int i = 0; i < 7; i++) {
printf("Inserting %d\n", values[i]);
tree_insert(tree, values[i]);
}
}
void test_remove(Tree *tree) {
int values_to_remove[] = {15, 5, 10};
for (int i = 0; i < 3; i++) {
printf("Removing %d\n", values_to_remove[i]);
if (tree_remove(&tree->root, values_to_remove[i]) == 0) {
printf("Successfully removed %d\n", values_to_remove[i]);
} else {
printf("Failed to remove %d\n", values_to_remove[i]);
}
}
printf("Remaining elements (in-order traversal):\n");
tree_inorder(tree->root);
printf("\n");
}
void test_contains(Tree *tree) {
int values_to_check[] = {7, 15, 20};
for (int i = 0; i < 3; i++) {
printf("Checking if tree contains %d: %s\n", values_to_check[i],
tree_contains(tree->root, values_to_check[i]) ? "Yes" : "No");
}
}
void test_inorder(Tree *tree) {
printf("Tree elements (in-order traversal):\n");
tree_inorder(tree->root);
printf("\n");
}