Wednesday, January 20, 2010

ColorModelTest.java ~ Unit Test Program

/** Unit Test for ColorModel
Author: Daniel J. Tanner
Date: 1/20/2010
Class: CMPT 360 - Computer Graphics
*/

/** This program extends the jUnit TestCase,
in order to test out the colormodel class.
It should be noted that since the colormodel program
deals with doubles, we cannot test that changing from RGB
to some other colorspace and back again will result in
exactly the same value, so we must come up with a way
of determining that said value is close enough to the
original value entered. We will do this by assuming
a standard deviation within .0001 to be accurate enough.
*/

import junit.framework.TestCase;

public class ColorModelTest extends TestCase
{
//Create variables
private double[] someRGB = {1, .5, .5};

/*isCloseEnough function - returns true if there is < .0001 difference
between two doubles
*/
public boolean isCloseEnough(double x, double y)
{
if(Math.abs(x - y) < .01)
return true;
else
return false;
}

/**********************************************************************

Testing Functions

***********************************************************************/
public void testHSV()
{
double[] someHSV = ColorModel.RGBtoHSV(someRGB);
someHSV = ColorModel.HSVtoRGB(someHSV);
for(int index = 0; index < 3; index++)
assertTrue(isCloseEnough(someRGB[index], someHSV[index]));
}

public void testCMY()
{
//Test RGB to CMY and CMY to RGB
double[] someCMY = ColorModel.RGBtoCMY(someRGB);
someCMY = ColorModel.CMYtoRGB(someCMY);
for(int index = 0; index < 3; index++)
assertTrue(isCloseEnough(someRGB[index], someCMY[index]));
}

public void testXYZ()
{
//Test RGB to XYZ and XYZ to RGB
double[] someXYZ = ColorModel.RGBtoXYZ(someRGB);
someXYZ = ColorModel.XYZtoRGB(someXYZ);
for(int index = 0; index < 3; index++)
assertTrue(isCloseEnough(someRGB[index], someXYZ[index]));
}

public void testYIQ()
{
//test YIQ
double[] someYIQ = ColorModel.RGBtoYIQ(someRGB);
someYIQ = ColorModel.YIQtoRGB(someYIQ);
for(int index = 0; index < 3; index++)
assertTrue(isCloseEnough(someRGB[index], someYIQ[index]));
}

public void testLAB()
{
//test L*A*B*
double[] someLAB = ColorModel.RGBtoCIELab(someRGB);
someLAB = ColorModel.CIELabtoRGB(someLAB);
for(int index = 0; index < 3; index++)
assertTrue(isCloseEnough(someRGB[index], someLAB[index]));
}

public void testLUV()
{
//test LUV
double[] someLUV = ColorModel.RGBtoCIELuv(someRGB);
someLUV = ColorModel.CIELuvtoRGB(someLUV);
for(int index = 0; index < 3; index++)
assertTrue(isCloseEnough(someRGB[index], someLUV[index]));
}
}

No comments:

Post a Comment