Skip to content

Commit

Permalink
test push and pull icy
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Aug 8, 2024
1 parent ce9ff1d commit 4621318
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/test/java/TestIcySequencePushAndPull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import org.junit.jupiter.api.Test;

import icy.image.IcyBufferedImage;
import icy.sequence.Sequence;
import icy.sequence.SequenceCursor;
import net.clesperanto.icy.IcyConverters;
import net.clesperanto.core.ArrayJ;
import net.clesperanto.core.DeviceJ;

import static org.junit.jupiter.api.Assertions.*;

public class TestIcySequencePushAndPull {

@Test
public void testIcySequencePushAndPull() {
int[] flatVals = new int[18];
for (int i = 0; i < flatVals.length; i ++)
flatVals[i] = i;
Sequence inputSeq = createSequence(new long[] {3, 3, 2}, flatVals);


DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = IcyConverters.copySequenceToArrayJ(inputSeq, device, "buffer");

Sequence outputSeq = IcyConverters.copyArrayJToSequence(in);

SequenceCursor inCursor = new SequenceCursor(inputSeq);
SequenceCursor outCursor = new SequenceCursor(outputSeq);

for (int y = 0; y < 3; y ++) {
for (int x = 0; x < 3; x ++) {
for (int z = 0; z < 2; z ++) {
assertEquals(inCursor.get(x, y, z, 0, 0), outCursor.get(x, y, z, 0, 0));
}
}
}
}

private static Sequence createSequence(long[] dims, int[] data)
{
while (dims.length < 3) {
long[] newArray = new long[dims.length + 1];
System.arraycopy(dims, 0, newArray, 0, dims.length);
newArray[dims.length] = 1;
dims = newArray;
}
Sequence seq = new Sequence();
int z;
for (z = 0; z < dims[2]; z++)
{
seq.setImage(0, z, new IcyBufferedImage((int) dims[0], (int) dims[1], 1, icy.type.DataType.INT));
}

SequenceCursor cursor = new SequenceCursor(seq);
int c = 0;
for (int x = 0; x < dims[0]; x ++) {
for (int y = 0; x < dims[1]; y ++) {
cursor.set(x, y, 0, 0, 0, data[c ++]);
}
}
cursor.commitChanges();
return seq;
}
}

0 comments on commit 4621318

Please sign in to comment.