public class check implements Testlet
{
public void test(TestHarness h)
{
float[] data = new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, };
Kernel k = new Kernel(3, 4, data);
h.check(k != null);
h.check(k.getWidth() == 3);
h.check(k.getHeight() == 4);
h.check(k.getXOrigin() == 1);
h.check(k.getYOrigin() == 1);
float[] data1;
try
{
data1 = k.getKernelData(null);
}
catch (IllegalArgumentException e)
{
data1 = new float[0];
h.fail("Kernel.getKernelData");
}
h.checkPoint("Check kernel data");
boolean ok = true;
h.check(data1.length == data.length);
for (int i=0; i < data1.length; i++)
if (data[i] != data1[i])
{
ok = false;
break;
}
h.check(ok == true);
data1 = new float[12];
try
{
data1 = k.getKernelData(data1);
}
catch (IllegalArgumentException e)
{
h.fail("Kernel.getKernelData");
}
ok = true;
h.check(data1.length == data.length);
for (int i=0; i < data1.length; i++)
if (data[i] != data1[i])
{
ok = false;
break;
}
h.check(ok == true);
// Check failure modes
h.checkPoint("Failure modes");
ok = false;
try
{
k.getKernelData(new float[1]);
}
catch (IllegalArgumentException e)
{
ok = true;
}
h.check(ok == true);
ok = false;
try
{
k = new Kernel(10, 10, data);
}
catch (IllegalArgumentException e)
{
ok = true;
}
h.check(ok == true);
// Check that only the specified data gets copied
data = new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
k = new Kernel(3, 4, data);
data1 = k.getKernelData(null);
h.check(data1.length == 12);
ok = true;
for (int i=0; i < data1.length; i++)
if (data[i] != data1[i])
{