commit e9a6df1c5bb43f6588db75b7870b5499d495d365
parent 4206dceba3c31cb5e99338f6639b749a2761cd24
Author: Andrew Laack <andrew@laack.co>
Date: Wed, 16 Sep 2026 01:05:25 -0500
Finished adding basic snapshot test
Diffstat:
3 files changed, 65 insertions(+), 52 deletions(-)
diff --git a/tests/snapshot_shared.cpp b/tests/snapshot_shared.cpp
@@ -0,0 +1,42 @@
+#include "../include/graph.hpp"
+#include <catch2/catch_test_macros.hpp>
+#include "../include/prim.hpp"
+#include <queue>
+#include <unordered_set>
+
+Graph basicGraphSerialization() {
+ srand(42);
+ int vertCount = 10;
+ int edgeCount = 10;
+ float xMax = 10;
+ float yMax = 10;
+ auto g = Graph(edgeCount,vertCount,xMax,yMax);
+ return g;
+}
+
+Graph fullTraversalSerialization() {
+ srand(42);
+ std::size_t edgeCount = 1;
+ std::size_t vertCount = 2;
+
+ float xMax = 5120;
+ float yMax = 1440;
+
+ Graph g = Graph(edgeCount, vertCount, xMax,yMax);
+ std::unordered_set<std::size_t> visitedIndices {};
+ std::priority_queue<Edge, std::vector<Edge>, std::greater<Edge>> toVisit {};
+ std::vector<Edge> edges = g.getEdgesOfVertexIdx(0);
+
+ for(auto edge: edges) {
+ toVisit.push(edge);
+ }
+
+ g.traverseVertexIdx(0);
+ visitedIndices.insert(0);
+
+ while (toVisit.size() != 0) {
+ oneStepPrim(toVisit, visitedIndices, g);
+ }
+
+ return g;
+}
diff --git a/tests/snapshot_test.cpp b/tests/snapshot_test.cpp
@@ -1,13 +1,23 @@
#include "../include/graph.hpp"
#include <catch2/catch_test_macros.hpp>
+#include <fstream>
#include <iostream>
+#include <sstream>
+#include "snapshot_shared.cpp"
+
+std::string readFileToString(std::string filename) {
+ auto in = std::ifstream ("tests/snapshot/" + filename + ".out");
+ std::ostringstream sstr;
+ sstr << in.rdbuf();
+ return sstr.str();
+}
+
TEST_CASE( "Basic graph serialization snapshot", "[basic graph serialization snapshot]" ) {
- srand(42);
- int vertCount = 10;
- int edgeCount = 10;
- float xMax = 10;
- float yMax = 10;
- auto g = Graph(edgeCount,vertCount,xMax,yMax);
- std::cout << g.toString() << std::endl;
+ Graph g = basicGraphSerialization();
+ REQUIRE(readFileToString("basicGraph") == g.toString());
+}
+
+TEST_CASE( "Traversed graph serialization snapshot", "[traversed graph serialization snapshot]" ) {
+ Graph g = fullTraversalSerialization();
}
diff --git a/tests/snapshot_update.cpp b/tests/snapshot_update.cpp
@@ -1,13 +1,9 @@
#include "../include/graph.hpp"
-#include "../include/prim.hpp"
+#include "snapshot_shared.cpp"
#include <fstream>
#include <filesystem>
-#include <queue>
-#include <unordered_set>
-
void snapshotGraph(std::string testName, Graph g) {
-
std::filesystem::path path{ "tests/snapshot" };
path /= testName + ".out";
std::filesystem::create_directories(path.parent_path());
@@ -16,45 +12,10 @@ void snapshotGraph(std::string testName, Graph g) {
}
-void updateBasicGraphSerialization() {
- srand(42);
- int vertCount = 10;
- int edgeCount = 10;
- float xMax = 10;
- float yMax = 10;
- auto g = Graph(edgeCount,vertCount,xMax,yMax);
- snapshotGraph("basicGraph",g);
-}
-
-
-void updateFullTraversalSerialization() {
- srand(42);
- std::size_t edgeCount = 1;
- std::size_t vertCount = 2;
-
- float xMax = 5120;
- float yMax = 1440;
-
- Graph g = Graph(edgeCount, vertCount, xMax,yMax);
- std::unordered_set<std::size_t> visitedIndices {};
- std::priority_queue<Edge, std::vector<Edge>, std::greater<Edge>> toVisit {};
- std::vector<Edge> edges = g.getEdgesOfVertexIdx(0);
-
- for(auto edge: edges) {
- toVisit.push(edge);
- }
-
- g.traverseVertexIdx(0);
- visitedIndices.insert(0);
-
- while (toVisit.size() != 0) {
- oneStepPrim(toVisit, visitedIndices, g);
- }
-
- snapshotGraph("traversedGraph",g);
-}
-
int main() {
- updateBasicGraphSerialization();
- updateFullTraversalSerialization();
+ Graph g1 = basicGraphSerialization();
+ snapshotGraph("basicGraph", g1);
+ Graph g2 = fullTraversalSerialization();
+ snapshotGraph("traversedGraph", g2);
+
}