Skip to content

Commit

Permalink
Extend test coverage (#310)
Browse files Browse the repository at this point in the history
* PyImathTestC

Signed-off-by: Cary Phillips <[email protected]>

* Random, Color, Frustum, PyImathTestC

Signed-off-by: Cary Phillips <[email protected]>

* Python_VERSION

Signed-off-by: Cary Phillips <[email protected]>

* set PYTHONPATH property

Signed-off-by: Cary Phillips <[email protected]>

* remove <iostream>

Signed-off-by: Cary Phillips <[email protected]>

---------

Signed-off-by: Cary Phillips <[email protected]>
  • Loading branch information
cary-ilm authored Mar 20, 2023
1 parent f5b7ae6 commit 7355971
Show file tree
Hide file tree
Showing 8 changed files with 2,719 additions and 79 deletions.
137 changes: 59 additions & 78 deletions src/ImathTest/testColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,97 +186,78 @@ testColor ()

IMATH_INTERNAL_NAMESPACE::C4f c4f, r4f, tmp4f;

c4f.r = 1.0f;
c4f.g = 1.0f;
c4f.b = 1.0f;
c4f.a = 1.0f;
tmp4f = rgb2hsv(c4f);
r4f = hsv2rgb(tmp4f);
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.r, c4f.r, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.g, c4f.g, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.b, c4f.b, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.a, c4f.a, 1e-5f));

c4f.r = 1.0f;
c4f.g = 1.0f;
c4f.b = 0.0f;
c4f.a = 0.0f;
tmp4f = rgb2hsv(c4f);
r4f = hsv2rgb(tmp4f);
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.r, c4f.r, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.g, c4f.g, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.b, c4f.b, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.a, c4f.a, 1e-5f));

for (float r=0.0f; r<=1.0; r += 1.0f)
for (float g=0.0f; g<=1.0; g += 1.0f)
for (float b=0.0f; b<=1.0; b += 1.0f)
{
c4f.r = r;
c4f.g = g;
c4f.b = b;
c4f.a = 1.0f;
tmp4f = rgb2hsv(c4f);
r4f = hsv2rgb(tmp4f);
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.r, c4f.r, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.g, c4f.g, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.b, c4f.b, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4f.a, c4f.a, 1e-5f));
}

// C3f

IMATH_INTERNAL_NAMESPACE::C3f c3f, r3f, tmp3f;

c3f.x = 1.0f;
c3f.y = 1.0f;
c3f.z = 1.0f;
tmp3f = rgb2hsv(c3f);
r3f = hsv2rgb(tmp3f);
assert (IMATH_INTERNAL_NAMESPACE::equal (r3f.x, c3f.x, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3f.y, c3f.y, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3f.z, c3f.z, 1e-5f));

c3f.x = 1.0f;
c3f.y = 1.0f;
c3f.z = 0.0f;
tmp3f = rgb2hsv(c3f);
r3f = hsv2rgb(tmp3f);
assert (IMATH_INTERNAL_NAMESPACE::equal (r3f.x, c3f.x, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3f.y, c3f.y, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3f.z, c3f.z, 1e-5f));

for (float r=0.0f; r<=1.0; r += 1.0f)
for (float g=0.0f; g<=1.0; g += 1.0f)
for (float b=0.0f; b<=1.0; b += 1.0f)
{
c3f.x = r;
c3f.y = g;
c3f.z = b;
tmp3f = rgb2hsv(c3f);
r3f = hsv2rgb(tmp3f);
assert (IMATH_INTERNAL_NAMESPACE::equal (r3f.x, c3f.x, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3f.y, c3f.y, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3f.z, c3f.z, 1e-5f));
}

// C4d

IMATH_INTERNAL_NAMESPACE::Color4<double> c4d, r4d, tmp4d;

c4d.r = 1.0;
c4d.g = 1.0;
c4d.b = 1.0;
c4d.a = 1.0;
tmp4d = rgb2hsv(c4d);
r4d = hsv2rgb(tmp4d);
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.r, c4d.r, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.g, c4d.g, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.b, c4d.b, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.a, c4d.a, 1e-5f));

c4d.r = 1.0;
c4d.g = 1.0;
c4d.b = 0.0;
c4d.a = 0.0;
tmp4d = rgb2hsv(c4d);
r4d = hsv2rgb(tmp4d);
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.r, c4d.r, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.g, c4d.g, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.b, c4d.b, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.a, c4d.a, 1e-5f));
for (double r=0.0; r<=1.0; r += 1.0)
for (double g=0.0; g<=1.0; g += 1.0)
for (double b=0.0; b<=1.0; b += 1.0)
{
c4d.r = r;
c4d.g = g;
c4d.b = b;
c4d.a = 1.0;
tmp4d = rgb2hsv(c4d);
r4d = hsv2rgb(tmp4d);
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.r, c4d.r, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.g, c4d.g, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.b, c4d.b, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r4d.a, c4d.a, 1e-5f));
}


// C3d

IMATH_INTERNAL_NAMESPACE::Color3<double> c3d, r3d, tmp3d;

