Skip to content

Commit

Permalink
Test compute graph I/O via protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
eguiraud committed Oct 1, 2023
1 parent c413d98 commit 0025ab4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cc_test(
size = "small",
srcs = ["test.cpp"],
deps = [
"@abseil-cpp//absl/status:statusor",
"@googletest//:gtest_main",
"//src:compute_graph_ad"
],
Expand Down
23 changes: 22 additions & 1 deletion tests/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>

#include "absl/status/statusor.h"
#include "src/graph.h"

using namespace compute_graph_ad;
Expand Down Expand Up @@ -58,4 +59,24 @@ TEST(Graph, MulEval) {
// Graph and Graph
const auto g9 = g1 * g1; // Graph * Graph
EXPECT_DOUBLE_EQ(g9.eval(inputs), 81.);
}
}

TEST(Tests, WriteAndReadGraph) {
const Const c{40.};
const Var x{"x"};
const Inputs inputs{{"x", 2.}};

const Graph g1 = x + c;

// write out
const absl::Status status = to_file(g1, "test.pb");
ASSERT_TRUE(status.ok());

// read in
const absl::StatusOr<Graph> gs = from_file("test.pb");
ASSERT_TRUE(gs.ok());

// check the graph still evaluates correctly
const Graph &g2 = gs.value();
EXPECT_DOUBLE_EQ(g2.eval(inputs), 42.);
}

0 comments on commit 0025ab4

Please sign in to comment.