//===-- 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 namespace llvm { namespace exegesis { namespace { TEST(CombinationGenerator, Square) { const std::vector> Choices{{0, 1}, {2, 3}}; std::vector> Variants; CombinationGenerator, 4> G(Choices); const size_t NumVariants = G.numCombinations(); G.generate([&](ArrayRef State) -> bool { Variants.emplace_back(State); return false; // keep going }); const std::vector> 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> Choices{{0}, {1, 2}, {3}}; std::vector> Variants; CombinationGenerator, 4> G(Choices); const size_t NumVariants = G.numCombinations(); G.generate([&](ArrayRef State) -> bool { Variants.emplace_back(State); return false; // keep going }); const std::vector> 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> Choices{{0, 1}, {2}, {3, 4}}; std::vector> Variants; CombinationGenerator, 4> G(Choices); const size_t NumVariants = G.numCombinations(); G.generate([&](ArrayRef State) -> bool { Variants.emplace_back(State); return false; // keep going }); const std::vector> 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> Choices{{0, 1}, {2}}; std::vector> Variants; CombinationGenerator, 4> G(Choices); const size_t NumVariants = G.numCombinations(); G.generate([&](ArrayRef State) -> bool { Variants.emplace_back(State); return false; // keep going }); const std::vector> ExpectedVariants{ {0, 2}, {1, 2}, }; ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants)); ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants)); } TEST(CombinationGenerator, RightColumn) { const std::vector> Choices{{0}, {1, 2}}; std::vector> Variants; CombinationGenerator, 4> G(Choices); const size_t NumVariants = G.numCombinations(); G.generate([&](ArrayRef State) -> bool { Variants.emplace_back(State); return false; // keep going }); const std::vector> ExpectedVariants{ {0, 1}, {0, 2}, }; ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants)); ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants)); } TEST(CombinationGenerator, Column) { const std::vector> Choices{{0, 1}}; std::vector> Variants; CombinationGenerator, 4> G(Choices); const size_t NumVariants = G.numCombinations(); G.generate([&](ArrayRef State) -> bool { Variants.emplace_back(State); return false; // keep going }); const std::vector> ExpectedVariants{ {0}, {1}, }; ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants)); ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants)); } TEST(CombinationGenerator, Row) { const std::vector> Choices{{0}, {1}}; std::vector> Variants; CombinationGenerator, 4> G(Choices); const size_t NumVariants = G.numCombinations(); G.generate([&](ArrayRef State) -> bool { Variants.emplace_back(State); return false; // keep going }); const std::vector> ExpectedVariants{ {0, 1}, }; ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants)); ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants)); } TEST(CombinationGenerator, Singleton) { const std::vector> Choices{{0}}; std::vector> Variants; CombinationGenerator, 4> G(Choices); const size_t NumVariants = G.numCombinations(); G.generate([&](ArrayRef State) -> bool { Variants.emplace_back(State); return false; // keep going }); const std::vector> ExpectedVariants{ {0}, }; ASSERT_THAT(Variants, ::testing::SizeIs(NumVariants)); ASSERT_THAT(Variants, ::testing::ContainerEq(ExpectedVariants)); } } // namespace } // namespace exegesis } // namespace llvm