1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <gtest/gtest.h>
#include <c10/util/irange.h>
#include <torch/torch.h>
#include <test/cpp/api/support.h>
#include <cstddef>
#include <initializer_list>
#include <vector>
struct ExpandingArrayTest : torch::test::SeedingFixture {};
TEST_F(ExpandingArrayTest, CanConstructFromInitializerList) {
torch::ExpandingArray<5> e({1, 2, 3, 4, 5});
ASSERT_EQ(e.size(), 5);
for (const auto i : c10::irange(e.size())) {
ASSERT_EQ((*e)[i], i + 1);
}
}
TEST_F(ExpandingArrayTest, CanConstructFromVector) {
torch::ExpandingArray<5> e(std::vector<int64_t>{1, 2, 3, 4, 5});
ASSERT_EQ(e.size(), 5);
for (const auto i : c10::irange(e.size())) {
ASSERT_EQ((*e)[i], i + 1);
}
}
TEST_F(ExpandingArrayTest, CanConstructFromArray) {
torch::ExpandingArray<5> e(std::array<int64_t, 5>({1, 2, 3, 4, 5}));
ASSERT_EQ(e.size(), 5);
for (const auto i : c10::irange(e.size())) {
ASSERT_EQ((*e)[i], i + 1);
}
}
TEST_F(ExpandingArrayTest, CanConstructFromSingleValue) {
torch::ExpandingArray<5> e(5);
ASSERT_EQ(e.size(), 5);
for (const auto i : c10::irange(e.size())) {
ASSERT_EQ((*e)[i], 5);
}
}
TEST_F(
ExpandingArrayTest,
ThrowsWhenConstructedWithIncorrectNumberOfArgumentsInInitializerList) {
ASSERT_THROWS_WITH(
torch::ExpandingArray<5>({1, 2, 3, 4, 5, 6, 7}),
"Expected 5 values, but instead got 7");
}
TEST_F(
ExpandingArrayTest,
ThrowsWhenConstructedWithIncorrectNumberOfArgumentsInVector) {
ASSERT_THROWS_WITH(
torch::ExpandingArray<5>(std::vector<int64_t>({1, 2, 3, 4, 5, 6, 7})),
"Expected 5 values, but instead got 7");
}
|