1 //===- llvm/unittest/ADT/DAGDeltaAlgorithmTest.cpp ------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/DAGDeltaAlgorithm.h"
10 #include "gtest/gtest.h"
17 typedef DAGDeltaAlgorithm::edge_ty edge_ty
;
19 class FixedDAGDeltaAlgorithm
: public DAGDeltaAlgorithm
{
20 changeset_ty FailingSet
;
24 bool ExecuteOneTest(const changeset_ty
&Changes
) override
{
26 return std::includes(Changes
.begin(), Changes
.end(),
27 FailingSet
.begin(), FailingSet
.end());
31 FixedDAGDeltaAlgorithm(const changeset_ty
&_FailingSet
)
32 : FailingSet(_FailingSet
),
35 unsigned getNumTests() const { return NumTests
; }
38 std::set
<unsigned> fixed_set(unsigned N
, ...) {
42 for (unsigned i
= 0; i
!= N
; ++i
)
43 S
.insert(va_arg(ap
, unsigned));
48 std::set
<unsigned> range(unsigned Start
, unsigned End
) {
55 std::set
<unsigned> range(unsigned N
) {
59 TEST(DAGDeltaAlgorithmTest
, Basic
) {
60 std::vector
<edge_ty
> Deps
;
65 Deps
.push_back(std::make_pair(3, 1));
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());
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.
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.
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());