-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlfp_tests.hpp
More file actions
72 lines (65 loc) · 1.62 KB
/
Copy pathlfp_tests.hpp
File metadata and controls
72 lines (65 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* MIT License
* Copyright (c) 2025 Youcef Lemsafer
* See LICENSE file for more details.
* Creation date: May 2025.
*/
#pragma once
#include "catch2/catch_test_macros.hpp"
#include "catch2/matchers/catch_matchers_all.hpp"
#if LFP_HAS_UINT128 && defined(__GNUC__)
# if (__GNUC__ < 13)
# define LFP_DISABLE_TESTS_ABOVE_64_BITS
# endif
# if defined(LFP_FORCE_TESTS_ABOVE_64_BITS) && defined(LFP_DISABLE_TESTS_ABOVE_64_BITS)
# undef LFP_DISABLE_TESTS_ABOVE_64_BITS
# endif
#endif // LFP_HAS_UINT128
template <typename T>
inline std::vector<T>
primes_by_division(uint64_t a, uint64_t b)
{
std::vector<T> results;
if(a <= 2) {
if(b > 2) {
results.push_back(2);
}
a = 3;
}
constexpr auto cmax = std::numeric_limits<decltype(b)>::max();
for(auto c = a | 1; c < b; c = (c > cmax - 2) ? cmax : c + 2) {
if(!(c % 3) && (c != 3)) {
continue;
}
bool isPrime = true;
int w[] = {2,4}, i = 0;
for(uint64_t p = 5; (p * p <= c) && (p <= std::numeric_limits<uint32_t>::max()); p += w[i], i^=1) {
if(!(c % p)) {
isPrime = false;
break;
}
}
if(isPrime) {
results.push_back(c);
}
}
return results;
}
template <typename T>
struct EqualsMatcher : Catch::Matchers::MatcherBase<T>
{
EqualsMatcher(T const & target) : target_(target) {}
bool match(T const & actual) const override {
return actual == target_;
}
std::string describe() const override {
return "equals " + Catch::Detail::stringify(target_);
}
private:
T target_;
};
template <typename T>
inline EqualsMatcher<T> equals(T const & target)
{
return EqualsMatcher<T>(target);
}