@@ -863,4 +863,208 @@ contract TestHelperClamp is Test, HelperClamp {
863863 );
864864 this .clampGte (int256 (50 ), int256 (type (int128 ).max) + 1 );
865865 }
866+
867+ function test_clampArr_within_bounds () public {
868+ uint256 [] memory arr = new uint256 [](5 );
869+ arr[0 ] = 10 ;
870+ arr[1 ] = 20 ;
871+ arr[2 ] = 30 ;
872+ arr[3 ] = 40 ;
873+ arr[4 ] = 50 ;
874+ assertEq (arr[0 ], this .clampArr (arr, 0 ));
875+ assertEq (arr[2 ], this .clampArr (arr, 2 ));
876+ assertEq (arr[4 ], this .clampArr (arr, 4 ));
877+ }
878+
879+ function test_clampArr_out_of_bounds () public {
880+ uint256 [] memory arr = new uint256 [](3 );
881+ arr[0 ] = 100 ;
882+ arr[1 ] = 200 ;
883+ arr[2 ] = 300 ;
884+
885+ assertEq (this .clampArr (arr, 5 ), arr[2 ]);
886+ assertEq (this .clampArr (arr, 10 ), arr[1 ]);
887+ assertEq (this .clampArr (arr, 15 ), arr[0 ]);
888+ }
889+
890+ function test_clampArr_empty_array () public {
891+ uint256 [] memory arr = new uint256 [](0 );
892+ vm.expectRevert (abi.encodeWithSelector (HelperClamp.ClampEmptyArray.selector ));
893+ this .clampArr (arr, 0 );
894+ }
895+
896+ /**
897+ * Tests for clampArr(int256[], uint256)
898+ */
899+ function test_clampArr_int256_within_bounds () public {
900+ int256 [] memory arr = new int256 [](4 );
901+ arr[0 ] = - 100 ;
902+ arr[1 ] = - 50 ;
903+ arr[2 ] = 0 ;
904+ arr[3 ] = 50 ;
905+ assertEq (arr[0 ], this .clampArr (arr, 0 ));
906+ assertEq (arr[1 ], this .clampArr (arr, 1 ));
907+ assertEq (arr[3 ], this .clampArr (arr, 3 ));
908+ }
909+
910+ function test_clampArr_int256_out_of_bounds () public {
911+ int256 [] memory arr = new int256 [](7 );
912+ arr[0 ] = - 1000 ;
913+ arr[1 ] = - 500 ;
914+ arr[2 ] = - 100 ;
915+ arr[3 ] = 0 ;
916+ arr[4 ] = 100 ;
917+ arr[5 ] = 500 ;
918+ arr[6 ] = 1000 ;
919+
920+ assertEq (this .clampArr (arr, 10 ), arr[3 ]);
921+ assertEq (this .clampArr (arr, 20 ), arr[6 ]);
922+ assertEq (this .clampArr (arr, 25 ), arr[4 ]);
923+ }
924+
925+ function test_clampArr_int256_empty_array () public {
926+ int256 [] memory arr = new int256 [](0 );
927+ vm.expectRevert (abi.encodeWithSelector (HelperClamp.ClampEmptyArray.selector ));
928+ this .clampArr (arr, 0 );
929+ }
930+
931+ /**
932+ * Tests for clampArr(address[], uint256)
933+ */
934+ function test_clampArr_address_within_bounds () public {
935+ address [] memory arr = new address [](6 );
936+ arr[0 ] = address (0x1111 );
937+ arr[1 ] = address (0x2222 );
938+ arr[2 ] = address (0x3333 );
939+ arr[3 ] = address (0x4444 );
940+ arr[4 ] = address (0x5555 );
941+ arr[5 ] = address (0x6666 );
942+ assertEq (arr[0 ], this .clampArr (arr, 0 ));
943+ assertEq (arr[3 ], this .clampArr (arr, 3 ));
944+ assertEq (arr[5 ], this .clampArr (arr, 5 ));
945+ }
946+
947+ function test_clampArr_address_out_of_bounds () public {
948+ address [] memory arr = new address [](2 );
949+ arr[0 ] = address (0xAAAA );
950+ arr[1 ] = address (0xBBBB );
951+
952+ assertEq (this .clampArr (arr, 4 ), arr[0 ]);
953+ assertEq (this .clampArr (arr, 7 ), arr[1 ]);
954+ assertEq (this .clampArr (arr, 12 ), arr[0 ]);
955+ }
956+
957+ function test_clampArr_address_empty_array () public {
958+ address [] memory arr = new address [](0 );
959+ vm.expectRevert (abi.encodeWithSelector (HelperClamp.ClampEmptyArray.selector ));
960+ this .clampArr (arr, 0 );
961+ }
962+
963+ /**
964+ * Tests for clampArr(bool[], uint256)
965+ */
966+ function test_clampArr_bool_within_bounds () public {
967+ bool [] memory arr = new bool [](3 );
968+ arr[0 ] = true ;
969+ arr[1 ] = false ;
970+ arr[2 ] = true ;
971+ assertEq (arr[0 ], this .clampArr (arr, 0 ));
972+ assertEq (arr[1 ], this .clampArr (arr, 1 ));
973+ assertEq (arr[2 ], this .clampArr (arr, 2 ));
974+ }
975+
976+ function test_clampArr_bool_out_of_bounds () public {
977+ bool [] memory arr = new bool [](5 );
978+ arr[0 ] = false ;
979+ arr[1 ] = true ;
980+ arr[2 ] = false ;
981+ arr[3 ] = true ;
982+ arr[4 ] = false ;
983+
984+ assertEq (this .clampArr (arr, 8 ), arr[3 ]);
985+ assertEq (this .clampArr (arr, 11 ), arr[1 ]);
986+ assertEq (this .clampArr (arr, 17 ), arr[2 ]);
987+ }
988+
989+ function test_clampArr_bool_empty_array () public {
990+ bool [] memory arr = new bool [](0 );
991+ vm.expectRevert (abi.encodeWithSelector (HelperClamp.ClampEmptyArray.selector ));
992+ this .clampArr (arr, 0 );
993+ }
994+
995+ /**
996+ * Tests for clampArr(string[], uint256)
997+ */
998+ function test_clampArr_string_within_bounds () public {
999+ string [] memory arr = new string [](8 );
1000+ arr[0 ] = "first " ;
1001+ arr[1 ] = "second " ;
1002+ arr[2 ] = "third " ;
1003+ arr[3 ] = "fourth " ;
1004+ arr[4 ] = "fifth " ;
1005+ arr[5 ] = "sixth " ;
1006+ arr[6 ] = "seventh " ;
1007+ arr[7 ] = "eighth " ;
1008+ assertEq (arr[0 ], this .clampArr (arr, 0 ));
1009+ assertEq (arr[4 ], this .clampArr (arr, 4 ));
1010+ assertEq (arr[7 ], this .clampArr (arr, 7 ));
1011+ }
1012+
1013+ function test_clampArr_string_out_of_bounds () public {
1014+ string [] memory arr = new string [](4 );
1015+ arr[0 ] = "alpha " ;
1016+ arr[1 ] = "beta " ;
1017+ arr[2 ] = "gamma " ;
1018+ arr[3 ] = "delta " ;
1019+
1020+ assertEq (this .clampArr (arr, 6 ), arr[2 ]);
1021+ assertEq (this .clampArr (arr, 13 ), arr[1 ]);
1022+ assertEq (this .clampArr (arr, 20 ), arr[0 ]);
1023+ }
1024+
1025+ function test_clampArr_string_empty_array () public {
1026+ string [] memory arr = new string [](0 );
1027+ vm.expectRevert (abi.encodeWithSelector (HelperClamp.ClampEmptyArray.selector ));
1028+ this .clampArr (arr, 0 );
1029+ }
1030+
1031+ /**
1032+ * Tests for clampArr(bytes[], uint256)
1033+ */
1034+ function test_clampArr_bytes_within_bounds () public {
1035+ bytes [] memory arr = new bytes [](10 );
1036+ arr[0 ] = hex "00 " ;
1037+ arr[1 ] = hex "11 " ;
1038+ arr[2 ] = hex "22 " ;
1039+ arr[3 ] = hex "33 " ;
1040+ arr[4 ] = hex "44 " ;
1041+ arr[5 ] = hex "55 " ;
1042+ arr[6 ] = hex "66 " ;
1043+ arr[7 ] = hex "77 " ;
1044+ arr[8 ] = hex "88 " ;
1045+ arr[9 ] = hex "99 " ;
1046+ assertEq (arr[0 ], this .clampArr (arr, 0 ));
1047+ assertEq (arr[5 ], this .clampArr (arr, 5 ));
1048+ assertEq (arr[9 ], this .clampArr (arr, 9 ));
1049+ }
1050+
1051+ function test_clampArr_bytes_out_of_bounds () public {
1052+ bytes [] memory arr = new bytes [](6 );
1053+ arr[0 ] = hex "AAAA " ;
1054+ arr[1 ] = hex "BBBB " ;
1055+ arr[2 ] = hex "CCCC " ;
1056+ arr[3 ] = hex "DDDD " ;
1057+ arr[4 ] = hex "EEEE " ;
1058+ arr[5 ] = hex "FFFF " ;
1059+
1060+ assertEq (this .clampArr (arr, 9 ), arr[3 ]);
1061+ assertEq (this .clampArr (arr, 19 ), arr[1 ]);
1062+ assertEq (this .clampArr (arr, 30 ), arr[0 ]);
1063+ }
1064+
1065+ function test_clampArr_bytes_empty_array () public {
1066+ bytes [] memory arr = new bytes [](0 );
1067+ vm.expectRevert (abi.encodeWithSelector (HelperClamp.ClampEmptyArray.selector ));
1068+ this .clampArr (arr, 0 );
1069+ }
8661070}
0 commit comments