Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adds tests for the new Morton Code class #187

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Adds tests for the new Morton Code class #187

wants to merge 5 commits into from

Conversation

Fletterio
Copy link
Contributor

Checks that the arithmetic and comparisons work as expected + checks it compiles for GPU

Comment on lines 55 to 198
// -------------------------------------- SUBTRACTION -------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// ---------------------------------------- Signed -----------------------------------------------------

// No overflow
assert(static_cast<vector_t>(morton_t(vector_t(1000, 764, -365)) - morton_t(vector_t(834, -243, 100))) == vector_t(166, 1007, -465));

// Type 1 overflow: Subtraction of representable coordinates goes out of range
assert(static_cast<vector_t>(morton_t(vector_t(-900, 70, 500)) - morton_t(vector_t(578, -50, -20))) == vector_t(570, 120, -504));

// Type 2 overflow: Subtraction of irrepresentable range gives correct result
assert(static_cast<vector_t>(morton_t(vector_t(54, 900, -475)) - morton_t(vector_t(-46, 1437, -699))) == vector_t(100, -537, 224));

// ---------------------------------------- Unsigned -----------------------------------------------------

// No overflow
assert(static_cast<unsigned_vector_t>(unsigned_morton_t(unsigned_vector_t(382, 910, 543)) - unsigned_morton_t(unsigned_vector_t(322, 564, 299))) == unsigned_vector_t(60, 346, 244));

// Type 1 overflow: Subtraction of representable coordinates goes out of range
assert(static_cast<unsigned_vector_t>(unsigned_morton_t(unsigned_vector_t(382, 910, 543)) - unsigned_morton_t(unsigned_vector_t(2000, 2000, 1000))) == unsigned_vector_t(430, 958, 567));

// Type 2 overflow: Subtraction of irrepresentable range gives correct result
assert(static_cast<unsigned_vector_t>(unsigned_morton_t(unsigned_vector_t(54, 900, 475)) - unsigned_morton_t(unsigned_vector_t(-865, -100, -10))) == unsigned_vector_t(919, 1000, 485));


// ----------------------------------------------------------------------------------------------------
// -------------------------------------- UNARY NEGATION ----------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Only makes sense for signed
assert(static_cast<vector_t>(- morton_t(vector_t(-1024, 543, -475))) == vector_t(-1024, -543, 475));

// ***********************************************************************************************************************************
// ************************************************* Comparison operator tests *******************************************************
// ***********************************************************************************************************************************

// ----------------------------------------------------------------------------------------------------
// -------------------------------------- OPERATOR< ---------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Signed

// Same sign, negative
assert(morton_t(vector_t(-954, -455, -333)) < morton_t(vector_t(-433, -455, -433)) == bool_vector_t(true, false, false));
// Same sign, positive
assert(morton_t(vector_t(954, 455, 333)) < morton_t(vector_t(433, 455, 433)) == bool_vector_t(false, false, true));
// Differing signs
assert(morton_t(vector_t(954, -32, 0)) < morton_t(vector_t(-44, 0, -1)) == bool_vector_t(false, true, false));

// Unsigned
assert(unsigned_morton_t(unsigned_vector_t(239, 435, 66)) < unsigned_morton_t(unsigned_vector_t(240, 435, 50)) == bool_vector_t(true, false, false));

// ----------------------------------------------------------------------------------------------------
// -------------------------------------- OPERATOR<= --------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Signed

// Same sign, negative
assert(morton_t(vector_t(-954, -455, -333)) <= morton_t(vector_t(-433, -455, -433)) == bool_vector_t(true, true, false));
// Same sign, positive
assert(morton_t(vector_t(954, 455, 333)) <= morton_t(vector_t(433, 455, 433)) == bool_vector_t(false, true, true));
// Differing signs
assert(morton_t(vector_t(954, -32, 0)) <= morton_t(vector_t(-44, 0, -1)) == bool_vector_t(false, true, false));

// Unsigned
assert(unsigned_morton_t(unsigned_vector_t(239, 435, 66)) <= unsigned_morton_t(unsigned_vector_t(240, 435, 50)) == bool_vector_t(true, true, false));

// ----------------------------------------------------------------------------------------------------
// -------------------------------------- OPERATOR> ---------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Signed

// Same sign, negative
assert(morton_t(vector_t(-954, -455, -333)) > morton_t(vector_t(-433, -455, -433)) == bool_vector_t(false, false, true));
// Same sign, positive
assert(morton_t(vector_t(954, 455, 333)) > morton_t(vector_t(433, 455, 433)) == bool_vector_t(true, false, false));
// Differing signs
assert(morton_t(vector_t(954, -32, 0)) > morton_t(vector_t(-44, 0, -1)) == bool_vector_t(true, false, true));

// Unsigned
assert(unsigned_morton_t(unsigned_vector_t(239, 435, 66)) > unsigned_morton_t(unsigned_vector_t(240, 435, 50)) == bool_vector_t(false, false, true));

// ----------------------------------------------------------------------------------------------------
// -------------------------------------- OPERATOR>= --------------------------------------------------
// ----------------------------------------------------------------------------------------------------

// Signed

// Same sign, negative
assert(morton_t(vector_t(-954, -455, -333)) >= morton_t(vector_t(-433, -455, -433)) == bool_vector_t(false, true, true));
// Same sign, positive
assert(morton_t(vector_t(954, 455, 333)) >= morton_t(vector_t(433, 455, 433)) == bool_vector_t(true, true, false));
// Differing signs
assert(morton_t(vector_t(954, -32, 0)) >= morton_t(vector_t(-44, 0, -1)) == bool_vector_t(true, false, true));

// Unsigned
assert(unsigned_morton_t(unsigned_vector_t(239, 435, 66)) >= unsigned_morton_t(unsigned_vector_t(240, 435, 50)) == bool_vector_t(false, true, true));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmon, do single source testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single source?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see bits of example 22, there's same code you include both in some C++ function and HLSL shader, you run same code in both tests

CMakeLists.txt Outdated
@@ -95,7 +95,8 @@ if(NBL_BUILD_EXAMPLES)
add_subdirectory(67_RayQueryGeometry EXCLUDE_FROM_ALL)
add_subdirectory(68_JpegLoading EXCLUDE_FROM_ALL)

add_subdirectory(70_FLIPFluids EXCLUDE_FROM_ALL)
add_subdirectory(70_FLIPFluids EXCLUDE_FROM_ALL)
add_subdirectory(XX_Mortons EXCLUDE_FROM_ALL)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take number 12

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants