1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:57:35 +00:00

AK: Add tests for AllOf and AnyOf

This commit is contained in:
Martin Janiczek 2023-09-26 20:45:57 +02:00 committed by Tim Schumacher
parent 0465ba242b
commit 6c1626e83b
2 changed files with 56 additions and 0 deletions

View file

@ -10,6 +10,34 @@
#include <AK/Array.h>
#include <AK/Vector.h>
using namespace Test::Randomized;
TEST_CASE(vacuous_truth)
{
constexpr Array<int, 0> a {};
static_assert(all_of(a.begin(), a.end(), [](auto) { return false; }));
EXPECT(all_of(a.begin(), a.end(), [](auto) { return false; }));
}
TEST_CASE(all_but_one_false)
{
constexpr Array<int, 5> a { 0, 1, 2, 3, 4 };
static_assert(!all_of(a.begin(), a.end(), [](auto n) { return n != 3; }));
EXPECT(!all_of(a.begin(), a.end(), [](auto n) { return n != 3; }));
}
RANDOMIZED_TEST_CASE(trivial_all_true)
{
GEN(vec, Gen::vector(0, 10, []() { return Gen::unsigned_int(); }));
EXPECT(all_of(vec.begin(), vec.end(), [](auto) { return true; }));
}
RANDOMIZED_TEST_CASE(trivial_all_false)
{
GEN(vec, Gen::vector(1, 10, []() { return Gen::unsigned_int(); }));
EXPECT(!all_of(vec.begin(), vec.end(), [](auto) { return false; }));
}
TEST_CASE(should_determine_if_predicate_applies_to_all_elements_in_container)
{
constexpr Array<int, 10> a {};

View file

@ -10,6 +10,34 @@
#include <AK/Array.h>
#include <AK/Vector.h>
using namespace Test::Randomized;
TEST_CASE(vacuous_truth)
{
constexpr Array<int, 0> a {};
static_assert(!any_of(a.begin(), a.end(), [](auto) { return true; }));
EXPECT(!any_of(a.begin(), a.end(), [](auto) { return true; }));
}
TEST_CASE(all_false)
{
constexpr Array<int, 5> a { 0, 1, 2, 3, 4 };
static_assert(!any_of(a.begin(), a.end(), [](auto n) { return n > 10; }));
EXPECT(!any_of(a.begin(), a.end(), [](auto n) { return n > 10; }));
}
RANDOMIZED_TEST_CASE(trivial_all_true)
{
GEN(vec, Gen::vector(1, 10, []() { return Gen::unsigned_int(); }));
EXPECT(any_of(vec.begin(), vec.end(), [](auto) { return true; }));
}
RANDOMIZED_TEST_CASE(trivial_all_false)
{
GEN(vec, Gen::vector(0, 10, []() { return Gen::unsigned_int(); }));
EXPECT(!any_of(vec.begin(), vec.end(), [](auto) { return false; }));
}
TEST_CASE(should_determine_if_predicate_applies_to_any_element_in_container)
{
constexpr Array<int, 10> a { 1 };