from test/more import *;
let s := << 1, 2, 2 >>;
s.add(3);
s.push(4);
is( s.length(), 4, "add/push and dedupe" );
s.remove(2);
is( s.contains(2), 0, "remove" );
is( s.count(), 3, "count" );
is( s.empty(), 0, "empty false" );
is( << >>.is_empty(), 1, "is_empty true" );
is( s.to_Array().length(), 3, "to_Array" );
is( s.to_Bag().length(), 3, "to_Bag" );
let set_it := << 3, 4, 5 >>.to_Iterator();
let set_total := 0;
for ( let v in set_it ) {
	set_total += v;
}
is( set_total, 12, "to_Iterator" );
let u := s.union( << 3, 5 >> );
is( u.length(), 4, "union" );
let i := s.intersection( << 3, 9 >> );
is( i.contains(3), 1, "intersection" );
let d := s.difference( << 1, 9 >> );
is( d.contains(1), 0, "difference" );
let sd := s.symmetric_difference( << 3, 5 >> );
is( sd.contains(5), 1, "symmetric_difference" );
is( s.is_subset(u), 1, "is_subset" );
is( u.is_superset(s), 1, "is_superset" );
is( s.is_disjoint( << 9 >> ), 1, "is_disjoint" );
is( s.equals( << 1, 3, 4 >> ), 1, "equals" );
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" );
let mapped := << 1, 2 >>.map( fn x -> x mod 2 );
is( mapped.length(), 2, "map" );
let grepped := << 1, 2, 3 >>.grep( fn x -> x > 1 );
is( grepped.length(), 2, "grep" );
is( << 1, 2, 3 >>.any( fn x -> x = 2 ), 1, "any" );
is( << 2, 4, 6 >>.all( fn x -> x mod 2 = 0 ), 1, "all" );
is( << 1, 8, 10 >>.first( fn x -> x > 5 ), 8, "first" );
let s2 := << 1, 2, 3, 4 >>;
s2.remove_if( fn x -> x mod 2 = 0 );
is( s2.length(), 2, "remove_if" );
let total := 0;
<< 1, 2, 3 >>.for_each_value( fn x -> total := total + x );
is( total, 6, "for_each_value" );
s.clear();
is( s.length(), 0, "clear" );
done_testing();
