1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <valarray>
10
11// template<class T> class valarray;
12
13// valarray cshift(int i) const;
14
15#include <valarray>
16#include <cassert>
17
18#include "test_macros.h"
19
20int main(int, char**)
21{
22 {
23 typedef int T;
24 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
25 T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
26 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
27 std::valarray<T> v1(a1, N1);
28 std::valarray<T> v2 = v1.cshift(n: 0);
29 assert(v2.size() == N1);
30 for (unsigned i = 0; i < N1; ++i)
31 assert(v2[i] == a2[i]);
32 }
33 {
34 typedef int T;
35 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
36 T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
37 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
38 std::valarray<T> v1(a1, N1);
39 std::valarray<T> v2 = v1.cshift(n: 3);
40 assert(v2.size() == N1);
41 for (unsigned i = 0; i < N1; ++i)
42 assert(v2[i] == a2[i]);
43 }
44 {
45 typedef int T;
46 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
47 T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
48 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
49 std::valarray<T> v1(a1, N1);
50 std::valarray<T> v2 = v1.cshift(n: 10);
51 assert(v2.size() == N1);
52 for (unsigned i = 0; i < N1; ++i)
53 assert(v2[i] == a2[i]);
54 }
55 {
56 typedef int T;
57 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
58 T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
59 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
60 std::valarray<T> v1(a1, N1);
61 std::valarray<T> v2 = v1.cshift(n: 17);
62 assert(v2.size() == N1);
63 for (unsigned i = 0; i < N1; ++i)
64 assert(v2[i] == a2[i]);
65 }
66 {
67 typedef int T;
68 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
69 T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
70 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
71 std::valarray<T> v1(a1, N1);
72 std::valarray<T> v2 = v1.cshift(n: -3);
73 assert(v2.size() == N1);
74 for (unsigned i = 0; i < N1; ++i)
75 assert(v2[i] == a2[i]);
76 }
77 {
78 typedef int T;
79 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
80 T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
81 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
82 std::valarray<T> v1(a1, N1);
83 std::valarray<T> v2 = v1.cshift(n: -10);
84 assert(v2.size() == N1);
85 for (unsigned i = 0; i < N1; ++i)
86 assert(v2[i] == a2[i]);
87 }
88 {
89 typedef int T;
90 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
91 T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
92 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
93 std::valarray<T> v1(a1, N1);
94 std::valarray<T> v2 = v1.cshift(n: -17);
95 assert(v2.size() == N1);
96 for (unsigned i = 0; i < N1; ++i)
97 assert(v2[i] == a2[i]);
98 }
99 {
100 typedef int T;
101 const unsigned N1 = 0;
102 std::valarray<T> v1;
103 std::valarray<T> v2 = v1.cshift(n: -17);
104 assert(v2.size() == N1);
105 }
106 {
107 typedef int T;
108 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
109 T a2[] = {8, 10, 12, 14, 16, 18, 20, 2, 4, 6};
110 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
111 std::valarray<T> v1(a1, N1);
112 std::valarray<T> v2 = (v1 + v1).cshift(3);
113 assert(v2.size() == N1);
114 for (unsigned i = 0; i < N1; ++i)
115 assert(v2[i] == a2[i]);
116 }
117 {
118 typedef int T;
119 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
120 T a2[] = {16, 18, 20, 2, 4, 6, 8, 10, 12, 14};
121 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
122 std::valarray<T> v1(a1, N1);
123 std::valarray<T> v2 = (v1 + v1).cshift(-3);
124 assert(v2.size() == N1);
125 for (unsigned i = 0; i < N1; ++i)
126 assert(v2[i] == a2[i]);
127 }
128
129 return 0;
130}
131

source code of libcxx/test/std/numerics/numarray/template.valarray/valarray.members/cshift.pass.cpp