MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/stl/range_access.cpp:6–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "fl/stl/static_assert.h"
5
6FL_TEST_FILE(FL_FILEPATH) {
7
8using namespace fl;
9
10FL_TEST_CASE("fl::begin and fl::end for C arrays") {
11 FL_SUBCASE("int array") {
12 int arr[5] = {1, 2, 3, 4, 5};
13
14 int* b = fl::begin(arr);
15 int* e = fl::end(arr);
16
17 FL_CHECK_EQ(b, arr);
18 FL_CHECK_EQ(e, arr + 5);
19 FL_CHECK_EQ(e - b, 5);
20 FL_CHECK_EQ(*b, 1);
21 FL_CHECK_EQ(*(e - 1), 5);
22 }
23
24 FL_SUBCASE("const int array") {
25 const int arr[3] = {10, 20, 30};
26
27 const int* b = fl::begin(arr);
28 const int* e = fl::end(arr);
29
30 FL_CHECK_EQ(b, arr);
31 FL_CHECK_EQ(e, arr + 3);
32 FL_CHECK_EQ(e - b, 3);
33 }
34
35 FL_SUBCASE("double array") {
36 double arr[4] = {1.1, 2.2, 3.3, 4.4};
37
38 double* b = fl::begin(arr);
39 double* e = fl::end(arr);
40
41 FL_CHECK_EQ(e - b, 4);
42 FL_CHECK(doctest::Approx(*b).epsilon(0.001) == 1.1);
43 }
44
45 FL_SUBCASE("single element array") {
46 int arr[1] = {42};
47
48 int* b = fl::begin(arr);
49 int* e = fl::end(arr);
50
51 FL_CHECK_EQ(e - b, 1);
52 FL_CHECK_EQ(*b, 42);
53 }
54
55 FL_SUBCASE("iterate with begin/end") {
56 int arr[5] = {1, 2, 3, 4, 5};
57 int sum = 0;
58
59 for (auto it = fl::begin(arr); it != fl::end(arr); ++it) {
60 sum += *it;
61 }
62
63 FL_CHECK_EQ(sum, 15);

Callers

nothing calls this directly

Calls 5

beginFunction · 0.50
endFunction · 0.50
ApproxFunction · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected