@@ -970,36 +970,34 @@ pub fn max_test() {
970
970
971
971
pub fn sample_test ( ) {
972
972
assert list . sample( [ ] , 3) == [ ]
973
-
974
973
as sert list . sample( [ 1 , 2 , 3 ] , 0 ) == [ ]
975
-
976
974
as sert list . sample( [ 1 , 2 , 3 ] , - 1) == [ ]
977
-
978
- as sert [ 1 , 2 ]
979
- |> list . sample( 5 )
980
- |> list . sort( int. compare )
981
- == [ 1 , 2 ]
982
-
975
+ as sert list . sort( list . sample( [ 1 , 2 ] , 5 ) , int. compare ) == [ 1 , 2 ]
983
976
as sert list . sample( [ 1 ] , 1 ) == [ 1 ]
984
977
985
- let input = list . range ( 1 , 100 )
986
- let sample = list . sample ( input , 10 )
987
- assert list . length( sample) == 10
978
+ as sert 10
979
+ == list . range( 1 , 100 )
980
+ |> list . sample( 10 )
981
+ |> list . unique
982
+ |> list . length
983
+
984
+ as sert [ 1 , 1 , 1 , 1 , 1 ]
985
+ |> list . sample( 3 )
986
+ |> list . all( fn ( x ) { x == 1 } )
988
987
989
- let repeated = [ 1 , 1 , 1 , 1 , 1 ]
990
- let sample = list . sample ( repeated , 3 )
991
- assert list . all( sample, fn ( x ) { x == 1 } )
988
+ // Some tests on a bigger sample.
989
+ let sample =
990
+ list . range ( 1 , 1000 )
991
+ |> list . sample ( 100 )
992
992
993
- let input = list . range ( 1 , 1000 )
994
- let sample = list . sample ( input , 100 )
995
993
assert sample
996
994
|> list. sort( int. compare)
997
995
|> list. all( fn ( x ) { x >= 1 && x <= 1000 } )
998
996
999
- assert list . length( sample) == 100
997
+ assert 100 == list . length( list . unique ( sample ) )
1000
998
1001
- let min = list . fold ( sample , 1000 , int . min )
1002
- let max = list . fold ( sample , 1 , int . max )
999
+ let assert Ok ( min ) = list . reduce ( sample , int . min )
1000
+ let assert Ok ( max ) = list . reduce ( sample , int . max )
1003
1001
assert min >= 1
1004
1002
assert max <= 1000
1005
1003
}
0 commit comments