Skip to content

Commit

Permalink
Merge branch 'create-tests' of https://github.com/clEsperanto/clesper…
Browse files Browse the repository at this point in the history
…antoj_prototype into create-tests
  • Loading branch information
carlosuc3m committed Aug 8, 2024
2 parents 4b689c4 + 33e64b5 commit 8e50dff
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 55 deletions.
80 changes: 40 additions & 40 deletions src/test/java/TestAbsolute.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public void testAbsolute() {
ArrayJ out = MemoryJ.makeIntBuffer(device, 2, 2, 0, 2, "buffer");
out.fillMemory(-1);
Tier1.absolute(device, in, out);

int[] result = new int[4];
IntBuffer resultBuff = IntBuffer.wrap(result);
MemoryJ.readIntBuffer(out, resultBuff, 4);

assertEquals(1, Arrays.stream(result).min().getAsInt());
assertEquals(1, Arrays.stream(result).max().getAsInt());
assertEquals(1, Arrays.stream(result).average().getAsDouble());
Expand All @@ -48,11 +48,11 @@ public void testAbsolute1() {
ArrayJ in = MemoryJ.makeIntBuffer(device, 2, 2, 0, 2, "buffer");
in.fillMemory(-1);
ArrayJ out = Tier1.absolute(device, in, null);

int[] result = new int[4];
IntBuffer resultBuff = IntBuffer.wrap(result);
MemoryJ.readIntBuffer(out, resultBuff, 4);

for (int val : result)
assertEquals(1, val);
}
Expand All @@ -62,17 +62,17 @@ public void testAbsoluteImgLib2() {
int[] flatVals = {1, 1, -1, -1};
RandomAccessibleInterval<IntType> inputImg = ArrayImgs.ints(flatVals, new long[] {2, 2});
RandomAccessibleInterval<IntType> outputImg = ArrayImgs.ints(flatVals, new long[] {2, 2});


DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImgLib2Converters.copyImgLib2ToArrayJ(inputImg, device, "buffer");
ArrayJ out = ImgLib2Converters.copyImgLib2ToArrayJ(outputImg, device, "buffer");

Tier1.absolute(device, in, out);

outputImg = ImgLib2Converters.copyArrayJToImgLib2(out);


double min = outputImg.firstElement().getRealDouble();
double max = min;
double mean = 0;
Expand All @@ -83,7 +83,7 @@ public void testAbsoluteImgLib2() {
min = Math.min(min,val);
max = Math.max(max,val);
}

assertEquals(1, min);
assertEquals(1, max);
assertEquals(1, mean);
Expand All @@ -93,15 +93,15 @@ public void testAbsoluteImgLib2() {
public void testAbsolute1ImgLib2() {
int[] flatVals = {1, 1, -1, -1};
RandomAccessibleInterval<IntType> inputImg = ArrayImgs.ints(flatVals, new long[] {2, 2});


DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImgLib2Converters.copyImgLib2ToArrayJ(inputImg, device, "buffer");

ArrayJ out = Tier1.absolute(device, in, null);

RandomAccessibleInterval<IntType> outputImg = ImgLib2Converters.copyArrayJToImgLib2(out);


for (IntType px : outputImg) {
double val = px.getRealDouble();
Expand All @@ -115,7 +115,7 @@ public void testAbsoluteImagePlus() {
ImagePlus outputImp = IJ.createImage("input", 2, 2, 1, 32);
ImageProcessor inpIp = inputImp.getProcessor();
ImageProcessor outIp = outputImp.getProcessor();

int[] vals = {-1, -1, 1, 1};
int c = 0;
for (int x = 0; x < 2; x ++) {
Expand All @@ -124,18 +124,18 @@ public void testAbsoluteImagePlus() {
outIp.putPixelValue(x, y, vals[c ++]);
}
}


DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImageJConverters.copyImagePlus2ToArrayJ(inputImp, device, "buffer");
ArrayJ out = ImageJConverters.copyImagePlus2ToArrayJ(outputImp, device, "buffer");

Tier1.absolute(device, in, out);

outputImp = ImageJConverters.copyArrayJToImagePlus(out);
outIp = outputImp.getProcessor();


double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
double mean = 0;
Expand All @@ -147,7 +147,7 @@ public void testAbsoluteImagePlus() {
max = Math.max(max,val);
}
}

assertEquals(1, min);
assertEquals(1, max);
assertEquals(1, mean);
Expand All @@ -157,24 +157,24 @@ public void testAbsoluteImagePlus() {
public void testAbsolute1ImagePlus() {
ImagePlus inputImp = IJ.createImage("input", 2, 2, 1, 32);
ImageProcessor inpIp = inputImp.getProcessor();

int[] vals = {-1, -1, 1, 1};
int c = 0;
for (int x = 0; x < 2; x ++) {
for (int y = 0; y < 2; y ++) {
inpIp.putPixelValue(x, y, vals[c ++]);
}
}


DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImageJConverters.copyImagePlus2ToArrayJ(inputImp, device, "buffer");

ArrayJ out = Tier1.absolute(device, in, null);

ImagePlus outputImp = ImageJConverters.copyArrayJToImagePlus(out);
ImageProcessor outIp = outputImp.getProcessor();

for (int x = 0; x < 2; x ++) {
for (int y = 0; y < 2; y ++) {
double val = outIp.getPixelValue(x, y);
Expand All @@ -188,16 +188,16 @@ public void testAbsoluteIcySequence() {
int[] data = new int[] {1, 1, -1, -1};
Sequence inputSeq = createSequence(new long[] {2, 2}, data);
Sequence outputSeq = createSequence(new long[] {2, 2}, data);


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

Tier1.absolute(device, in, out);
outputSeq = IcyConverters.copyArrayJToSequence(out);

outputSeq = IcyConverters.copyArrayJToSequence(out);

double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
double mean = 0;
Expand All @@ -210,7 +210,7 @@ public void testAbsoluteIcySequence() {
max = Math.max(max,val);
}
}

assertEquals(1, min);
assertEquals(1, max);
assertEquals(1, mean);
Expand All @@ -220,15 +220,15 @@ public void testAbsoluteIcySequence() {
public void testAbsolute1IcySequence() {
int[] data = new int[] {1, 1, -1, -1};
Sequence inputSeq = createSequence(new long[] {2, 2}, data);


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

ArrayJ out = Tier1.absolute(device, in, null);
Sequence outputSeq = IcyConverters.copyArrayJToSequence(out);

Sequence outputSeq = IcyConverters.copyArrayJToSequence(out);

SequenceCursor cursor = new SequenceCursor(outputSeq);
for (int y = 0; y < 2; y++) {
for (int x = 0; x < 2; x++) {
Expand All @@ -237,7 +237,7 @@ public void testAbsolute1IcySequence() {
}
}
}

private static Sequence createSequence(long[] dims, int[] data)
{
while (dims.length < 3) {
Expand All @@ -252,7 +252,7 @@ private static Sequence createSequence(long[] dims, int[] data)
{
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 ++) {
Expand All @@ -263,4 +263,4 @@ private static Sequence createSequence(long[] dims, int[] data)
cursor.commitChanges();
return seq;
}
}
}
14 changes: 7 additions & 7 deletions src/test/java/TestIcySequencePushAndPull.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ public void testIcySequencePushAndPull() {
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 ++) {
Expand All @@ -35,7 +35,7 @@ public void testIcySequencePushAndPull() {
}
}
}

private static Sequence createSequence(long[] dims, int[] data)
{
while (dims.length < 3) {
Expand All @@ -50,7 +50,7 @@ private static Sequence createSequence(long[] dims, int[] data)
{
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 ++) {
Expand All @@ -61,4 +61,4 @@ private static Sequence createSequence(long[] dims, int[] data)
cursor.commitChanges();
return seq;
}
}
}
6 changes: 3 additions & 3 deletions src/test/java/TestImagePlusPushAndPull.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public void testImagePlusPushAndPull() {
}
}


DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImageJConverters.copyImagePlus2ToArrayJ(inputImp, device, "buffer");
ImagePlus outputImp = ImageJConverters.copyArrayJToImagePlus(in);


for (int z = 0; z < 2; z ++) {
inputImp.setPositionWithoutUpdate(1, 1 + z, 1);
Expand All @@ -47,4 +47,4 @@ public void testImagePlusPushAndPull() {
}
}
}
}
}
10 changes: 5 additions & 5 deletions src/test/java/TestImgLibPushAndPull.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ public void testImgLibPushAndPull() {
for (int i = 0; i < flatVals.length; i ++)
flatVals[i] = i;
RandomAccessibleInterval<IntType> inputImg = ArrayImgs.ints(flatVals, new long[] {3, 3, 2});


DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImgLib2Converters.copyImgLib2ToArrayJ(inputImg, device, "buffer");
RandomAccessibleInterval<IntType> outputImg = ImgLib2Converters.copyArrayJToImgLib2(in);

Cursor<IntType> inCursor = inputImg.cursor();
Cursor<IntType> outCursor = outputImg.cursor();

while (inCursor.hasNext()) {
inCursor.next();
outCursor.next();
assertEquals(inCursor.get().get(), outCursor.get().get());
}
}
}
}

0 comments on commit 8e50dff

Please sign in to comment.