From b941baf6bbb96a3f68a8a0047597c11756a242fc Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 13 Feb 2026 07:52:38 +0700 Subject: [PATCH] additional nr/to spawn/lookup tests --- develop/testing/clone_tests.lua | 162 ++++++++++++++++++++++++++ develop/testing/lookup_tests.lua | 19 +++ develop/testing/multi_spawn_tests.lua | 161 +++++++++++++++++++++++++ 3 files changed, 342 insertions(+) diff --git a/develop/testing/clone_tests.lua b/develop/testing/clone_tests.lua index 26b2d6e..29b3c32 100644 --- a/develop/testing/clone_tests.lua +++ b/develop/testing/clone_tests.lua @@ -397,3 +397,165 @@ do end end end + +do + local f1, f2 = evo.id(2) + local p = evo.spawn { [f1] = 42, [f2] = 'hello' } + + do + local entity_list, entity_count = {}, 2 + evo.multi_clone_to(entity_list, 1, entity_count, p) + assert(evo.has_all(entity_list[1], f1, f2)) + assert(evo.has_all(entity_list[2], f1, f2)) + assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == 'hello') + assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello') + end + + do + local entity_list, entity_count = {}, 2 + evo.multi_clone_to(entity_list, 2, entity_count, p) + assert(evo.has_all(entity_list[2], f1, f2)) + assert(evo.has_all(entity_list[3], f1, f2)) + assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello') + assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == 'hello') + end + + do + local entity_list, entity_count = {}, 2 + evo.defer() + evo.multi_clone_to(entity_list, 1, entity_count, p) + assert(entity_list[1] and entity_list[2]) + assert(evo.empty_all(entity_list[1], entity_list[2])) + evo.commit() + assert(evo.has_all(entity_list[1], f1, f2)) + assert(evo.has_all(entity_list[2], f1, f2)) + assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == 'hello') + assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello') + end + + do + local entity_list, entity_count = {}, 2 + evo.defer() + evo.multi_clone_to(entity_list, 2, entity_count, p) + assert(entity_list[2] and entity_list[3]) + assert(evo.empty_all(entity_list[2], entity_list[3])) + evo.commit() + assert(evo.has_all(entity_list[2], f1, f2)) + assert(evo.has_all(entity_list[3], f1, f2)) + assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello') + assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == 'hello') + end +end + +do + local f1, f2 = evo.id(2) + local q12 = evo.builder():include(f1, f2):build() + local p = evo.spawn { [f1] = 42, [f2] = 'hello' } + + do + assert(select('#', evo.multi_clone_nr(2, p)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 3) + end + end + + do + local b = evo.builder():set(f1, 42):set(f2, 'hello') + + assert(select('#', b:multi_clone_nr(2, p)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 5) + end + end + + do + local b = evo.builder():set(f1, 42):set(f2, 'hello') + + assert(select('#', b:multi_build_nr(2, p)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 7) + end + end +end + +do + local f1, f2 = evo.id(2) + local q12 = evo.builder():include(f1, f2):build() + local p = evo.spawn { [f1] = 42, [f2] = 'hello' } + + do + local entity_list = {} + assert(select('#', evo.multi_clone_to(entity_list, 1, 2, p)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 3) + end + end + + do + local b = evo.builder():set(f1, 42):set(f2, 'hello') + + local entity_list = {} + assert(select('#', b:multi_clone_to(entity_list, 1, 2, p)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 5) + end + end + + do + local b = evo.builder():set(f1, 42):set(f2, 'hello') + + local entity_list = {} + assert(select('#', b:multi_build_to(entity_list, 1, 2, p)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 7) + end + end +end diff --git a/develop/testing/lookup_tests.lua b/develop/testing/lookup_tests.lua index bc1374d..1120662 100644 --- a/develop/testing/lookup_tests.lua +++ b/develop/testing/lookup_tests.lua @@ -174,3 +174,22 @@ do assert(entity_list and #entity_list == 0 and entity_count == 0) end end + +do + local e1, e2 = evo.id(2) + + evo.set(e1, evo.NAME, 'lookup_e') + evo.set(e2, evo.NAME, 'lookup_e') + + do + local entity_list = {} + local entity_count = evo.multi_lookup_to(entity_list, 1, 'lookup_e') + assert(entity_count == 2 and entity_list[1] == e1 and entity_list[2] == e2) + end + + do + local entity_list = {} + local entity_count = evo.multi_lookup_to(entity_list, 2, 'lookup_e') + assert(entity_count == 2 and entity_list[2] == e1 and entity_list[3] == e2) + end +end diff --git a/develop/testing/multi_spawn_tests.lua b/develop/testing/multi_spawn_tests.lua index 8908e17..e0d0e7b 100644 --- a/develop/testing/multi_spawn_tests.lua +++ b/develop/testing/multi_spawn_tests.lua @@ -607,3 +607,164 @@ do end end end + +do + local f1, f2 = evo.id(2) + + do + local entity_list, entity_count = {}, 2 + evo.multi_spawn_to(entity_list, 1, entity_count, { [f1] = 42, [f2] = "hello" }) + assert(evo.has_all(entity_list[1], f1, f2)) + assert(evo.has_all(entity_list[2], f1, f2)) + assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == "hello") + assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello") + end + + do + local entity_list, entity_count = {}, 2 + evo.multi_spawn_to(entity_list, 2, entity_count, { [f1] = 42, [f2] = "hello" }) + assert(evo.has_all(entity_list[2], f1, f2)) + assert(evo.has_all(entity_list[3], f1, f2)) + assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello") + assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == "hello") + end + + do + local entity_list, entity_count = {}, 2 + evo.defer() + evo.multi_spawn_to(entity_list, 1, entity_count, { [f1] = 42, [f2] = "hello" }) + assert(entity_list[1] and entity_list[2]) + assert(evo.empty_all(entity_list[1], entity_list[2])) + evo.commit() + assert(evo.has_all(entity_list[1], f1, f2)) + assert(evo.has_all(entity_list[2], f1, f2)) + assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == "hello") + assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello") + end + + do + local entity_list, entity_count = {}, 2 + evo.defer() + evo.multi_spawn_to(entity_list, 2, entity_count, { [f1] = 42, [f2] = "hello" }) + assert(entity_list[2] and entity_list[3]) + assert(evo.empty_all(entity_list[2], entity_list[3])) + evo.commit() + assert(evo.has_all(entity_list[2], f1, f2)) + assert(evo.has_all(entity_list[3], f1, f2)) + assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello") + assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == "hello") + end +end + +do + local f1, f2 = evo.id(2) + local q12 = evo.builder():include(f1, f2):spawn() + + do + assert(select('#', evo.multi_spawn_nr(2, { [f1] = 42, [f2] = "hello" })) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 2) + end + end + + do + local b = evo.builder():set(f1, 42):set(f2, "hello") + + assert(select('#', b:multi_spawn_nr(2)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 4) + end + end + + do + local b = evo.builder():set(f1, 42):set(f2, "hello") + + assert(select('#', b:multi_build_nr(2)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 6) + end + end +end + +do + local f1, f2 = evo.id(2) + local q12 = evo.builder():include(f1, f2):spawn() + + do + local entity_list = {} + assert(select('#', evo.multi_spawn_to(entity_list, 1, 2, { [f1] = 42, [f2] = "hello" })) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 2) + end + end + + do + local b = evo.builder():set(f1, 42):set(f2, "hello") + + + local entity_list = {} + assert(select('#', b:multi_spawn_to(entity_list, 1, 2)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 4) + end + end + + do + local b = evo.builder():set(f1, 42):set(f2, "hello") + + + local entity_list = {} + assert(select('#', b:multi_build_to(entity_list, 1, 2)) == 0) + + do + local entity_count = 0 + + for chunk in evo.execute(q12) do + local _, chunk_entity_count = chunk:entities() + entity_count = entity_count + chunk_entity_count + end + + assert(entity_count == 6) + end + end +end