1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <valarray>
11
12 // template<class T> class valarray;
13
14 // valarray cshift(int i) const;
15
16 #include <valarray>
17 #include <cassert>
18
main()19 int main()
20 {
21 {
22 typedef int T;
23 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
24 T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
25 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
26 std::valarray<T> v1(a1, N1);
27 std::valarray<T> v2 = v1.cshift(0);
28 assert(v2.size() == N1);
29 for (unsigned i = 0; i < N1; ++i)
30 assert(v2[i] == a2[i]);
31 }
32 {
33 typedef int T;
34 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
35 T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
36 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
37 std::valarray<T> v1(a1, N1);
38 std::valarray<T> v2 = v1.cshift(3);
39 assert(v2.size() == N1);
40 for (unsigned i = 0; i < N1; ++i)
41 assert(v2[i] == a2[i]);
42 }
43 {
44 typedef int T;
45 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
46 T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
47 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
48 std::valarray<T> v1(a1, N1);
49 std::valarray<T> v2 = v1.cshift(10);
50 assert(v2.size() == N1);
51 for (unsigned i = 0; i < N1; ++i)
52 assert(v2[i] == a2[i]);
53 }
54 {
55 typedef int T;
56 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
57 T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
58 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
59 std::valarray<T> v1(a1, N1);
60 std::valarray<T> v2 = v1.cshift(17);
61 assert(v2.size() == N1);
62 for (unsigned i = 0; i < N1; ++i)
63 assert(v2[i] == a2[i]);
64 }
65 {
66 typedef int T;
67 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
68 T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
69 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
70 std::valarray<T> v1(a1, N1);
71 std::valarray<T> v2 = v1.cshift(-3);
72 assert(v2.size() == N1);
73 for (unsigned i = 0; i < N1; ++i)
74 assert(v2[i] == a2[i]);
75 }
76 {
77 typedef int T;
78 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
79 T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
80 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
81 std::valarray<T> v1(a1, N1);
82 std::valarray<T> v2 = v1.cshift(-10);
83 assert(v2.size() == N1);
84 for (unsigned i = 0; i < N1; ++i)
85 assert(v2[i] == a2[i]);
86 }
87 {
88 typedef int T;
89 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
90 T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
91 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
92 std::valarray<T> v1(a1, N1);
93 std::valarray<T> v2 = v1.cshift(-17);
94 assert(v2.size() == N1);
95 for (unsigned i = 0; i < N1; ++i)
96 assert(v2[i] == a2[i]);
97 }
98 {
99 typedef int T;
100 const unsigned N1 = 0;
101 std::valarray<T> v1;
102 std::valarray<T> v2 = v1.cshift(-17);
103 assert(v2.size() == N1);
104 }
105 {
106 typedef int T;
107 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
108 T a2[] = {8, 10, 12, 14, 16, 18, 20, 2, 4, 6};
109 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
110 std::valarray<T> v1(a1, N1);
111 std::valarray<T> v2 = (v1 + v1).cshift(3);
112 assert(v2.size() == N1);
113 for (unsigned i = 0; i < N1; ++i)
114 assert(v2[i] == a2[i]);
115 }
116 {
117 typedef int T;
118 T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
119 T a2[] = {16, 18, 20, 2, 4, 6, 8, 10, 12, 14};
120 const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
121 std::valarray<T> v1(a1, N1);
122 std::valarray<T> v2 = (v1 + v1).cshift(-3);
123 assert(v2.size() == N1);
124 for (unsigned i = 0; i < N1; ++i)
125 assert(v2[i] == a2[i]);
126 }
127 }
128