1 //===- llvm/unittest/ADT/DAGDeltaAlgorithmTest.cpp ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/DAGDeltaAlgorithm.h"
18 typedef DAGDeltaAlgorithm::edge_ty edge_ty;
20 class FixedDAGDeltaAlgorithm : public DAGDeltaAlgorithm {
21 changeset_ty FailingSet;
25 virtual bool ExecuteOneTest(const changeset_ty &Changes) {
27 return std::includes(Changes.begin(), Changes.end(),
28 FailingSet.begin(), FailingSet.end());
32 FixedDAGDeltaAlgorithm(const changeset_ty &_FailingSet)
33 : FailingSet(_FailingSet),
36 unsigned getNumTests() const { return NumTests; }
39 std::set<unsigned> fixed_set(unsigned N, ...) {
43 for (unsigned i = 0; i != N; ++i)
44 S.insert(va_arg(ap, unsigned));
49 std::set<unsigned> range(unsigned Start, unsigned End) {
56 std::set<unsigned> range(unsigned N) {
60 TEST(DAGDeltaAlgorithmTest, Basic) {
61 std::vector<edge_ty> Deps;
66 Deps.push_back(std::make_pair(3, 1));
70 // should minimize to {1,3,5,7} in a reasonable number of tests.
71 FixedDAGDeltaAlgorithm FDA(fixed_set(3, 3, 5, 7));
72 EXPECT_EQ(fixed_set(4, 1, 3, 5, 7), FDA.Run(range(20), Deps));
73 EXPECT_GE(46U, FDA.getNumTests());
80 Deps.push_back(std::make_pair(1, 0));
81 Deps.push_back(std::make_pair(2, 0));
82 Deps.push_back(std::make_pair(4, 0));
83 Deps.push_back(std::make_pair(3, 2));
85 // This is a case where we must hold required changes.
89 // should minimize to {0,1,2,3} in a small number of tests.
90 FixedDAGDeltaAlgorithm FDA2(fixed_set(2, 1, 3));
91 EXPECT_EQ(fixed_set(4, 0, 1, 2, 3), FDA2.Run(range(5), Deps));
92 EXPECT_GE(9U, FDA2.getNumTests());
94 // This is a case where we should quickly prune part of the tree.
98 // should minimize to {0,4} in a small number of tests.
99 FixedDAGDeltaAlgorithm FDA3(fixed_set(1, 4));
100 EXPECT_EQ(fixed_set(2, 0, 4), FDA3.Run(range(5), Deps));
101 EXPECT_GE(6U, FDA3.getNumTests());