43#include <gtest/gtest.h>
55 using Cell = std::pair<ca_index_t, ca_index_t>;
58 std::initializer_list<Cell> alive)
61 for (
const auto &c : alive)
62 g.set({c.first, c.second}, 1);
81 if (g.at({r, c}) != 0)
92 EXPECT_EQ(a.at({r, c}), b.at({
r, c})) <<
"at (" <<
r <<
", " << c <<
")";
95 std::string bytes(std::initializer_list<unsigned> values)
98 for (
const unsigned v : values)
106 const Grid src =
make_grid(4, 5, {{1, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}});
109 opts.comment =
"full-frame snapshot";
113 EXPECT_NE(
rle.find(
"#C full-frame snapshot"), std::string::npos);
114 EXPECT_NE(
rle.find(
"x = 5, y = 4, rule = B3/S23"), std::string::npos);
126 const Grid src =
make_grid(6, 7, {{2, 3}, {3, 4}, {4, 2}, {4, 3}, {4, 4}});
132 EXPECT_NE(
rle.find(
"x = 3, y = 3, rule = B3/S23"), std::string::npos);
137 (std::set<Cell>{{0, 1}, {1, 2}, {2, 0}, {2, 1}, {2, 2}}));
142 const std::string text =
144 "#C A is accepted as alive and . as dead\n"
145 "x = 5, y = 3, rule = B36/S23\n"
167 const Grid src =
make_grid(3, 4, {{0, 1}, {1, 2}, {2, 0}, {2, 1}, {2, 2}});
171 EXPECT_NE(text.find(
"!plaintext glider"), std::string::npos);
172 EXPECT_NE(text.find(
".O.."), std::string::npos);
192 const std::string text =
197 std::istringstream
in(text);
208 const Grid src =
make_grid(3, 3, {{0, 2}, {2, 0}});
209 std::ostringstream
out;
212 std::istringstream
in(
out.str());
221 const Grid src =
make_grid(3, 4, {{0, 0}, {1, 2}, {2, 3}});
222 std::ostringstream
out;
224 EXPECT_NE(
out.str().find(
"#Life 1.05"), std::string::npos);
227 std::istringstream
in(
out.str());
235 const std::string text =
242 std::istringstream
in(text);
258 std::ostringstream
out;
262 std::istringstream
in(
out.str());
271 std::istringstream
in(
"1,2\n3\n");
275 std::istringstream
in(
"1,x\n");
287 std::ostringstream
out;
289 EXPECT_NE(
out.str().find(
"\"type\": \"Aleph::CA::frame\""), std::string::npos);
290 EXPECT_NE(
out.str().find(
"\"rule\": \"demo\""), std::string::npos);
292 std::istringstream
in(
out.str());
300 ByteGrid frame({1, 3}, std::uint8_t{0});
301 frame.set({0, 0}, std::uint8_t{7});
302 frame.set({0, 1}, std::uint8_t{42});
303 frame.set({0, 2}, std::uint8_t{255});
305 std::ostringstream
csv;
309 std::ostringstream json;
311 EXPECT_NE(json.str().find(
"\"cells\":[[7,42,255]]"), std::string::npos);
316 std::istringstream
in(
317 "{\"type\":\"Aleph::CA::frame\",\"rank\":2,\"height\":1,\"width\":2,"
318 "\"cells\":[[1,2],[3,4]]}");
324 const Grid frame =
make_grid(2, 2, {{0, 0}, {1, 1}});
325 std::ostringstream
out;
332 EXPECT_NE(
out.str().find(
"\"type\": \"Aleph::CA::frame-stream\""), std::string::npos);
333 EXPECT_NE(
out.str().find(
"\"step\": 0"), std::string::npos);
334 EXPECT_NE(
out.str().find(
"\"step\": 4"), std::string::npos);
335 EXPECT_NE(
out.str().find(
"\"cells\":[[1,0],[0,1]]"), std::string::npos);
340 const Grid frame =
make_grid(2, 3, {{0, 1}, {1, 2}});
341 std::ostringstream
out(std::ios::binary);
344 std::string
expected =
"P5\n3 2\n255\n";
345 expected += bytes({255, 0, 255, 255, 255, 0});
351 const Grid frame =
make_grid(1, 2, {{0, 1}});
352 std::ostringstream
out(std::ios::binary);
355 return v == 0 ?
RGB8{1, 2, 3} :
RGB8{250, 0, 7};
358 std::string
expected =
"P6\n2 1\n255\n";
359 expected += bytes({1, 2, 3, 250, 0, 7});
size_t size_t int32_t * out
File-format readers and writers for cellular-automata frames.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Streaming JSON writer for CA trajectories.
Lattice that adds boundary-aware access on top of a storage.
Minimal std::expected-style result type for C++20.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
void write_pgm(std::ostream &out, const Lattice &frame, Mapper &&mapper, const NetPBM_Write_Options &opts={})
Write a binary PGM (P5) image.
void write_life_105(std::ostream &out, const Lattice &frame, const std::string &comment={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
Write a Life 1.05 file.
Binary_Cell_Pattern read_plaintext_string(const std::string &s)
Read a Life plaintext pattern from a string.
void write_life_106(std::ostream &out, const Lattice &frame, const typename Lattice::state_type &dead=typename Lattice::state_type{})
Write a Life 1.06 file.
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
std::array< ca_index_t, N > Coord_Vec
Default coordinate vector.
std::string write_plaintext_string(const Lattice &frame, const Plaintext_Write_Options &opts={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
Return a Life plaintext document.
void write_ppm(std::ostream &out, const Lattice &frame, Mapper &&mapper, const NetPBM_Write_Options &opts={})
Write a binary PPM (P6) image.
Binary_Cell_Pattern read_life_105(std::istream &in)
Read a Life 1.05 pattern.
void write_csv(std::ostream &out, const Lattice &frame, const CSV_Options &opts={})
Write a numeric CSV snapshot.
std::string write_rle_string(const Lattice &frame, const RLE_Write_Options &opts={}, const typename Lattice::state_type &dead=typename Lattice::state_type{})
Return a frame encoded as Conway RLE.
RLE_Pattern read_rle_string(const std::string &s)
Read a Conway RLE pattern from a string.
Binary_Cell_Pattern read_life_106(std::istream &in)
Read a Life 1.06 pattern.
void write_json(std::ostream &out, const Lattice &frame, const JSON_Write_Options &opts={})
Write a JSON snapshot.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Binary pattern shared by RLE, plaintext and Life formats.
std::string name
optional pattern name
ca_index_t origin_row
original row offset before normalisation
ca_size_t height
number of rows
ca_size_t width
number of columns
Array< std::string > comments
format comments without marker prefixes
ca_index_t origin_col
original column offset before normalisation
std::string rule
optional rule string, e.g. B3/S23
Array< Coord_Vec< 2 > > alive
live cells as {row, col}
Options controlling CSV output and input.
char delimiter
separator between cells
Dense numeric snapshot used by CSV and JSON readers.
Options controlling JSON snapshot output.
bool pretty
pretty-print with indentation
Out-of-range neighbours behave as if the lattice ended.
Options controlling Life plaintext output.
std::string comment
optional ! comments, split on newlines
RGB byte triplet used by PPM exporters.
Options controlling Conway RLE output.
bool trim_dead_border
crop to the live-cell bounding box
std::string name
optional #N line
Cellular automata lattice with pluggable boundary policies.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).