Skip to content

Commit b941baf

Browse files
committed
additional nr/to spawn/lookup tests
1 parent 8b77b45 commit b941baf

3 files changed

Lines changed: 342 additions & 0 deletions

File tree

develop/testing/clone_tests.lua

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,165 @@ do
397397
end
398398
end
399399
end
400+
401+
do
402+
local f1, f2 = evo.id(2)
403+
local p = evo.spawn { [f1] = 42, [f2] = 'hello' }
404+
405+
do
406+
local entity_list, entity_count = {}, 2
407+
evo.multi_clone_to(entity_list, 1, entity_count, p)
408+
assert(evo.has_all(entity_list[1], f1, f2))
409+
assert(evo.has_all(entity_list[2], f1, f2))
410+
assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == 'hello')
411+
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello')
412+
end
413+
414+
do
415+
local entity_list, entity_count = {}, 2
416+
evo.multi_clone_to(entity_list, 2, entity_count, p)
417+
assert(evo.has_all(entity_list[2], f1, f2))
418+
assert(evo.has_all(entity_list[3], f1, f2))
419+
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello')
420+
assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == 'hello')
421+
end
422+
423+
do
424+
local entity_list, entity_count = {}, 2
425+
evo.defer()
426+
evo.multi_clone_to(entity_list, 1, entity_count, p)
427+
assert(entity_list[1] and entity_list[2])
428+
assert(evo.empty_all(entity_list[1], entity_list[2]))
429+
evo.commit()
430+
assert(evo.has_all(entity_list[1], f1, f2))
431+
assert(evo.has_all(entity_list[2], f1, f2))
432+
assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == 'hello')
433+
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello')
434+
end
435+
436+
do
437+
local entity_list, entity_count = {}, 2
438+
evo.defer()
439+
evo.multi_clone_to(entity_list, 2, entity_count, p)
440+
assert(entity_list[2] and entity_list[3])
441+
assert(evo.empty_all(entity_list[2], entity_list[3]))
442+
evo.commit()
443+
assert(evo.has_all(entity_list[2], f1, f2))
444+
assert(evo.has_all(entity_list[3], f1, f2))
445+
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == 'hello')
446+
assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == 'hello')
447+
end
448+
end
449+
450+
do
451+
local f1, f2 = evo.id(2)
452+
local q12 = evo.builder():include(f1, f2):build()
453+
local p = evo.spawn { [f1] = 42, [f2] = 'hello' }
454+
455+
do
456+
assert(select('#', evo.multi_clone_nr(2, p)) == 0)
457+
458+
do
459+
local entity_count = 0
460+
461+
for chunk in evo.execute(q12) do
462+
local _, chunk_entity_count = chunk:entities()
463+
entity_count = entity_count + chunk_entity_count
464+
end
465+
466+
assert(entity_count == 3)
467+
end
468+
end
469+
470+
do
471+
local b = evo.builder():set(f1, 42):set(f2, 'hello')
472+
473+
assert(select('#', b:multi_clone_nr(2, p)) == 0)
474+
475+
do
476+
local entity_count = 0
477+
478+
for chunk in evo.execute(q12) do
479+
local _, chunk_entity_count = chunk:entities()
480+
entity_count = entity_count + chunk_entity_count
481+
end
482+
483+
assert(entity_count == 5)
484+
end
485+
end
486+
487+
do
488+
local b = evo.builder():set(f1, 42):set(f2, 'hello')
489+
490+
assert(select('#', b:multi_build_nr(2, p)) == 0)
491+
492+
do
493+
local entity_count = 0
494+
495+
for chunk in evo.execute(q12) do
496+
local _, chunk_entity_count = chunk:entities()
497+
entity_count = entity_count + chunk_entity_count
498+
end
499+
500+
assert(entity_count == 7)
501+
end
502+
end
503+
end
504+
505+
do
506+
local f1, f2 = evo.id(2)
507+
local q12 = evo.builder():include(f1, f2):build()
508+
local p = evo.spawn { [f1] = 42, [f2] = 'hello' }
509+
510+
do
511+
local entity_list = {}
512+
assert(select('#', evo.multi_clone_to(entity_list, 1, 2, p)) == 0)
513+
514+
do
515+
local entity_count = 0
516+
517+
for chunk in evo.execute(q12) do
518+
local _, chunk_entity_count = chunk:entities()
519+
entity_count = entity_count + chunk_entity_count
520+
end
521+
522+
assert(entity_count == 3)
523+
end
524+
end
525+
526+
do
527+
local b = evo.builder():set(f1, 42):set(f2, 'hello')
528+
529+
local entity_list = {}
530+
assert(select('#', b:multi_clone_to(entity_list, 1, 2, p)) == 0)
531+
532+
do
533+
local entity_count = 0
534+
535+
for chunk in evo.execute(q12) do
536+
local _, chunk_entity_count = chunk:entities()
537+
entity_count = entity_count + chunk_entity_count
538+
end
539+
540+
assert(entity_count == 5)
541+
end
542+
end
543+
544+
do
545+
local b = evo.builder():set(f1, 42):set(f2, 'hello')
546+
547+
local entity_list = {}
548+
assert(select('#', b:multi_build_to(entity_list, 1, 2, p)) == 0)
549+
550+
do
551+
local entity_count = 0
552+
553+
for chunk in evo.execute(q12) do
554+
local _, chunk_entity_count = chunk:entities()
555+
entity_count = entity_count + chunk_entity_count
556+
end
557+
558+
assert(entity_count == 7)
559+
end
560+
end
561+
end

