@@ -609,3 +609,225 @@ UTEST(test_MHArray, ClearEmptyArray)
609
609
ASSERT_EQ (array.Count (), 0 );
610
610
ASSERT_EQ (array.Data (), nullptr );
611
611
}
612
+
613
+ UTEST (test_MHArray, IterateWithFunction)
614
+ {
615
+ MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
616
+
617
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
618
+
619
+ size_t i = 0 ;
620
+ array.ForEach ([&](uint32_t & val) {
621
+ ASSERT_EQ (expectedResults[i], val);
622
+ i++;
623
+ });
624
+ }
625
+
626
+ UTEST (test_MHArray, IterateWithFunctionAndIndex)
627
+ {
628
+ MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
629
+
630
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
631
+
632
+ array.ForEachI ([&](uint32_t & val, size_t i) { ASSERT_EQ (expectedResults[i], val); });
633
+ }
634
+
635
+ UTEST (test_MHArray, IterateWithConstFunction)
636
+ {
637
+ MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
638
+
639
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
640
+
641
+ size_t i = 0 ;
642
+ array.ForEach ([&](const uint32_t & val) {
643
+ ASSERT_EQ (expectedResults[i], val);
644
+ i++;
645
+ });
646
+ }
647
+
648
+ UTEST (test_MHArray, IterateWithConstFunctionOnConstArray)
649
+ {
650
+ const MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
651
+
652
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
653
+
654
+ size_t i = 0 ;
655
+ array.ForEach ([&](const uint32_t & val) {
656
+ ASSERT_EQ (expectedResults[i], val);
657
+ i++;
658
+ });
659
+ }
660
+
661
+ UTEST (test_MHArray, IterateWithConstFunctionAndIndex)
662
+ {
663
+ MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
664
+
665
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
666
+
667
+ array.ForEachI ([&](const uint32_t & val, size_t i) { ASSERT_EQ (expectedResults[i], val); });
668
+ }
669
+
670
+ UTEST (test_MHArray, IterateWithConstFunctionAndIndexOnConstArray)
671
+ {
672
+ const MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
673
+
674
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
675
+
676
+ array.ForEachI ([&](const uint32_t & val, size_t i) { ASSERT_EQ (expectedResults[i], val); });
677
+ }
678
+
679
+ UTEST (test_MHArray, IterateWithFunctionOverZeroSizedArray)
680
+ {
681
+ MHArray<uint32_t > array;
682
+
683
+ size_t i = 0 ;
684
+ array.ForEach ([&](uint32_t & val) { i++; });
685
+
686
+ ASSERT_EQ (i, 0 );
687
+ }
688
+
689
+ UTEST (test_MHArray, IterateWithFunctionOverEmptyArray)
690
+ {
691
+ MHArray<uint32_t > array (5 );
692
+
693
+ size_t i = 0 ;
694
+ array.ForEach ([&](uint32_t & val) { i++; });
695
+
696
+ ASSERT_EQ (i, 5 );
697
+ }
698
+
699
+ UTEST (test_MHArray, IterateWithFunctionOverZeroSizedArrayWithIndex)
700
+ {
701
+ MHArray<uint32_t > array;
702
+
703
+ size_t iterations = 0 ;
704
+ array.ForEachI ([&](uint32_t & val, size_t i) { iterations++; });
705
+
706
+ ASSERT_EQ (iterations, 0 );
707
+ }
708
+
709
+ UTEST (test_MHArray, IterateWithFunctionOverEmptyArrayWithIndex)
710
+ {
711
+ MHArray<uint32_t > array (5 );
712
+
713
+ size_t iterations = 0 ;
714
+ array.ForEachI ([&](uint32_t & val, size_t i) { iterations++; });
715
+
716
+ ASSERT_EQ (iterations, 5 );
717
+ }
718
+
719
+ UTEST (test_MHArray, IterateWithManagedFunction)
720
+ {
721
+ MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
722
+
723
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
724
+
725
+ size_t i = 0 ;
726
+ array.MForEach ([&](uint32_t & val) {
727
+ ASSERT_EQ (expectedResults[i], val);
728
+ i++;
729
+ });
730
+ }
731
+
732
+ UTEST (test_MHArray, IterateWithManagedFunctionAndIndex)
733
+ {
734
+ MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
735
+
736
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
737
+
738
+ array.MForEachI ([&](uint32_t & val, size_t i) { ASSERT_EQ (expectedResults[i], val); });
739
+ }
740
+
741
+ UTEST (test_MHArray, IterateWithManagedFunctionOnConstArray)
742
+ {
743
+ const MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
744
+
745
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
746
+
747
+ size_t i = 0 ;
748
+ array.MForEach ([&](const uint32_t & val) {
749
+ ASSERT_EQ (expectedResults[i], val);
750
+ i++;
751
+ });
752
+ }
753
+
754
+ UTEST (test_MHArray, IterateWithManagedFunctionAndIndexOnConstArray)
755
+ {
756
+ const MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
757
+
758
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
759
+
760
+ array.MForEachI ([&](const uint32_t & val, size_t i) { ASSERT_EQ (expectedResults[i], val); });
761
+ }
762
+
763
+ UTEST (test_MHArray, IterateWithManagedFunctionAndConstant)
764
+ {
765
+ MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
766
+
767
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
768
+
769
+ size_t i = 0 ;
770
+ array.MForEach ([&](const uint32_t & val) {
771
+ ASSERT_EQ (expectedResults[i], val);
772
+ i++;
773
+ });
774
+ }
775
+
776
+ UTEST (test_MHArray, IterateWithManagedFunctionAndIndexAndConstant)
777
+ {
778
+ MHArray<uint32_t > array = {1 , 2 , 3 , 4 , 5 };
779
+
780
+ uint32_t expectedResults[] = {1 , 2 , 3 , 4 , 5 };
781
+
782
+ array.MForEachI ([&](const uint32_t & val, size_t i) { ASSERT_EQ (expectedResults[i], val); });
783
+ }
784
+
785
+ UTEST (test_MHArray, IterateWithManagedFunctionWithGaps)
786
+ {
787
+ MHArray<uint32_t > array (5 );
788
+
789
+ array[1 ] = 2 ;
790
+ array[3 ] = 4 ;
791
+ array[4 ] = 0 ;
792
+
793
+ uint32_t expectedResults[] = {2 , 4 , 0 };
794
+
795
+ size_t i = 0 ;
796
+ array.MForEach ([&](uint32_t & val) {
797
+ ASSERT_EQ (expectedResults[i], val);
798
+ i++;
799
+ });
800
+ }
801
+
802
+ UTEST (test_MHArray, IterateWithManagedFunctionAndIndexWithGaps)
803
+ {
804
+ MHArray<uint32_t > array (5 );
805
+
806
+ array[1 ] = 2 ;
807
+ array[3 ] = 4 ;
808
+ array[4 ] = 0 ;
809
+
810
+ uint32_t expectedResults[] = {2 , 4 , 0 };
811
+
812
+ array.MForEachI ([&](uint32_t & val, size_t i) { ASSERT_EQ (expectedResults[i], val); });
813
+ }
814
+
815
+ UTEST (test_MHArray, IterateOverEmptyArrayWithManagedFunction)
816
+ {
817
+ MHArray<uint32_t > array;
818
+
819
+ size_t iterations = 0 ;
820
+ array.MForEach ([&](uint32_t & val) { iterations++; });
821
+
822
+ ASSERT_EQ (0 , iterations);
823
+ }
824
+
825
+ UTEST (test_MHArray, IterateOverEmptyArrayWithManagedFunctionAndIndex)
826
+ {
827
+ MHArray<uint32_t > array;
828
+
829
+ size_t iterations = 0 ;
830
+ array.MForEachI ([&](uint32_t & val, size_t i) { iterations++; });
831
+
832
+ ASSERT_EQ (0 , iterations);
833
+ }
0 commit comments