Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / unittests / ADT / CombinationGeneratorTest.cpp
blobf3e174a83ba69ce3b9f6af9fe36b4defa2ca3200
1 //===- llvm/unittest/ADT/CombinationGeneratorTest.cpp ---------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/CombinationGenerator.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/Support/ErrorHandling.h"
13 #include "gmock/gmock.h"
14 #include "gtest/gtest.h"
15 #include <algorithm>
16 #include <cstddef>
17 #include <iterator>
18 #include <vector>
20 using namespace llvm;
22 namespace {
24 TEST(CombinationGenerator, Square) {
25 const std::vector<std::vector<int>> Choices{{0, 1}, {2, 3}};
27 std::vector<std::vector<int>> Variants;
28 CombinationGenerator<int, std::vector<int>, 4> G(Choices);
29 const size_t NumVariants = G.numCombinations();
30 G.generate([&](ArrayRef<int> State) -> bool {
31 Variants.emplace_back(State);
32 return false; // keep going
33 });
35 const std::vector<std::vector<int>> ExpectedVariants{
36 {0, 2},
37 {0, 3},
38 {1, 2},
39 {1, 3},
41 ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
42 ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
45 TEST(CombinationGenerator, MiddleColumn) {
46 const std::vector<std::vector<int>> Choices{{0}, {1, 2}, {3}};
48 std::vector<std::vector<int>> Variants;
49 CombinationGenerator<int, std::vector<int>, 4> G(Choices);
50 const size_t NumVariants = G.numCombinations();
51 G.generate([&](ArrayRef<int> State) -> bool {
52 Variants.emplace_back(State);
53 return false; // keep going
54 });
56 const std::vector<std::vector<int>> ExpectedVariants{
57 {0, 1, 3},
58 {0, 2, 3},
60 ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
61 ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
64 TEST(CombinationGenerator, SideColumns) {
65 const std::vector<std::vector<int>> Choices{{0, 1}, {2}, {3, 4}};
67 std::vector<std::vector<int>> Variants;
68 CombinationGenerator<int, std::vector<int>, 4> G(Choices);
69 const size_t NumVariants = G.numCombinations();
70 G.generate([&](ArrayRef<int> State) -> bool {
71 Variants.emplace_back(State);
72 return false; // keep going
73 });
75 const std::vector<std::vector<int>> ExpectedVariants{
76 {0, 2, 3},
77 {0, 2, 4},
78 {1, 2, 3},
79 {1, 2, 4},
81 ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
82 ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
85 TEST(CombinationGenerator, LeftColumn) {
86 const std::vector<std::vector<int>> Choices{{0, 1}, {2}};
88 std::vector<std::vector<int>> Variants;
89 CombinationGenerator<int, std::vector<int>, 4> G(Choices);
90 const size_t NumVariants = G.numCombinations();
91 G.generate([&](ArrayRef<int> State) -> bool {
92 Variants.emplace_back(State);
93 return false; // keep going
94 });
96 const std::vector<std::vector<int>> ExpectedVariants{
97 {0, 2},
98 {1, 2},
100 ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
101 ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
104 TEST(CombinationGenerator, RightColumn) {
105 const std::vector<std::vector<int>> Choices{{0}, {1, 2}};
107 std::vector<std::vector<int>> Variants;
108 CombinationGenerator<int, std::vector<int>, 4> G(Choices);
109 const size_t NumVariants = G.numCombinations();
110 G.generate([&](ArrayRef<int> State) -> bool {
111 Variants.emplace_back(State);
112 return false; // keep going
115 const std::vector<std::vector<int>> ExpectedVariants{
116 {0, 1},
117 {0, 2},
119 ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
120 ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
123 TEST(CombinationGenerator, Column) {
124 const std::vector<std::vector<int>> Choices{{0, 1}};
126 std::vector<std::vector<int>> Variants;
127 CombinationGenerator<int, std::vector<int>, 4> G(Choices);
128 const size_t NumVariants = G.numCombinations();
129 G.generate([&](ArrayRef<int> State) -> bool {
130 Variants.emplace_back(State);
131 return false; // keep going
134 const std::vector<std::vector<int>> ExpectedVariants{
135 {0},
136 {1},
138 ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
139 ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
142 TEST(CombinationGenerator, Row) {
143 const std::vector<std::vector<int>> Choices{{0}, {1}};
145 std::vector<std::vector<int>> Variants;
146 CombinationGenerator<int, std::vector<int>, 4> G(Choices);
147 const size_t NumVariants = G.numCombinations();
148 G.generate([&](ArrayRef<int> State) -> bool {
149 Variants.emplace_back(State);
150 return false; // keep going
153 const std::vector<std::vector<int>> ExpectedVariants{
154 {0, 1},
156 ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
157 ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
160 TEST(CombinationGenerator, Singleton) {
161 const std::vector<std::vector<int>> Choices{{0}};
163 std::vector<std::vector<int>> Variants;
164 CombinationGenerator<int, std::vector<int>, 4> G(Choices);
165 const size_t NumVariants = G.numCombinations();
166 G.generate([&](ArrayRef<int> State) -> bool {
167 Variants.emplace_back(State);
168 return false; // keep going
171 const std::vector<std::vector<int>> ExpectedVariants{
172 {0},
174 ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants));
175 ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants));
178 } // end anonymous namespace