develop/testing/lookup_tests.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,22 @@ do
174174
assert(entity_list and #entity_list == 0 and entity_count == 0)
175175
end
176176
end
177+
178+
do
179+
local e1, e2 = evo.id(2)
180+
181+
evo.set(e1, evo.NAME, 'lookup_e')
182+
evo.set(e2, evo.NAME, 'lookup_e')
183+
184+
do
185+
local entity_list = {}
186+
local entity_count = evo.multi_lookup_to(entity_list, 1, 'lookup_e')
187+
assert(entity_count == 2 and entity_list[1] == e1 and entity_list[2] == e2)
188+
end
189+
190+
do
191+
local entity_list = {}
192+
local entity_count = evo.multi_lookup_to(entity_list, 2, 'lookup_e')
193+
assert(entity_count == 2 and entity_list[2] == e1 and entity_list[3] == e2)
194+
end
195+
end

develop/testing/multi_spawn_tests.lua

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,164 @@ do
607607
end
608608
end
609609
end
610+
611+
do
612+
local f1, f2 = evo.id(2)
613+
614+
do
615+
local entity_list, entity_count = {}, 2
616+
evo.multi_spawn_to(entity_list, 1, entity_count, { [f1] = 42, [f2] = "hello" })
617+
assert(evo.has_all(entity_list[1], f1, f2))
618+
assert(evo.has_all(entity_list[2], f1, f2))
619+
assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == "hello")
620+
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello")
621+
end
622+
623+
do
624+
local entity_list, entity_count = {}, 2
625+
evo.multi_spawn_to(entity_list, 2, entity_count, { [f1] = 42, [f2] = "hello" })
626+
assert(evo.has_all(entity_list[2], f1, f2))
627+
assert(evo.has_all(entity_list[3], f1, f2))
628+
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello")
629+
assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == "hello")
630+
end
631+
632+
do
633+
local entity_list, entity_count = {}, 2
634+
evo.defer()
635+
evo.multi_spawn_to(entity_list, 1, entity_count, { [f1] = 42, [f2] = "hello" })
636+
assert(entity_list[1] and entity_list[2])
637+
assert(evo.empty_all(entity_list[1], entity_list[2]))
638+
evo.commit()
639+
assert(evo.has_all(entity_list[1], f1, f2))
640+
assert(evo.has_all(entity_list[2], f1, f2))
641+
assert(evo.get(entity_list[1], f1) == 42 and evo.get(entity_list[1], f2) == "hello")
642+
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello")
643+
end
644+
645+
do
646+
local entity_list, entity_count = {}, 2
647+
evo.defer()
648+
evo.multi_spawn_to(entity_list, 2, entity_count, { [f1] = 42, [f2] = "hello" })
649+
assert(entity_list[2] and entity_list[3])
650+
assert(evo.empty_all(entity_list[2], entity_list[3]))
651+
evo.commit()
652+
assert(evo.has_all(entity_list[2], f1, f2))
653+
assert(evo.has_all(entity_list[3], f1, f2))
654+
assert(evo.get(entity_list[2], f1) == 42 and evo.get(entity_list[2], f2) == "hello")
655+
assert(evo.get(entity_list[3], f1) == 42 and evo.get(entity_list[3], f2) == "hello")
656+
end
657+
end
658+
659+
do
660+
local f1, f2 = evo.id(2)
661+
local q12 = evo.builder():include(f1, f2):spawn()
662+
663+
do
664+
assert(select('#', evo.multi_spawn_nr(2, { [f1] = 42, [f2] = "hello" })) == 0)
665+
666+
do
667+
local entity_count = 0
668+
669+
for chunk in evo.execute(q12) do
670+
local _, chunk_entity_count = chunk:entities()
671+
entity_count = entity_count + chunk_entity_count
672+
end
673+
674+
assert(entity_count == 2)
675+
end
676+
end
677+
678+
do
679+
local b = evo.builder():set(f1, 42):set(f2, "hello")
680+
681+
assert(select('#', b:multi_spawn_nr(2)) == 0)
682+
683+
do
684+
local entity_count = 0
685+
686+
for chunk in evo.execute(q12) do
687+
local _, chunk_entity_count = chunk:entities()
688+
entity_count = entity_count + chunk_entity_count
689+
end
690+
691+
assert(entity_count == 4)
692+
end
693+
end
694+
695+
do
696+
local b = evo.builder():set(f1, 42):set(f2, "hello")
697+
698+
assert(select('#', b:multi_build_nr(2)) == 0)
699+
700+
do
701+
local entity_count = 0
702+
703+
for chunk in evo.execute(q12) do
704+
local _, chunk_entity_count = chunk:entities()
705+
entity_count = entity_count + chunk_entity_count
706+
end
707+
708+
assert(entity_count == 6)
709+
end
710+
end
711+
end
712+
713+
do
714+
local f1, f2 = evo.id(2)
715+
local q12 = evo.builder():include(f1, f2):spawn()
716+
717+
do
718+
local entity_list = {}
719+
assert(select('#', evo.multi_spawn_to(entity_list, 1, 2, { [f1] = 42, [f2] = "hello" })) == 0)
720+
721+
do
722+
local entity_count = 0
723+
724+
for chunk in evo.execute(q12) do
725+
local _, chunk_entity_count = chunk:entities()
726+
entity_count = entity_count + chunk_entity_count
727+
end
728+
729+
assert(entity_count == 2)
730+
end
731+
end
732+
733+
do
734+
local b = evo.builder():set(f1, 42):set(f2, "hello")
735+
736+
737+
local entity_list = {}
738+
assert(select('#', b:multi_spawn_to(entity_list, 1, 2)) == 0)
739+
740+
do
741+
local entity_count = 0
742+
743+
for chunk in evo.execute(q12) do
744+
local _, chunk_entity_count = chunk:entities()
745+
entity_count = entity_count + chunk_entity_count
746+
end
747+
748+
assert(entity_count == 4)
749+
end
750+
end
751+
752+
do
753+
local b = evo.builder():set(f1, 42):set(f2, "hello")
754+
755+
756+
local entity_list = {}
757+
assert(select('#', b:multi_build_to(entity_list, 1, 2)) == 0)
758+
759+
do
760+
local entity_count = 0
761+
762+
for chunk in evo.execute(q12) do
763+
local _, chunk_entity_count = chunk:entities()
764+
entity_count = entity_count + chunk_entity_count
765+
end
766+
767+
assert(entity_count == 6)
768+
end
769+
end
770+
end

0 commit comments

Comments
 (0)