1 //===- llvm/unittest/ADT/DeltaAlgorithmTest.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/DeltaAlgorithm.h"
18 std::ostream
&operator<<(std::ostream
&OS
,
19 const std::set
<unsigned> &S
) {
21 for (std::set
<unsigned>::const_iterator it
= S
.begin(),
22 ie
= S
.end(); it
!= ie
; ++it
) {
35 class FixedDeltaAlgorithm
: public DeltaAlgorithm
{
36 changeset_ty FailingSet
;
40 virtual bool ExecuteOneTest(const changeset_ty
&Changes
) {
42 return std::includes(Changes
.begin(), Changes
.end(),
43 FailingSet
.begin(), FailingSet
.end());
47 FixedDeltaAlgorithm(const changeset_ty
&_FailingSet
)
48 : FailingSet(_FailingSet
),
51 unsigned getNumTests() const { return NumTests
; }
54 std::set
<unsigned> fixed_set(unsigned N
, ...) {
58 for (unsigned i
= 0; i
!= N
; ++i
)
59 S
.insert(va_arg(ap
, unsigned));
64 std::set
<unsigned> range(unsigned Start
, unsigned End
) {
71 std::set
<unsigned> range(unsigned N
) {
75 TEST(DeltaAlgorithmTest
, Basic
) {
77 // [0, 20) should minimize to {3,5,7} in a reasonable number of tests.
78 std::set
<unsigned> Fails
= fixed_set(3, 3, 5, 7);
79 FixedDeltaAlgorithm
FDA(Fails
);
80 EXPECT_EQ(fixed_set(3, 3, 5, 7), FDA
.Run(range(20)));
81 EXPECT_GE(33U, FDA
.getNumTests());
84 // [10, 20) should minimize to [10,20)
85 EXPECT_EQ(range(10,20), FDA
.Run(range(10,20)));
88 // [0, 4) should minimize to [0,4) in 11 tests.
91 // {0}, {1}, {2}, {3},
92 // {1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2},
94 FDA
= FixedDeltaAlgorithm(range(10));
95 EXPECT_EQ(range(4), FDA
.Run(range(4)));
96 EXPECT_EQ(11U, FDA
.getNumTests());