from
DataStructures
by Paul Richards
Set and map datastructures implemented in pure Matlab
|
| SortedSetTest
|
function test = SortedSetTest
test = munit_testcase;
function setup
end
function teardown
end
function test_create
set = SortedSet();
test.assert( @() isequal(class(set), 'SortedSet') );
test.assert( @() IsEmpty(set) );
test.assert( @() Size(set) == 0 );
end
function test_insert
set = SortedSet();
values = randperm(20);
values = [values values(1:5)];
for v = values
set = Insert(set, v);
CheckConstraints(set);
end
values = sort(unique(values));
test.assert( @() ~IsEmpty(set) );
size = Size(set);
test.assert( @() size == length(values) );
test.assert( @() First(set) == values(1) );
test.assert( @() Last(set) == values(length(values)) );
values = values(randperm(20));
for v = values
[set, removed_value] = Remove(set, v);
CheckConstraints(set);
test.assert( @() removed_value == v );
size = size - 1;
test.assert( @() IsEmpty(set) == (size == 0) );
set_size = Size(set);
test.assert( @() set_size == size );
for w = values(1:(length(values)-size))
test.assert( @() ~Contains(set, w) );
end
for w = values((1+length(values)-size):length(values))
test.assert( @() Contains(set, w) );
end
end
test.assert( @() size == 0 ); % sanity check
end
end
|
|
Contact us at files@mathworks.com