mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
acc25033f2
function_ref is non-owning, so if we get it as a parameter in constructor, our reference goes out-of-scope as soon as constructor returns. Instead, let's just take it as a parameter to the actual `generate()` call
176 lines
5.2 KiB
C++
176 lines
5.2 KiB
C++
//===-- SnippetGeneratorTest.cpp --------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "SnippetGenerator.h"
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
#include <initializer_list>
|
|
|
|
namespace llvm {
|
|
namespace exegesis {
|
|
|
|
namespace {
|
|
|
|
TEST(CombinationGenerator, Square) {
|
|
const std::vector<std::vector<int>> Choices{{0, 1}, {2, 3}};
|
|
|
|
std::vector<std::vector<int>> Variants;
|
|
CombinationGenerator<int, std::vector<int>, 4> G(Choices);
|
|
const size_t NumVariants = G.numCombinations();
|
|
G.generate([&](ArrayRef<int> State) -> bool {
|
|
Variants.emplace_back(State);
|
|
return false; // keep going
|
|
});
|
|
|
|
const std::vector<std::vector<int>> ExpectedVariants{
|
|
{0, 2},
|
|
{0, 3},
|
|
{1, 2},
|
|
{1, 3},
|
|
};
|
|
ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
|
|
ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
|
|
}
|
|
|
|
TEST(CombinationGenerator, MiddleColumn) {
|
|
const std::vector<std::vector<int>> Choices{{0}, {1, 2}, {3}};
|
|
|
|
std::vector<std::vector<int>> Variants;
|
|
CombinationGenerator<int, std::vector<int>, 4> G(Choices);
|
|
const size_t NumVariants = G.numCombinations();
|
|
G.generate([&](ArrayRef<int> State) -> bool {
|
|
Variants.emplace_back(State);
|
|
return false; // keep going
|
|
});
|
|
|
|
const std::vector<std::vector<int>> ExpectedVariants{
|
|
{0, 1, 3},
|
|
{0, 2, 3},
|
|
};
|
|
ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
|
|
ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
|
|
}
|
|
|
|
TEST(CombinationGenerator, SideColumns) {
|
|
const std::vector<std::vector<int>> Choices{{0, 1}, {2}, {3, 4}};
|
|
|
|
std::vector<std::vector<int>> Variants;
|
|
CombinationGenerator<int, std::vector<int>, 4> G(Choices);
|
|
const size_t NumVariants = G.numCombinations();
|
|
G.generate([&](ArrayRef<int> State) -> bool {
|
|
Variants.emplace_back(State);
|
|
return false; // keep going
|
|
});
|
|
|
|
const std::vector<std::vector<int>> ExpectedVariants{
|
|
{0, 2, 3},
|
|
{0, 2, 4},
|
|
{1, 2, 3},
|
|
{1, 2, 4},
|
|
};
|
|
ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
|
|
ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
|
|
}
|
|
|
|
TEST(CombinationGenerator, LeftColumn) {
|
|
const std::vector<std::vector<int>> Choices{{0, 1}, {2}};
|
|
|
|
std::vector<std::vector<int>> Variants;
|
|
CombinationGenerator<int, std::vector<int>, 4> G(Choices);
|
|
const size_t NumVariants = G.numCombinations();
|
|
G.generate([&](ArrayRef<int> State) -> bool {
|
|
Variants.emplace_back(State);
|
|
return false; // keep going
|
|
});
|
|
|
|
const std::vector<std::vector<int>> ExpectedVariants{
|
|
{0, 2},
|
|
{1, 2},
|
|
};
|
|
ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
|
|
ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
|
|
}
|
|
|
|
TEST(CombinationGenerator, RightColumn) {
|
|
const std::vector<std::vector<int>> Choices{{0}, {1, 2}};
|
|
|
|
std::vector<std::vector<int>> Variants;
|
|
CombinationGenerator<int, std::vector<int>, 4> G(Choices);
|
|
const size_t NumVariants = G.numCombinations();
|
|
G.generate([&](ArrayRef<int> State) -> bool {
|
|
Variants.emplace_back(State);
|
|
return false; // keep going
|
|
});
|
|
|
|
const std::vector<std::vector<int>> ExpectedVariants{
|
|
{0, 1},
|
|
{0, 2},
|
|
};
|
|
ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
|
|
ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
|
|
}
|
|
|
|
TEST(CombinationGenerator, Column) {
|
|
const std::vector<std::vector<int>> Choices{{0, 1}};
|
|
|
|
std::vector<std::vector<int>> Variants;
|
|
CombinationGenerator<int, std::vector<int>, 4> G(Choices);
|
|
const size_t NumVariants = G.numCombinations();
|
|
G.generate([&](ArrayRef<int> State) -> bool {
|
|
Variants.emplace_back(State);
|
|
return false; // keep going
|
|
});
|
|
|
|
const std::vector<std::vector<int>> ExpectedVariants{
|
|
{0},
|
|
{1},
|
|
};
|
|
ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
|
|
ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
|
|
}
|
|
|
|
TEST(CombinationGenerator, Row) {
|
|
const std::vector<std::vector<int>> Choices{{0}, {1}};
|
|
|
|
std::vector<std::vector<int>> Variants;
|
|
CombinationGenerator<int, std::vector<int>, 4> G(Choices);
|
|
const size_t NumVariants = G.numCombinations();
|
|
G.generate([&](ArrayRef<int> State) -> bool {
|
|
Variants.emplace_back(State);
|
|
return false; // keep going
|
|
});
|
|
|
|
const std::vector<std::vector<int>> ExpectedVariants{
|
|
{0, 1},
|
|
};
|
|
ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
|
|
ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
|
|
}
|
|
|
|
TEST(CombinationGenerator, Singleton) {
|
|
const std::vector<std::vector<int>> Choices{{0}};
|
|
|
|
std::vector<std::vector<int>> Variants;
|
|
CombinationGenerator<int, std::vector<int>, 4> G(Choices);
|
|
const size_t NumVariants = G.numCombinations();
|
|
G.generate([&](ArrayRef<int> State) -> bool {
|
|
Variants.emplace_back(State);
|
|
return false; // keep going
|
|
});
|
|
|
|
const std::vector<std::vector<int>> ExpectedVariants{
|
|
{0},
|
|
};
|
|
ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
|
|
ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace exegesis
|
|
} // namespace llvm
|