Skip to content

Commit

Permalink
Add testing upperBound function acting on values.
Browse files Browse the repository at this point in the history
  • Loading branch information
HaxyM committed Aug 28, 2024
1 parent dc54223 commit 3d9533d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ crap_test(signbittype)
crap_test(subsatvalue)
crap_test(trunctype)
crap_test(upperboundtype)
crap_test(upperboundvalue)
42 changes: 42 additions & 0 deletions test/upperboundvaluetest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "../include/crap/algorithm.d/upperboundfortype.h"

#include <cstdlib>
#include <functional>
#include <iostream>
#include <iterator>
#include <numeric>

#include "testutils.h"
#include "../include/crap/utility.d/valuelist.h"

bool test_upperBoundValueTrivialTest()
{
using valueTestType = unsigned int;
constexpr const static valueTestType Constrain = 42u;
constexpr const static valueTestType Subject = 7u;
static_assert(Subject < Constrain, "Subject should be smaller than Constrain so test may function.");

//TODO: Make sequence random.
using testList1 =
crap :: valueList<valueTestType, 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u, Subject, Subject + 1u, Constrain>;
using testedFun = crap :: upperBoundForType<
valueTestType,
Subject,
lessConstrainedForType <valueTestType, Constrain> :: template type>;
using testResult_t = typename testList1 :: copy <testedFun :: template type>;
constexpr const static auto testResult = testResult_t :: value;
static_assert(testResult < testList1 :: size + 1u, "Subject should be somewher!");
static_assert(testList1 :: data()[testResult - 1u] == Subject, "Subject in wrong place");
return true;
}

int main()
{
const bool results[] = {
test_upperBoundValueTrivialTest()
};
return std :: accumulate(std :: begin(results), std :: end(results), true, std :: logical_and<bool>())
? EXIT_SUCCESS
: EXIT_FAILURE;
}

0 comments on commit 3d9533d

Please sign in to comment.