c3d.x = 1.0;
c3d.y = 1.0;
c3d.z = 1.0;
tmp3d = rgb2hsv(c3d);
r3d = hsv2rgb(tmp3d);
assert (IMATH_INTERNAL_NAMESPACE::equal (r3d.x, c3d.x, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3d.y, c3d.y, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3d.z, c3d.z, 1e-5f));

c3d.x = 1.0;
c3d.y = 1.0;
c3d.z = 0.0;
tmp3d = rgb2hsv(c3d);
r3d = hsv2rgb(tmp3d);
assert (IMATH_INTERNAL_NAMESPACE::equal (r3d.x, c3d.x, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3d.y, c3d.y, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3d.z, c3d.z, 1e-5f));
for (double r=0.0; r<=1.0; r += 1.0)
for (double g=0.0; g<=1.0; g += 1.0)
for (double b=0.0; b<=1.0; b += 1.0)
{
c3d.x = r;
c3d.y = g;
c3d.z = b;
tmp3d = rgb2hsv(c3d);
r3d = hsv2rgb(tmp3d);
assert (IMATH_INTERNAL_NAMESPACE::equal (r3d.x, c3d.x, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3d.y, c3d.y, 1e-5f));
assert (IMATH_INTERNAL_NAMESPACE::equal (r3d.z, c3d.z, 1e-5f));
}

cout << "ok\n" << endl;
}
8 changes: 8 additions & 0 deletions src/ImathTest/testFrustumTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ testFrustumTest ()
assert (!frustumTest.isVisible (outsideVec_far));
assert (!frustumTest.isVisible (outsideVec_side));
assert (!frustumTest.isVisible (outsideVec_up));

cout << "passed Vec3\n";

/////////////////////////////////////////////////////
Expand All @@ -78,6 +79,10 @@ testFrustumTest ()
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> (
insideVec + tinySize, insideVec + tinySize)));

assert (frustumTest.completelyContains (
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> (
insideVec + tinySize, insideVec + tinySize)));

// Huge boxes inside and outside should be visible
assert (frustumTest.isVisible (
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> (
Expand Down Expand Up @@ -119,6 +124,9 @@ testFrustumTest ()
assert (frustumTest.isVisible (
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (insideVec, tinyRadius)));

assert (frustumTest.completelyContains(
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (insideVec, tinyRadius)));

// Huge spheres inside and outside should be visible
assert (frustumTest.isVisible (
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (insideVec, hugeRadius)));
Expand Down
39 changes: 39 additions & 0 deletions src/ImathTest/testRandom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,38 @@ testErand48 ()
assert (state[2] == 0x306d);
}

void
testDrand48 ()
{
std::cout << "testDrand48()" << std::endl;

//
// Confirm that drand48/lrand48 return the same values as
// erand48/nrand48 with the same seed.
//

unsigned short state[3];
state[2] = 0;
state[1] = 0;
state[0] = 0x330e;

IMATH_INTERNAL_NAMESPACE::srand48(0);

double e = IMATH_INTERNAL_NAMESPACE::erand48(state);
double d = IMATH_INTERNAL_NAMESPACE::drand48();
assert (e == d);

state[2] = 0;
state[1] = 0;
state[0] = 0x330e;

IMATH_INTERNAL_NAMESPACE::srand48(0);

long int n = IMATH_INTERNAL_NAMESPACE::nrand48(state);
long int l = IMATH_INTERNAL_NAMESPACE::lrand48();
assert (l == n);
}

template <class Rand>
void
testGenerator ()
Expand Down Expand Up @@ -218,12 +250,19 @@ testRandom ()
cout << "erand48(), nrand48()" << endl;
testErand48 ();

cout << "drand48(), lrand48()" << endl;
testDrand48 ();

cout << "Rand32" << endl;
testGenerator<IMATH_INTERNAL_NAMESPACE::Rand32> ();

cout << "Rand48" << endl;
testGenerator<IMATH_INTERNAL_NAMESPACE::Rand48> ();

cout << "Rand48" << endl;
testGenerator<IMATH_INTERNAL_NAMESPACE::Rand48> ();


cout << "solidSphereRand()" << endl;
testSolidSphere<IMATH_INTERNAL_NAMESPACE::Rand32> ();

Expand Down
17 changes: 17 additions & 0 deletions src/python/PyImathTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ if(TARGET Python3::Interpreter)
set_tests_properties(PyImath.PyImathTest_Python3 PROPERTIES
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/python${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}"
)

add_executable(PyImathTestC main.cpp testStringTable.cpp)

target_link_libraries(PyImathTestC
Imath::Config
Imath::PyImath_Python${Python_VERSION_MAJOR}_${Python_VERSION_MINOR}
Python3::Python
Boost::${PYIMATH_BOOST_PY_COMPONENT})
set_target_properties(PyImathTestC PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

add_test(NAME Imath.PyImathTestC COMMAND $<TARGET_FILE:PyImathTestC>)
set(PYTHONPATH ${CMAKE_BINARY_DIR}/python${Python_VERSION_MAJOR}_${Python_VERSION_MINOR})
set_tests_properties(Imath.PyImathTestC PROPERTIES ENVIRONMENT PYTHONPATH=${PYTHONPATH})

endif()

Loading

0 comments on commit 7355971

Please sign in to comment.