Skip to content

Commit

Permalink
WIP: add tiny tests + THERE'S A BUG
Browse files Browse the repository at this point in the history
Only on bit of SparseBitmask is true.
But SparseBitmask.region().cursor() seems to have two elements?
  • Loading branch information
maarzt authored and tpietzsch committed Jan 9, 2019
1 parent b1d8a51 commit 47ca2a9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/test/java/net/imglib2/roi/sparse/GrowableTreeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.imglib2.roi.sparse;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class GrowableTreeTest
{
@Test
public void testCreate() {
GrowableTree tree = new GrowableTree( new int[] { 8, 8, 8 } );
assertEquals(0, tree.height());
}
}
50 changes: 50 additions & 0 deletions src/test/java/net/imglib2/roi/sparse/SparseBitmaskTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package net.imglib2.roi.sparse;

import net.imglib2.Cursor;
import net.imglib2.RandomAccess;
import net.imglib2.roi.IterableRegion;
import net.imglib2.type.logic.NativeBoolType;
import net.imglib2.util.Localizables;
import org.junit.Test;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class SparseBitmaskTest
{
@Test
public void testCreate() {
new SparseBitmask( 3 );
}

@Test
public void testRandomAccess() {
SparseBitmask bitmask = new SparseBitmask( 3 );
RandomAccess< NativeBoolType > ra = bitmask.randomAccess();
ra.get().set( true );
assertTrue( ra.get().get() );
ra.get().set( false );
assertFalse( ra.get().get() );
}


@Test
public void testRegion() {
SparseBitmask bitmask = new SparseBitmask( 3 );
RandomAccess< NativeBoolType > ra = bitmask.randomAccess();
final long[] position = { 1, 2, 3 };
ra.setPosition( position );
ra.get().set( true );
final IterableRegion< NativeBoolType > region = bitmask.region();
Cursor< Void > cursor = region.cursor();
assertEquals(1, region.size());
assertTrue( cursor.hasNext() );
cursor.next();
assertArrayEquals( position, Localizables.asLongArray( cursor ) );
assertFalse( cursor.hasNext() );
}


}

0 comments on commit 47ca2a9

Please sign in to comment.