@@ -24,7 +24,7 @@ describe("clamp", () => {
2424 } ) ;
2525
2626 test (
27- "returns the upper boundary when the upper boundary is less than the lower boundary" ,
27+ "returns the upper boundary if the upper boundary is less than the lower boundary" ,
2828 ( ) => {
2929 expect ( clamp ( 5 , 10 , 1 ) ) . toBe ( 1 ) ;
3030 }
@@ -56,48 +56,48 @@ describe("upperBoundBinarySearch", () => {
5656 const emptyArray : number [ ] = [ ] ;
5757 const singleElementArray = [ 3 ] ;
5858 const array = [ - 5 , - 3 , 0 , 1 , 1 , 8 , 8 , 8 , 100 ] ;
59- test ( "returns null for empty collection with fake highIdx" , ( ) => {
59+ test ( "returns null if collection is empty with lowIdx < highIdx" , ( ) => {
6060 const result = upperBoundBinarySearch ( ( idx ) => emptyArray [ idx ] , 0 , 1 , 5 ) ;
6161 expect ( result ) . toBeNull ( ) ;
6262 } ) ;
63- test ( "returns null for empty collection with valid highIdx" , ( ) => {
63+ test ( "returns null if collection is empty with highIdx < lowIdx " , ( ) => {
6464 const result = upperBoundBinarySearch ( ( idx ) => emptyArray [ idx ] , 0 , - 1 , 5 ) ;
6565 expect ( result ) . toBeNull ( ) ;
6666 } ) ;
67- test ( "returns the first index for upperboundValue < all elements in array" , ( ) => {
67+ test ( "returns the first index if upperboundValue < all elements in array" , ( ) => {
6868 const result = upperBoundBinarySearch ( ( idx ) => array [ idx ] , 0 , array . length - 1 , - 10 ) ;
6969 expect ( result ) . toBe ( 0 ) ;
7070 } ) ;
71- test ( "returns the first index for upperboundValue < element in singleElementArray" , ( ) => {
71+ test ( "returns the first index if upperboundValue < element in singleElementArray" , ( ) => {
7272 const result = upperBoundBinarySearch ( ( idx ) => singleElementArray [ idx ] , 0 , 0 , - 10 ) ;
7373 expect ( result ) . toBe ( 0 ) ;
7474 } ) ;
75- test ( "returns the last index for upperboundValue > all elements in array" , ( ) => {
75+ test ( "returns the last index if upperboundValue > all elements in array" , ( ) => {
7676 const result = upperBoundBinarySearch ( ( idx ) => array [ idx ] , 0 , array . length - 1 , 200 ) ;
7777 expect ( result ) . toBe ( array . length - 1 ) ;
7878 } ) ;
79- test ( "returns the last index for upperboundValue > element in singleElementArray" , ( ) => {
79+ test ( "returns the last index if upperboundValue > element in singleElementArray" , ( ) => {
8080 const result = upperBoundBinarySearch ( ( idx ) => singleElementArray [ idx ] , 0 , 0 , 200 ) ;
8181 expect ( result ) . toBe ( 0 ) ;
8282 } ) ;
83- test ( "returns the index for upperboundValue doesn't exactly match any elements" , ( ) => {
83+ test ( "returns the correct index if upperboundValue doesn't match any elements" , ( ) => {
8484 const result = upperBoundBinarySearch ( ( idx ) => array [ idx ] , 0 , array . length - 1 , 2 ) ;
8585 expect ( result ) . toBe ( 4 ) ;
8686 } ) ;
87- test ( "returns the index for upperboundValue matches a unique element" , ( ) => {
87+ test ( "returns the correct index if upperboundValue matches a unique element" , ( ) => {
8888 const result = upperBoundBinarySearch ( ( idx ) => array [ idx ] , 0 , array . length - 1 , 0 ) ;
8989 expect ( result ) . toBe ( 2 ) ;
9090 } ) ;
91- test ( "returns the index for upperboundValue matches a duplicated element" , ( ) => {
91+ test ( "returns the last matched index if upperboundValue matches a duplicated element" , ( ) => {
9292 const result = upperBoundBinarySearch ( ( idx ) => array [ idx ] , 0 , array . length - 1 , 8 ) ;
9393 expect ( result ) . toBe ( 7 ) ;
9494 } ) ;
95- test ( "returns the first element index " , ( ) => {
95+ test ( "returns index 0 if upperboundValue matches the first element" , ( ) => {
9696 const result = upperBoundBinarySearch ( ( idx ) => array [ idx ] , 0 , array . length - 1 , - 5 ) ;
9797 expect ( result ) . toBe ( 0 ) ;
9898 } ) ;
99- test ( "returns the last element index" , ( ) => {
99+ test ( "returns the last index if upperboundValue matches the last element " , ( ) => {
100100 const result = upperBoundBinarySearch ( ( idx ) => array [ idx ] , 0 , array . length - 1 , 100 ) ;
101- expect ( result ) . toBe ( 8 ) ;
101+ expect ( result ) . toBe ( array . length - 1 ) ;
102102 } ) ;
103103} ) ;
0 commit comments