Skip to content

Commit

Permalink
Add test to dag
Browse files Browse the repository at this point in the history
  • Loading branch information
Matts966 committed Jul 14, 2020
1 parent 0c406a9 commit e03e5e9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ sample:
dag ./samples/sample2/ --output_path ./samples/sample2/dag.dot
dot -Tpng ./samples/sample2/dag.dot -o ./samples/sample2/dag.png
pipeline_type_checker ./samples/sample2/dag.dot

linux: build
./docker/linux-copy-bin.sh
test:
CC=g++ bazel test //alphasql:all

.PHONY: run build osx push
10 changes: 10 additions & 0 deletions alphasql/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,13 @@ cc_binary(
":identifier_resolver",
],
)

cc_test(
name = "dag_test",
srcs = ["dag_test.cc"],
deps = [
":dag",
"@com_google_googletest//:gtest_main",
"@boost//:graph",
],
)
76 changes: 76 additions & 0 deletions alphasql/dag_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// Copyright 2019 Matts966
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "alphasql/dag.cc"
#include "boost/graph/depth_first_search.hpp"
#include "gtest/gtest.h"

namespace alphasql {
namespace {

using namespace boost;

typedef adjacency_list<vecS, vecS, directedS, property<vertex_name_t, std::string>> Graph;
bool has_cycle = false;

TEST(cycle_detector, cycle) {
Graph g1(2);
add_edge(0, 1, g);
add_edge(1, 0, g);
cycle_detector vis(has_cycle);
depth_first_search(g, visitor(vis));
ASSERT_TRUE(has_cycle);

has_cycle = false;
Graph g2(3);
add_edge(0, 1, g2);
add_edge(1, 2, g2);
add_edge(2, 0, g2);
cycle_detector vis(has_cycle);
depth_first_search(g2, visitor(vis));
ASSERT_TRUE(has_cycle);

has_cycle = false;
Graph g3(5);
add_edge(0, 1, g3);
add_edge(1, 2, g3);
add_edge(2, 3, g3);
add_edge(3, 4, g3);
add_edge(4, 0, g3);
cycle_detector vis(has_cycle);
depth_first_search(g3, visitor(vis));
ASSERT_TRUE(has_cycle);
}

TEST(cycle_detector, acycle) {
has_cycle = false;
Graph g1(2);
add_edge(0, 1, g);
cycle_detector vis(has_cycle);
depth_first_search(g, visitor(vis));
ASSERT_FALSE(has_cycle);

has_cycle = false;
Graph g2(3);
add_edge(0, 1, g2);
add_edge(1, 2, g2);
add_edge(0, 2, g2);
cycle_detector vis(has_cycle);
depth_first_search(g2, visitor(vis));
ASSERT_FALSE(has_cycle);
}

}

0 comments on commit e03e5e9

Please sign in to comment.