#include "llvm/ADT/DeltaAlgorithm.h"
#include "gtest/gtest.h"
#include <algorithm>
#include <cstdarg>
using namespace llvm;
namespace std {
std::ostream &operator<<(std::ostream &OS,
const std::set<unsigned> &S) {
OS << "{";
for (std::set<unsigned>::const_iterator it = S.begin(),
ie = S.end(); it != ie; ++it) {
if (it != S.begin())
OS << ",";
OS << *it;
}
OS << "}";
return OS;
}
}
namespace {
class FixedDeltaAlgorithm final : public DeltaAlgorithm {
changeset_ty FailingSet;
unsigned NumTests;
protected:
bool ExecuteOneTest(const changeset_ty &Changes) override {
++NumTests;
return std::includes(Changes.begin(), Changes.end(),
FailingSet.begin(), FailingSet.end());
}
public:
FixedDeltaAlgorithm(const changeset_ty &_FailingSet)
: FailingSet(_FailingSet),
NumTests(0) {}
unsigned getNumTests() const { return NumTests; }
};
std::set<unsigned> fixed_set(unsigned N, ...) {
std::set<unsigned> S;
va_list ap;
va_start(ap, N);
for (unsigned i = 0; i != N; ++i)
S.insert(va_arg(ap, unsigned));
va_end(ap);
return S;
}
std::set<unsigned> range(unsigned Start, unsigned End) {
std::set<unsigned> S;
while (Start != End)
S.insert(Start++);
return S;
}
std::set<unsigned> range(unsigned N) {
return range(0, N);
}
TEST(DeltaAlgorithmTest, Basic) {
std::set<unsigned> Fails = fixed_set(3, 3, 5, 7);
FixedDeltaAlgorithm FDA(Fails);
EXPECT_EQ(fixed_set(3, 3, 5, 7), FDA.Run(range(20)));
EXPECT_GE(33U, FDA.getNumTests());
EXPECT_EQ(range(10,20), FDA.Run(range(10,20)));
FDA = FixedDeltaAlgorithm(range(10));
EXPECT_EQ(range(4), FDA.Run(range(4)));
EXPECT_EQ(11U, FDA.getNumTests());
}
}