2020-09-06 15:13:34 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 04:24:48 -04:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-06 15:13:34 -04:00
|
|
|
*/
|
|
|
|
|
2021-04-25 01:53:23 -04:00
|
|
|
#include <LibTest/TestCase.h>
|
2020-09-06 15:13:34 -04:00
|
|
|
|
|
|
|
#include <AK/Array.h>
|
|
|
|
|
2022-04-01 13:58:27 -04:00
|
|
|
static constexpr int constexpr_sum(Span<int const> const span)
|
2020-09-06 15:13:34 -04:00
|
|
|
{
|
|
|
|
int sum = 0;
|
2020-10-20 20:26:19 -04:00
|
|
|
for (auto value : span)
|
2020-09-06 15:13:34 -04:00
|
|
|
sum += value;
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2022-01-07 07:04:05 -05:00
|
|
|
TEST_CASE(compile_time_constructible)
|
2020-09-06 15:13:34 -04:00
|
|
|
{
|
|
|
|
constexpr Array<int, 4> array = { 0, 1, 2, 3 };
|
|
|
|
static_assert(array.size() == 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(compile_time_iterable)
|
|
|
|
{
|
|
|
|
constexpr Array<int, 8> array = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
|
|
|
static_assert(constexpr_sum(array) == 28);
|
|
|
|
}
|