[604038c] | 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>
|
---|
[9b0877f] | 32 | #include <internal/test/tests.hpp>
|
---|
[604038c] | 33 |
|
---|
| 34 | namespace 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 |
|
---|
[11e2adf] | 87 | arr2.swap(arr3);
|
---|
| 88 | test_eq(
|
---|
| 89 | "swap part 1",
|
---|
| 90 | arr2.begin(), arr2.end(),
|
---|
| 91 | check3.begin(), check3.end()
|
---|
| 92 | );
|
---|
| 93 | test_eq(
|
---|
| 94 | "swap part 2",
|
---|
| 95 | arr3.begin(), arr3.end(),
|
---|
| 96 | check2.begin(), check2.end()
|
---|
| 97 | );
|
---|
| 98 |
|
---|
| 99 | // TODO: test bound checking of at when implemented
|
---|
| 100 |
|
---|
[604038c] | 101 | return true;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | const char* array_test::name()
|
---|
| 105 | {
|
---|
| 106 | return "array";
|
---|
| 107 | }
|
---|
| 108 | }
|
---|