1 //===- llvm/unittest/ADT/DeltaAlgorithmTest.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/DeltaAlgorithm.h"
10 #include "gtest/gtest.h"
17 std::ostream
&operator<<(std::ostream
&OS
,
18 const std::set
<unsigned> &S
) {
20 for (std::set
<unsigned>::const_iterator it
= S
.begin(),
21 ie
= S
.end(); it
!= ie
; ++it
) {
34 class FixedDeltaAlgorithm final
: public DeltaAlgorithm
{
35 changeset_ty FailingSet
;
39 bool ExecuteOneTest(const changeset_ty
&Changes
) override
{
41 return std::includes(Changes
.begin(), Changes
.end(),
42 FailingSet
.begin(), FailingSet
.end());
46 FixedDeltaAlgorithm(const changeset_ty
&_FailingSet
)
47 : FailingSet(_FailingSet
),
50 unsigned getNumTests() const { return NumTests
; }
53 std::set
<unsigned> fixed_set(unsigned N
, ...) {
57 for (unsigned i
= 0; i
!= N
; ++i
)
58 S
.insert(va_arg(ap
, unsigned));
63 std::set
<unsigned> range(unsigned Start
, unsigned End
) {
70 std::set
<unsigned> range(unsigned N
) {
74 TEST(DeltaAlgorithmTest
, Basic
) {
76 // [0, 20) should minimize to {3,5,7} in a reasonable number of tests.
77 std::set
<unsigned> Fails
= fixed_set(3, 3, 5, 7);
78 FixedDeltaAlgorithm
FDA(Fails
);
79 EXPECT_EQ(fixed_set(3, 3, 5, 7), FDA
.Run(range(20)));
80 EXPECT_GE(33U, FDA
.getNumTests());
83 // [10, 20) should minimize to [10,20)
84 EXPECT_EQ(range(10,20), FDA
.Run(range(10,20)));
87 // [0, 4) should minimize to [0,4) in 11 tests.
90 // {0}, {1}, {2}, {3},
91 // {1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2},
93 FDA
= FixedDeltaAlgorithm(range(10));
94 EXPECT_EQ(range(4), FDA
.Run(range(4)));
95 EXPECT_EQ(11U, FDA
.getNumTests());