49#include <gtest/gtest.h>
69TEST(CAMetrics, CountStateAndCountAliveAreConsistent)
85TEST(CAMetrics, DensityIsZeroOnEmptyLattice)
88 EXPECT_DOUBLE_EQ(
density(empty, 0), 0.0);
92TEST(CAMetrics, DensityMatchesCountOverTotal)
98 EXPECT_DOUBLE_EQ(
density(lat, 1), 3.0 / 9.0);
102TEST(CAMetrics, StateHistogramSumsToTotal)
106 lat.set({i, i},
static_cast<int>(i % 3));
108 ASSERT_EQ(
h.size(), 4u);
112 EXPECT_EQ(total, 16u);
115TEST(CAMetrics, ShannonEntropyZeroForUniformLattice)
121TEST(CAMetrics, ShannonEntropyForBalancedBinaryReachesLn2)
127 lat.set({i, j}, ((i + j) & 1) != 0 ? 1 : 0);
131TEST(CAMetrics, FrameHashEqualForEqualFrames)
143TEST(CAMetrics, FrameHashDiffersForDifferentFrames)
153TEST(CAMetrics, FrameHashStableAcrossLatticeReconstruction)
161 lat.set({i, j}, ((i * 4 + j) % 3 == 0) ? 1 : 0);
167TEST(CAMetrics, CellDiffCountMatchesActivity)
185TEST(CAMetrics, ForEachCellWalksRank1And3LatticesToo)
189 a.set({i},
static_cast<int>(i));
190 std::vector<int> seen;
192 EXPECT_EQ(seen, (std::vector<int>{0, 1, 2, 3, 4}));
200TEST(CAMetrics, MetricsWorkOnGraphLattice)
207 EXPECT_DOUBLE_EQ(
density(g, 1), 0.4);
Free metric helpers for cellular automata frames.
Common typedefs and tag types for the Cellular Automata module.
Graph lattice: one cell per node + precomputed adjacency.
void set_node(std::size_t n, const T &v)
Direct write at node id n.
Lattice that adds boundary-aware access on top of a storage.
double shannon_entropy(const Lattice &lat, std::size_t max_state)
Shannon entropy in nats of the [0, max_state) distribution.
Array< ca_size_t > state_histogram(const Lattice &lat, std::size_t max_state)
Count occurrences of every integer state in [0, max_state).
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
std::uint64_t frame_hash(const Lattice &lat)
Deterministic 64-bit FNV-1a hash of the lattice cells.
void for_each_cell(const Lattice &lat, F &&f)
Visit every cell of a lattice in canonical row-major order.
double density(const Lattice &lat, const typename Lattice::state_type &s)
bool frames_equal(const Lattice &a, const Lattice &b)
Array< Array< std::size_t > > make_path_graph_adjacency(std::size_t n, bool cycle=false)
Build the adjacency of a path graph with n nodes.
ca_size_t count_state(const Lattice &lat, const typename Lattice::state_type &s)
ca_size_t count_alive(const Lattice &lat)
double alive_density(const Lattice &lat)
std::size_t ca_size_t
Unsigned size component used for extents and counts.
ca_size_t cell_diff_count(const Lattice &a, const Lattice &b)
Main namespace for Aleph-w library functions.
Out-of-range neighbours behave as if the lattice ended.
C++20 concepts for the Cellular Automata module.
CA whose underlying topology is an arbitrary undirected graph.
Cellular automata lattice with pluggable boundary policies.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).