diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-12-03 11:12:42 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-12-03 11:12:42 +0000 |
commit | a6d5e40e25e6b4fc856fa5cd10a59b8fdf51d9a7 (patch) | |
tree | f0bbfb4de8dde6ca47ba3744656321460257549d /unittests | |
parent | 44299c9507dc25279741b28ade2d2efa0b8506ad (diff) |
Add an implementation of the delta debugging algorithm.
- This is a pretty slow / memory intensive implementation, and I will likely
change it to an iterative model, but it works.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90447 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/DeltaAlgorithmTest.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/unittests/ADT/DeltaAlgorithmTest.cpp b/unittests/ADT/DeltaAlgorithmTest.cpp new file mode 100644 index 0000000000..362892207f --- /dev/null +++ b/unittests/ADT/DeltaAlgorithmTest.cpp @@ -0,0 +1,96 @@ +//===- llvm/unittest/ADT/DeltaAlgorithmTest.cpp ---------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" +#include "llvm/ADT/DeltaAlgorithm.h" +#include <algorithm> +#include <cstdarg> +using namespace llvm; + +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 : public DeltaAlgorithm { + changeset_ty FailingSet; + unsigned NumTests; + +protected: + virtual bool ExecuteOneTest(const changeset_ty &Changes) { + ++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) { + // P = {3,5,7} \in S + // [0, 20) should minimize to {3,5,7} in a reasonable number of tests. + 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()); + + // P = {3,5,7} \in S + // [10, 20) should minimize to [10,20) + EXPECT_EQ(range(10,20), FDA.Run(range(10,20))); + + // P = [0,4) \in S + // [0, 4) should minimize to [0,4) in 11 tests. + // + // 11 = |{ {}, + // {0}, {1}, {2}, {3}, + // {1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2}, + // {0, 1}, {2, 3} }| + FDA = FixedDeltaAlgorithm(range(10)); + EXPECT_EQ(range(4), FDA.Run(range(4))); + EXPECT_EQ(11U, FDA.getNumTests()); +} + +} + |