commit 004a4ea4ddfaac30a4a426d4a6d8bba0e92ddde7
parent a92a02c13b9e120340cbe766e6ced0cbd601b359
Author: Andrew Laack <andrew@laack.co>
Date: Wed, 16 Sep 2026 10:31:46 -0500
Fixed compiler warnings, refactored makefile
Diffstat:
5 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,23 +1,31 @@
include config.mk
-
+# building actual program
build:
${COMMAND_P} src/main.cpp ${COMMAND_S} -o abg.out
install: build
cp abg.out /usr/local/bin/abg
clean:
rm abg.out
+
+# snapshot update
update-snapshot:
${TCOMMAND_P} tests/snapshot_update.cpp ${TCOMMAND_S} -o snapshot_update
./snapshot_update
rm snapshot_update
-test:
+
+# tests
+snapshot-test:
${TCOMMAND_P} tests/snapshot_test.cpp ${TCOMMAND_S} -o snapshot_tests
./snapshot_tests
rm snapshot_tests
+graph-test:
${TCOMMAND_P} tests/graph_test.cpp ${TCOMMAND_S} -o graph_tests
./graph_tests
rm graph_tests
+algo-test:
${TCOMMAND_P} tests/algo_test.cpp ${TCOMMAND_S} -o algo_tests
./algo_tests
rm algo_tests
+
+test: snapshot-test graph-test algo-test
diff --git a/config.mk b/config.mk
@@ -12,8 +12,8 @@ TLIBS = -lCatch2Main -lCatch2 ${LIBS}
# compiler
CC = g++
-CFLAGS = -Ofast -pedantic -Wall -Wno-deprecated-declarations -Os
-CTFLAGS = -O0 -pedantic -Wall -Wno-deprecated-declarations -Os
+CFLAGS = -Ofast -std=c++23 -Wpedantic -Wall -Werror -Wextra -Wno-deprecated-declarations -Os
+CTFLAGS = -fsanitize=address,undefined -O0 -std=c++23 -Wpedantic -Wall -Werror -Wextra -Wno-deprecated-declarations -Os
BASE_FILES = src/prim.cpp src/graph.cpp src/edge.cpp src/utils.cpp src/vertex.cpp src/background.cpp
diff --git a/include/edge.hpp b/include/edge.hpp
@@ -6,10 +6,10 @@ class Edge {
public:
// indices of v1 and v2
Edge(std::size_t v1, std::size_t v2, double length2, std::size_t identifier);
- std::size_t identifier;
std::size_t v1Index;
std::size_t v2Index;
double length2;
+ std::size_t identifier;
bool traversed = false;
std::string toString() const noexcept;
bool operator<(const Edge &other) const;
diff --git a/src/main.cpp b/src/main.cpp
@@ -66,9 +66,7 @@ int main(int argc, char **argv) {
InitWindow(xMax, yMax, "abg");
sendToBg("abg");
- int count = 0;
while (!WindowShouldClose()) {
- count += 1;
Graph g = Graph(edgeCount, vertexCount, xMax, yMax);
std::unordered_set<std::size_t> visitedIndices{};
diff --git a/tests/graph_test.cpp b/tests/graph_test.cpp
@@ -10,10 +10,8 @@ TEST_CASE("Graph traversal invariants", "[graph traversal]") {
float xMax = 10;
float yMax = 10;
auto g = Graph(edgeCount, vertCount, xMax, yMax);
- int count = 0;
for (int i = 0; i < vertCount; ++i) {
g.traverseVertexIdx(i);
- count += 1;
}
for (int i = 0; i < vertCount; ++i) {
REQUIRE(g.getVertex(i).visited);
@@ -23,7 +21,7 @@ TEST_CASE("Graph traversal invariants", "[graph traversal]") {
try {
g.getVertex(vertCount + 1);
- } catch (std::invalid_argument e) {
+ } catch (std::invalid_argument& e) {
error = true;
}
@@ -43,7 +41,7 @@ TEST_CASE("Graph gracefully handles stupid fucking inputs",
try {
createGraph(vertCount, edgeCount);
- } catch (std::invalid_argument e) {
+ } catch (std::invalid_argument& e) {
error = true;
}
REQUIRE(!error);
@@ -54,7 +52,7 @@ TEST_CASE("Graph gracefully handles stupid fucking inputs",
error = false;
try {
createGraph(vertCount, edgeCount);
- } catch (std::invalid_argument e) {
+ } catch (std::invalid_argument& e) {
error = true;
}
@@ -111,8 +109,8 @@ TEST_CASE("Graph vertex and edge counts", "[graph counts]") {
for (int i = 2; i < 100; ++i) {
for (int x = 1; x < 10; ++x) {
- int vertCount = i;
- int edgeCount = x;
+ std::size_t vertCount = i;
+ std::size_t edgeCount = x;
float xMax = 10;
float yMax = 10;