diff --git a/src/Engine/gramambular2/reading_grid_test.cpp b/src/Engine/gramambular2/reading_grid_test.cpp index 8415ada..23b2991 100644 --- a/src/Engine/gramambular2/reading_grid_test.cpp +++ b/src/Engine/gramambular2/reading_grid_test.cpp @@ -456,6 +456,81 @@ TEST(ReadingGridTest, LongGridDeletion) { ASSERT_EQ(grid.spans()[8].nodeOf(5)->reading(), "jklmn"); } +TEST(ReadingGridTest, FindNodeInSpans) { + ReadingGrid grid(std::make_shared()); + grid.setReadingSeparator(";"); + grid.insertReading("a"); + grid.insertReading("b"); + grid.insertReading("c"); + + ASSERT_FALSE( + grid.findInSpan(0, [](const auto& n) { return n->spanningLength() == 4; }) + .has_value()); + ASSERT_FALSE( + grid.findInSpan(1, [](const auto& n) { return n->spanningLength() == 0; }) + .has_value()); + ASSERT_EQ( + grid.findInSpan(0, [](const auto& n) { return n->spanningLength() == 1; }) + ->get() + ->reading(), + "a"); + ASSERT_EQ( + grid.findInSpan(1, [](const auto& n) { return n->spanningLength() == 1; }) + ->get() + ->reading(), + "b"); + ASSERT_EQ( + grid.findInSpan(2, [](const auto& n) { return n->spanningLength() == 1; }) + ->get() + ->reading(), + "c"); + ASSERT_EQ( + grid.findInSpan(3, [](const auto& n) { return n->spanningLength() == 1; }) + ->get() + ->reading(), + "c"); + ASSERT_EQ( + grid.findInSpan(0, [](const auto& n) { return n->spanningLength() == 2; }) + ->get() + ->reading(), + "a;b"); + ASSERT_EQ( + grid.findInSpan(1, [](const auto& n) { return n->spanningLength() == 2; }) + ->get() + ->reading(), + "b;c"); + ASSERT_EQ( + grid.findInSpan(2, [](const auto& n) { return n->spanningLength() == 2; }) + ->get() + ->reading(), + "b;c"); + ASSERT_EQ( + grid.findInSpan(3, [](const auto& n) { return n->spanningLength() == 2; }) + ->get() + ->reading(), + "b;c"); + ASSERT_EQ( + grid.findInSpan(0, [](const auto& n) { return n->spanningLength() == 3; }) + ->get() + ->reading(), + "a;b;c"); + ASSERT_EQ( + grid.findInSpan(1, [](const auto& n) { return n->spanningLength() == 3; }) + ->get() + ->reading(), + "a;b;c"); + ASSERT_EQ( + grid.findInSpan(2, [](const auto& n) { return n->spanningLength() == 3; }) + ->get() + ->reading(), + "a;b;c"); + ASSERT_EQ( + grid.findInSpan(3, [](const auto& n) { return n->spanningLength() == 3; }) + ->get() + ->reading(), + "a;b;c"); +} + TEST(ReadingGridTest, StressTest) { constexpr char kStressData[] = R"( ㄧ 一 -2.08170692