source: mainline/uspace/lib/cpp/src/__bits/test/array.cpp@ c6f23a7

Last change on this file since c6f23a7 was b57ba05, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update headers in C++ files

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <__bits/test/tests.hpp>
8#include <algorithm>
9#include <array>
10#include <initializer_list>
11
12namespace std::test
13{
14 bool array_test::run(bool report)
15 {
16 report_ = report;
17 start();
18
19 auto check1 = {1, 2, 3, 4};
20 auto check2 = {4, 3, 2, 1};
21 auto check3 = {5, 5, 5, 5};
22
23 std::array<int, 4> arr1{1, 2, 3, 4};
24 test_eq(
25 "initializer list construction",
26 arr1.begin(), arr1.end(),
27 check1.begin(), check1.end()
28 );
29
30 auto it = arr1.begin();
31 test_eq(
32 "iterator increment",
33 *(++it), arr1[1]
34 );
35 test_eq(
36 "iterator decrement",
37 *(--it), arr1[0]
38 );
39
40 std::array<int, 4> arr2{arr1};
41 test_eq(
42 "copy construction",
43 arr1.begin(), arr1.end(),
44 arr2.begin(), arr2.end()
45 );
46
47 std::reverse(arr2.begin(), arr2.end());
48 test_eq(
49 "reverse",
50 arr2.begin(), arr2.end(),
51 check2.begin(), check2.end()
52 );
53 test_eq(
54 "reverse iterator",
55 arr1.rbegin(), arr1.rend(),
56 arr2.begin(), arr2.end()
57 );
58
59
60 std::array<int, 4> arr3{};
61 arr3.fill(5);
62 test_eq(
63 "fill",
64 arr3.begin(), arr3.end(),
65 check3.begin(), check3.end()
66 );
67
68 arr2.swap(arr3);
69 test_eq(
70 "swap part 1",
71 arr2.begin(), arr2.end(),
72 check3.begin(), check3.end()
73 );
74 test_eq(
75 "swap part 2",
76 arr3.begin(), arr3.end(),
77 check2.begin(), check2.end()
78 );
79
80 // TODO: test bound checking of at when implemented
81
82 std::array<int, 3> arr4{1, 2, 3};
83 auto [a, b, c] = arr4;
84 test_eq("structured binding part 1", a, 1);
85 test_eq("structured binding part 2", b, 2);
86 test_eq("structured binding part 3", c, 3);
87
88 return end();
89 }
90
91 const char* array_test::name()
92 {
93 return "array";
94 }
95}
Note: See TracBrowser for help on using the repository browser.