Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Adds constexpr tests of the range class #272

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ add_test(testScale testScale)
add_executable(testrange testrange.cpp)
add_test(testrange testrange)

add_executable(testrange_constexpr testrange_constexpr.cpp)
add_test(testrange_constexpr testrange_constexpr)

# Test the colour mapping
add_executable(testColourMap testColourMap.cpp)
add_test(testColourMap testColourMap)
Expand Down
74 changes: 74 additions & 0 deletions tests/testrange_constexpr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <iostream>
#include <morph/range.h>
#include <morph/mathconst.h>

constexpr morph::range<float> test_update()
{
morph::range<float> r{2.0f, 4.0f};
r.update (1.0f);
r.update (5.0f);
return r;
}

constexpr morph::range<float> test_update_and_search_init()
{
morph::range<float> r;
r.search_init();
r.update (1.0f);
r.update (5.0f);
return r;
}

constexpr bool test_update_and_includes()
{
morph::range<float> r(2.0f, 4.0f); // also test 2 arg constructor
r.update (1.0f);
r.update (5.0f);
int rtn = 0;
if (r.includes (3.0f) == false) { --rtn; }
if (r.includes (0.5f) == true) { --rtn; }

return (rtn == 0 ? true : false);
}

constexpr float test_span()
{
morph::range<float> r{2.0f, 4.0f};
return r.span();
}

constexpr float test_set()
{
morph::range<float> r;
r.set (56.0f, 59.0f);
return r.span();
}

int main()
{
int rtn = 0;

constexpr morph::range<float> r1 = test_update();
if (r1.min == 1.0f && r1.max == 5.0f) {
// good
} else {
--rtn;
}
constexpr morph::range<float> r2 = test_update_and_search_init();
if (r2.min == 1.0f && r2.max == 5.0f) {
// good
} else {
--rtn;
}
constexpr bool tres = test_update_and_includes();
if (tres == false) { --rtn; }

constexpr float spn = test_span();
if (spn != 2.0f) { --rtn; }

constexpr float spn2 = test_set();
if (spn2 != 3.0f) { --rtn; }

std::cout << "Test " << (rtn == 0 ? "Passed" : "Failed") << std::endl;
return rtn;
}
Loading