Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ishan-karmakar committed Aug 13, 2024
1 parent fdb7cb0 commit 82ce0ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
24 changes: 0 additions & 24 deletions include/frg/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,30 +152,6 @@ constexpr const T &&get(const frg::array<T, N> &&a) noexcept {

namespace std {

template<size_t I, class T, size_t N>
constexpr T &get(frg::array<T, N> &a) noexcept {
static_assert(I < N, "array index is not within bounds");
return a[I];
};

template<size_t I, class T, size_t N>
constexpr T &&get(frg::array<T, N> &&a) noexcept {
static_assert(I < N, "array index is not within bounds");
return std::move(a[I]);
};

template<size_t I, class T, size_t N>
constexpr const T &get(const frg::array<T, N> &a) noexcept {
static_assert(I < N, "array index is not within bounds");
return a[I];
};

template<size_t I, class T, size_t N>
constexpr const T &&get(const frg::array<T, N> &&a) noexcept {
static_assert(I < N, "array index is not within bounds");
return std::move(a[I]);
};

template<class T, size_t N>
struct tuple_size<frg::array<T, N>> :
integral_constant<size_t, N> { };
Expand Down
26 changes: 26 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,32 @@ TEST(tuples, reference_test) {
EXPECT_EQ(&z, &t2.get<2>());
}

#include <frg/array.hpp>

TEST(array, basic_test) {
constexpr int N = 4;
frg::array<int, N> arr{0, 1, 2, 3};
for (int i = 0; i < N; i++)
EXPECT_EQ(arr[i], i);

const auto [a, b, c, d] = arr;
EXPECT_EQ(a, 0);
EXPECT_EQ(b, 1);
EXPECT_EQ(c, 2);
EXPECT_EQ(d, 3);

arr[0] = 1;
EXPECT_NE(a, arr[0]); // Make sure a doesn't change when array changes

const auto& [e, f, g, h] = arr;
EXPECT_EQ(e, 1);
arr[0] = 2;
EXPECT_EQ(e, 2); // Make sure e does change when array changes

static_assert(std::tuple_size_v<decltype(arr)> == N, "tuple_size produces wrong result");
static_assert(std::is_same_v<std::tuple_element_t<N, decltype(arr)>, int>, "tuple_element produces wrong result");
}

#include <frg/formatting.hpp>
#include <frg/logging.hpp>
#include <string> // std::string
Expand Down

0 comments on commit 82ce0ca

Please sign in to comment.