45# include <gtest/gtest.h>
70 std::array<std::size_t, 2>
extents { 0, 0 };
71 std::array<T, 16> cells { };
73 static std::size_t dimension()
76 std::size_t
size(std::size_t d)
const {
return extents[d]; }
78 T at(
const coord_type & c)
const
80 return cells[c[0] *
extents[1] + c[1]];
83 void set(
const coord_type & c,
const T & v)
85 cells[c[0] *
extents[1] + c[1]] = v;
90 struct Mock_Neighborhood
93 static constexpr std::size_t rank_v = 2;
94 static constexpr std::size_t size_v = 8;
96 std::size_t radius()
const {
return 1; }
97 std::size_t
size()
const {
return size_v; }
100 static void for_each_offset(
const coord_type &,
F &&)
107 template <
typename S>
108 S operator()(
S s)
const {
return s; }
110 template <
typename S>
119 static_assert(CellState<bool>);
120 static_assert(CellState<std::uint8_t>);
121 static_assert(CellState<int>);
127 static_assert(LatticeLike<Mock_Lattice<bool>>);
128 static_assert(LatticeLike<Mock_Lattice<std::uint8_t>>);
130 static_assert(NeighborhoodLike<Mock_Neighborhood>);
132 static_assert(RuleLike<Identity_Rule, Mock_Lattice<bool>>);
133 static_assert(RuleLike<Identity_Rule, Mock_Lattice<std::uint8_t>>);
136 struct Not_A_Lattice {};
137 static_assert(not LatticeLike<Not_A_Lattice>);
139 struct Not_A_Neighborhood {};
140 static_assert(not NeighborhoodLike<Not_A_Neighborhood>);
145TEST(CACellularAutomataConcepts, MockLatticeReadWrite)
147 Mock_Lattice<std::uint8_t> lat;
148 lat.extents = { 4, 4 };
149 for (std::size_t i = 0; i < lat.cells.size(); ++i)
154 EXPECT_EQ(lat.at(c), 7u);
155 EXPECT_EQ(lat.dimension(), 2u);
156 EXPECT_EQ(lat.size(0), 4u);
157 EXPECT_EQ(lat.size(1), 4u);
160TEST(CACellularAutomataConcepts, MockNeighborhoodInterface)
163 EXPECT_EQ(
h.radius(), 1u);
164 EXPECT_EQ(
h.size(), 8u);
167TEST(CACellularAutomataConcepts, IdentityRuleProducesSameState)
170 EXPECT_EQ(
r(
static_cast<std::uint8_t
>(42)),
static_cast<std::uint8_t
>(42));
171 EXPECT_TRUE(
r(
true));
172 EXPECT_FALSE(
r(
false));
175TEST(CACellularAutomataConcepts, BoundaryTagsAreEmpty)
187 EXPECT_EQ(B::value, 0u);
Common typedefs and tag types for the Cellular Automata module.
Shape (per-axis sizes) of an mdspan, mixing compile-time and run-time extents.
std::span< const T > Neighbor_View
Read-only view over a contiguous range of neighbour values.
std::array< ca_index_t, N > Coord_Vec
Default coordinate vector.
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
std::decay_t< typename HeadC::Item_Type > T
Iterate the lattice in column-major (Fortran) order.
Out-of-range neighbours behave as if the lattice ended.
Out-of-range coordinates mirror back into the lattice.
Iterate the lattice in row-major (C) order.
The lattice wraps around on every axis.
C++20 concepts for the Cellular Automata module.