Skip to content
Permalink
Browse files

TST: use properly balanced datasets as input

  • Loading branch information
nno committed Jan 31, 2020
1 parent 3079b75 commit a0849546c1ccf1ac4659a2ce1c9a211e1da66b8b
Showing with 18 additions and 17 deletions.
  1. +18 −17 tests/test_oddeven_partitioner.m
@@ -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.
You can’t perform that action at this time.