from test/more import *;
let a := [ 1, 2 ];
a.append(3);
a.push(4);
a.add(5);
is( a.length(), 5, "append/push/add" );
is( a.pop(), 5, "pop" );
a.prepend(0);
a.unshift( -1 );
is( a.shift(), -1, "shift" );
is( a.count(), 5, "count" );
is( a.empty(), 0, "empty false" );
is( [].is_empty(), 1, "is_empty true" );
is( a.get( 0, 99 ), 0, "get existing" );
is( a.get( 99, 42 ), 42, "get default" );
a.set( 0, 9 );
is( a.get( 0, 0 ), 9, "set" );
let mapped := a.map( fn x -> x * 2 );
is( mapped.get( 0, 0 ), 18, "map" );
let grepped := a.grep( fn x -> x > 2 );
is( grepped.length(), 3, "grep" );
is( a.any( fn x -> x = 4 ), 1, "any" );
is( a.all( fn x -> x > -1 ), 1, "all" );
is( a.first( fn x -> x > 2 ), 9, "first" );
a.remove( fn x -> x = 9 );
is( a.contains(9), 0, "remove" );
is( a.first_index( fn x -> x = 3 ), 2, "first_index" );
let reduced := [ 1, 2, 3 ].reduce( function( x, y ) {
	return x + y;
}
);
is( reduced, 6, "reduce" );
let runs := [ 1, 2, 3 ].reductions( function( x, y ) {
	return x + y;
}
);
is( runs.get( 2, 0 ), 6, "reductions" );
is( [ "1", "2", 3 ].sum(), 6, "sum casts" );
is( [ "2", "3", 4 ].product(), 24, "product casts" );
is( [ 1, 2, 3 ].head(2).length(), 2, "head" );
is( [ 1, 2, 3 ].tail(2).get( 0, 0 ), 2, "tail" );
is( [ 1, 2, 3 ].shuffle().length(), 3, "shuffle" );
is( [ 1, 2, 3 ].sample(2).length(), 2, "sample" );
let visited := 0;
[ 1, 2, 3 ].for_each_value( fn x -> visited := visited + x );
is( visited, 6, "for_each_value" );
let sorted := [ 1, 3, 2 ].sort( function( x, y ) {
	return y <=> x;
}
);
is( sorted.get( 0, 0 ), 3, "sort" );
is( [ 2, 10, 1 ].sortstr().get( 1, "" ), 10, "sortstr" );
is( [ "2", "10", "1" ].sortnum().get( 1, 0 ), 2, "sortnum" );
is( [ 1, 2, 3 ].reverse().get( 0, 0 ), 3, "reverse" );
is( [ 1, 1, 2 ].to_Set().length(), 2, "to_Set" );
is( [ 1, 2 ].to_Bag().length(), 2, "to_Bag" );
let arr_it := [ 4, 5, 6 ].to_Iterator();
let arr_total := 0;
for ( let v in arr_it ) {
	arr_total += v;
}
is( arr_total, 15, "to_Iterator" );
a.clear();
is( a.length(), 0, "clear" );
done_testing();
