[CMake] Allow overriding MSVC_DIA_SDK_DIR via CMake
[llvm-core.git] / unittests / ADT / DAGDeltaAlgorithmTest.cpp
blob66a67d96d15323fd44a3334ba3106da7d3bee108
1 //===- llvm/unittest/ADT/DAGDeltaAlgorithmTest.cpp ------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/DAGDeltaAlgorithm.h"
10 #include "gtest/gtest.h"
11 #include <algorithm>
12 #include <cstdarg>
13 using namespace llvm;
15 namespace {
17 typedef DAGDeltaAlgorithm::edge_ty edge_ty;
19 class FixedDAGDeltaAlgorithm : public DAGDeltaAlgorithm {
20 changeset_ty FailingSet;
21 unsigned NumTests;
23 protected:
24 bool ExecuteOneTest(const changeset_ty &Changes) override {
25 ++NumTests;
26 return std::includes(Changes.begin(), Changes.end(),
27 FailingSet.begin(), FailingSet.end());
30 public:
31 FixedDAGDeltaAlgorithm(const changeset_ty &_FailingSet)
32 : FailingSet(_FailingSet),
33 NumTests(0) {}
35 unsigned getNumTests() const { return NumTests; }
38 std::set<unsigned> fixed_set(unsigned N, ...) {
39 std::set<unsigned> S;
40 va_list ap;
41 va_start(ap, N);
42 for (unsigned i = 0; i != N; ++i)
43 S.insert(va_arg(ap, unsigned));
44 va_end(ap);
45 return S;
48 std::set<unsigned> range(unsigned Start, unsigned End) {
49 std::set<unsigned> S;
50 while (Start != End)
51 S.insert(Start++);
52 return S;
55 std::set<unsigned> range(unsigned N) {
56 return range(0, N);
59 TEST(DAGDeltaAlgorithmTest, Basic) {
60 std::vector<edge_ty> Deps;
62 // Dependencies:
63 // 1 - 3
64 Deps.clear();
65 Deps.push_back(std::make_pair(3, 1));
67 // P = {3,5,7} \in S,
68 // [0, 20),
69 // should minimize to {1,3,5,7} in a reasonable number of tests.
70 FixedDAGDeltaAlgorithm FDA(fixed_set(3, 3, 5, 7));
71 EXPECT_EQ(fixed_set(4, 1, 3, 5, 7), FDA.Run(range(20), Deps));
72 EXPECT_GE(46U, FDA.getNumTests());
74 // Dependencies:
75 // 0 - 1
76 // \- 2 - 3
77 // \- 4
78 Deps.clear();
79 Deps.push_back(std::make_pair(1, 0));
80 Deps.push_back(std::make_pair(2, 0));
81 Deps.push_back(std::make_pair(4, 0));
82 Deps.push_back(std::make_pair(3, 2));
84 // This is a case where we must hold required changes.
86 // P = {1,3} \in S,
87 // [0, 5),
88 // should minimize to {0,1,2,3} in a small number of tests.
89 FixedDAGDeltaAlgorithm FDA2(fixed_set(2, 1, 3));
90 EXPECT_EQ(fixed_set(4, 0, 1, 2, 3), FDA2.Run(range(5), Deps));
91 EXPECT_GE(9U, FDA2.getNumTests());
93 // This is a case where we should quickly prune part of the tree.
95 // P = {4} \in S,
96 // [0, 5),
97 // should minimize to {0,4} in a small number of tests.
98 FixedDAGDeltaAlgorithm FDA3(fixed_set(1, 4));
99 EXPECT_EQ(fixed_set(2, 0, 4), FDA3.Run(range(5), Deps));
100 EXPECT_GE(6U, FDA3.getNumTests());