Skip to content

Commit

Permalink
Add clang-format check to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
eguiraud authored Oct 1, 2023
2 parents 0bcfa77 + cca7b8d commit 2dcb0a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ jobs:
bazel mod graph
bazel test -c dbg -s --test_output=all //tests:test
shell: bash
clang_format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: DoozyX/[email protected]
with:
source: '.'
extensions: 'h,cpp'
clangFormatVersion: 14
4 changes: 2 additions & 2 deletions src/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
*/
#include "absl/container/flat_hash_map.h"

#include <memory>
#include <string>
#include <string_view>

#include "absl/container/flat_hash_map.h"

/* A note on the use of shared_ptr<const T>
They are not as bad as they might seem at first sight:
Expand Down
18 changes: 6 additions & 12 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ TEST(Graph, SumEval) {

const Graph g3 = x + c; // Var + Const
const Graph g4 = c + x; // Const + Var
for (const auto &g: {g3, g4})
EXPECT_DOUBLE_EQ(g.eval(inputs), 5.);
for (const auto &g : {g3, g4}) EXPECT_DOUBLE_EQ(g.eval(inputs), 5.);

const Graph g5 = x + g1; // Var + Graph
const Graph g6 = g1 + x; // Graph + Var
for (const auto &g: {g5, g6})
EXPECT_DOUBLE_EQ(g.eval(inputs), 9.);
for (const auto &g : {g5, g6}) EXPECT_DOUBLE_EQ(g.eval(inputs), 9.);

const Graph g7 = c + g1; // Const + Graph
const Graph g8 = g1 + c; // Graph + Const
for (const auto &g: {g7, g8})
EXPECT_DOUBLE_EQ(g.eval(inputs), 8.);
for (const auto &g : {g7, g8}) EXPECT_DOUBLE_EQ(g.eval(inputs), 8.);

// Graph and Graph
const auto g9 = g1 + g1; // Graph + Graph
Expand All @@ -48,18 +45,15 @@ TEST(Graph, MulEval) {

const Graph g3 = x * c; // Var * Const
const Graph g4 = c * x; // Const * Var
for (const auto &g: {g3, g4})
EXPECT_DOUBLE_EQ(g.eval(inputs), 6.);
for (const auto &g : {g3, g4}) EXPECT_DOUBLE_EQ(g.eval(inputs), 6.);

const Graph g5 = x * g1; // Var * Graph
const Graph g6 = g1 * x; // Graph * Var
for (const auto &g: {g5, g6})
EXPECT_DOUBLE_EQ(g.eval(inputs), 27.);
for (const auto &g : {g5, g6}) EXPECT_DOUBLE_EQ(g.eval(inputs), 27.);

const Graph g7 = c * g1; // Const * Graph
const Graph g8 = g1 * c; // Graph * Const
for (const auto &g: {g7, g8})
EXPECT_DOUBLE_EQ(g.eval(inputs), 18.);
for (const auto &g : {g7, g8}) EXPECT_DOUBLE_EQ(g.eval(inputs), 18.);

// Graph and Graph
const auto g9 = g1 * g1; // Graph * Graph
Expand Down

0 comments on commit 2dcb0a5

Please sign in to comment.