From 7f939fc7ae6697af9c6dfbe0860cdacc6afaca88 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 22 May 2026 14:43:00 +0000 Subject: [PATCH 1/2] Add test for snap function in direction.h Co-authored-by: perim <436583+perim@users.noreply.github.com> --- tests/test_direction.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_direction.cpp b/tests/test_direction.cpp index 41483c9..121da28 100644 --- a/tests/test_direction.cpp +++ b/tests/test_direction.cpp @@ -30,5 +30,19 @@ int main() printf("min: %i max: %i\n", min, max); assert(min <= 2 && max <= 2); + for (int i = 0; i <= UINT16_MAX; i++) + { + direction expected = 0; + if (i >= 8192 && i <= 24575) expected = 16384; + else if (i >= 24576 && i <= 40959) expected = 32768; + else if (i >= 40960 && i <= 57343) expected = 49152; + + if (snap(i) != expected) { + printf("snap(%d) failed. Expected %d, got %d\n", i, expected, snap(i)); + } + assert(snap(i) == expected); + } + printf("snap tests passed\n"); + return 0; } From 58dc68a67945af5090e8cdcdb004490149560614 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 22 May 2026 15:17:27 +0000 Subject: [PATCH 2/2] Resolve merge conflict with isinr and icosr tests Co-authored-by: perim <436583+perim@users.noreply.github.com> --- dice.cpp | 3 +++ tests/test_direction.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/dice.cpp b/dice.cpp index 17193a0..e7d6f9f 100644 --- a/dice.cpp +++ b/dice.cpp @@ -15,6 +15,7 @@ void const_roll_table::init(const std::vector& weights) std::queue small; std::queue large; std::vector w; + w.reserve(size); for (int i : weights) { w.push_back(i * size); @@ -48,6 +49,8 @@ filtered_const_roll_table::filtered_const_roll_table(const std::vector& wei { assert(weights.size() == mask.size()); std::vector filtered; + filtered.reserve(mask.size()); + indices.reserve(mask.size()); for (size_t i = 0; i < mask.size(); i++) { if (mask[i]) diff --git a/tests/test_direction.cpp b/tests/test_direction.cpp index 121da28..152e2fc 100644 --- a/tests/test_direction.cpp +++ b/tests/test_direction.cpp @@ -30,6 +30,36 @@ int main() printf("min: %i max: %i\n", min, max); assert(min <= 2 && max <= 2); + const int distances[] = {0, 1, 10, 100, 1000, 10000, 65536, 100000, 1000000}; + for (int dist : distances) + { + int32_t rmax = 0, rmin = 0; + for (int i = 0; i <= UINT16_MAX; i++) + { + double exact = dist * sin(2 * M_PI * i / 65536.0) / 16.0; + int s = lround(exact); + int s5d = isinr(i, dist); + int err = s - s5d; + if (err > rmax) rmax = err; + if (err < rmin) rmin = err; + } + int limit = dist > 0 ? (dist * 2 / 65536) + 2 : 0; + printf("isinr dist %i min: %i max: %i (limit: %i)\n", dist, rmin, rmax, limit); + assert(rmin >= -limit && rmax <= limit); + + rmax = 0; rmin = 0; + for (int i = 0; i <= UINT16_MAX; i++) + { + double exact = dist * cos(2 * M_PI * i / 65536.0) / 16.0; + int c = lround(exact); + int c5d = icosr(i, dist); + int err = c - c5d; + if (err > rmax) rmax = err; + if (err < rmin) rmin = err; + } + printf("icosr dist %i min: %i max: %i (limit: %i)\n", dist, rmin, rmax, limit); + assert(rmin >= -limit && rmax <= limit); + } for (int i = 0; i <= UINT16_MAX; i++) { direction expected = 0;