source: mainline/uspace/lib/cpp/src/internal/test/array.cpp@ 604038c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 604038c was 604038c, checked in by Dzejrou <dzejrou@…>, 7 years ago

cpp: added basic array tests

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2017 Jaroslav Jindrak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <algorithm>
30#include <array>
31#include <initializer_list>
32#include <internal/test/array.hpp>
33
34namespace std::test
35{
36 bool array_test::run()
37 {
38 auto check1 = {1, 2, 3, 4};
39 auto check2 = {4, 3, 2, 1};
40 auto check3 = {5, 5, 5, 5};
41
42 std::array<int, 4> arr1{1, 2, 3, 4};
43 test_eq(
44 "initializer list construction",
45 arr1.begin(), arr1.end(),
46 check1.begin(), check1.end()
47 );
48
49 auto it = arr1.begin();
50 test_eq(
51 "iterator increment",
52 *(++it), arr1[1]
53 );
54 test_eq(
55 "iterator decrement",
56 *(--it), arr1[0]
57 );
58
59 std::array<int, 4> arr2{arr1};
60 test_eq(
61 "copy construction",
62 arr1.begin(), arr1.end(),
63 arr2.begin(), arr2.end()
64 );
65
66 std::reverse(arr2.begin(), arr2.end());
67 test_eq(
68 "reverse",
69 arr2.begin(), arr2.end(),
70 check2.begin(), check2.end()
71 );
72 test_eq(
73 "reverse iterator",
74 arr1.rbegin(), arr1.rend(),
75 arr2.begin(), arr2.end()
76 );
77
78
79 std::array<int, 4> arr3{};
80 arr3.fill(5);
81 test_eq(
82 "fill",
83 arr3.begin(), arr3.end(),
84 check3.begin(), check3.end()
85 );
86
87 return true;
88 }
89
90 const char* array_test::name()
91 {
92 return "array";
93 }
94}
Note: See TracBrowser for help on using the repository browser.