Skip to content

Commit

Permalink
TST: use properly balanced datasets as input
Browse files Browse the repository at this point in the history
  • Loading branch information
nno committed Jan 31, 2020
1 parent 3079b75 commit a084954
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions tests/test_oddeven_partitioner.m
Expand Up @@ -71,23 +71,24 @@ function assert_cell_same_elements(p,q)

function test_unbalanced_partitions()
ds=struct();
ntargets=randi();
nchunks=randi();
ds.samples=randn(ntargets*nchunks,1);
ds.sa.chunks=repmat(1:nchunks,1,ntargets)';
ds.sa.targets=repmat(1:ntargets,1,nchunks)';

idxs=cosmo_randperm(numel(ds.sa.chunks));
ds=cosmo_slice(ds,idxs);

% should be ok
cosmo_oddeven_partitioner(ds);

idx=ceil(rand()*ntargets*nchunks);
ds.sa.chunks(idx)=ds.sa.chunks(idx)+1;
assertExceptionThrown(@() cosmo_oddeven_partitioner(ds),'*');
for ntargets=2:5
for nchunks=2:5
nsamples=ntargets*nchunks;
ds.samples=randn(nsamples,1);
ds.sa.chunks=repmat(1:nchunks,1,ntargets)';
ds.sa.targets=ceil((1:nsamples)'/nchunks);

idxs=cosmo_randperm(numel(ds.sa.chunks));
ds=cosmo_slice(ds,idxs);

% should be ok
cosmo_oddeven_partitioner(ds);

idx=ceil(rand()*ntargets*nchunks);
ds.sa.chunks(idx)=ds.sa.chunks(idx)+1;
assertExceptionThrown(@() cosmo_oddeven_partitioner(ds),'*');
end
end

function v=randi()
v=ceil(rand()*10+2);


0 comments on commit a084954

Please sign in to comment.