File: test_xcomplex_sequence.cpp

package info (click to toggle)
xtl 0.7.2-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,352 kB
  • sloc: cpp: 19,501; makefile: 164; python: 25
file content (174 lines) | stat: -rw-r--r-- 4,485 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht          *
* Copyright (c) QuantStack                                                 *
*                                                                          *
* Distributed under the terms of the BSD 3-Clause License.                 *
*                                                                          *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "xtl/xcomplex_sequence.hpp"

#include "gtest/gtest.h"

namespace xtl
{
    using complex_vector = xcomplex_vector<double, false>;

    TEST(xcomplex_sequence, constructor)
    {
        complex_vector v1;
        EXPECT_TRUE(v1.empty());
        EXPECT_EQ(v1.size(), std::size_t(0));

        complex_vector v2(10);
        EXPECT_FALSE(v2.empty());
        EXPECT_EQ(v2.size(), std::size_t(10));

        complex_vector v3(10, xcomplex<double>(1., 1.));
        EXPECT_FALSE(v3.empty());
        EXPECT_EQ(v3.size(), std::size_t(10));
    }

    TEST(xcomplex_sequence, resize)
    {
        complex_vector v1(2);
        v1.resize(4);
        EXPECT_EQ(v1.size(), 4u);

        v1.resize(8, xcomplex<double>(1., 1.));
        EXPECT_EQ(v1.size(), 8u);
    }

    TEST(xcomplex_sequence, access)
    {
        xcomplex<double> c0(1., 2.);
        xcomplex<double> c1(2., 3.);
        
        complex_vector v = { c0, c1 };
        EXPECT_EQ(v[0], c0);
        EXPECT_EQ(v[1], c1);
    }

    TEST(xcomplex_sequence, at)
    {
        xcomplex<double> c0(1., 2.);
        xcomplex<double> c1(2., 3.);

        complex_vector v = { c0, c1 };
        EXPECT_EQ(v.at(0), c0);
        EXPECT_EQ(v.at(1), c1);
    }

    TEST(xcomplex_sequence, front)
    {
        xcomplex<double> c0(1., 2.);
        xcomplex<double> c1(2., 3.);

        complex_vector v = { c0, c1 };
        EXPECT_EQ(v.front(), c0);
    }

    TEST(xcomplex_sequence, back)
    {
        xcomplex<double> c0(1., 2.);
        xcomplex<double> c1(2., 3.);

        complex_vector v = { c0, c1 };
        EXPECT_EQ(v.back(), c1);
    }

    TEST(xcomplex_sequence, iterator)
    {
        xcomplex<double> c0(1., 2.);
        xcomplex<double> c1(2., 3.);
        xcomplex<double> c2(4., 6.);
        xcomplex<double> c3(8., 12.);

        complex_vector v = { c0, c1, c2, c3 };
        auto iter = v.begin();
        auto citer = v.cbegin();

        EXPECT_EQ(*iter, c0);
        EXPECT_EQ(*citer, c0);

        ++iter, ++citer;
        EXPECT_EQ(*iter, c1);
        EXPECT_EQ(*citer, c1);

        ++iter, ++citer;
        EXPECT_EQ(*iter, c2);
        EXPECT_EQ(*citer, c2);

        ++iter, ++citer;
        EXPECT_EQ(*iter, c3);
        EXPECT_EQ(*citer, c3);

        ++iter, ++citer;
        EXPECT_EQ(iter, v.end());
        EXPECT_EQ(citer, v.cend());
    }

    TEST(xcomplex_sequence, reverse_iterator)
    {
        xcomplex<double> c0(1., 2.);
        xcomplex<double> c1(2., 3.);
        xcomplex<double> c2(4., 6.);
        xcomplex<double> c3(8., 12.);

        complex_vector v = { c0, c1, c2, c3 };
        auto iter = v.rbegin();
        auto citer = v.crbegin();

        EXPECT_EQ(*iter, c3);
        EXPECT_EQ(*citer, c3);

        ++iter, ++citer;
        EXPECT_EQ(*iter, c2);
        EXPECT_EQ(*citer, c2);

        ++iter, ++citer;
        EXPECT_EQ(*iter, c1);
        EXPECT_EQ(*citer, c1);

        ++iter, ++citer;
        EXPECT_EQ(*iter, c0);
        EXPECT_EQ(*citer, c0);

        ++iter, ++citer;
        EXPECT_EQ(iter, v.rend());
        EXPECT_EQ(citer, v.crend());
    }

    TEST(xcomplex_sequence, comparison)
    {
        xcomplex<double> c0(1., 2.);
        xcomplex<double> c1(2., 3.);
        xcomplex<double> c2(4., 6.);
        xcomplex<double> c3(8., 12.);
        complex_vector v1 = { c0, c1, c2, c3 };

        EXPECT_TRUE(v1 == v1);
        EXPECT_FALSE(v1 != v1);
    }

    TEST(xcomplex_sequence, real)
    {
        xcomplex<double> c0(1., 2.);
        xcomplex<double> c1(2., 3.);

        complex_vector v = { c0, c1 };
        EXPECT_EQ(v.real()[0], 1.);
        EXPECT_EQ(v.real()[1], 2.);
    }

    TEST(xcomplex_sequence, imag)
    {
        xcomplex<double> c0(1., 2.);
        xcomplex<double> c1(2., 3.);

        complex_vector v = { c0, c1 };
        EXPECT_EQ(v.imag()[0], 2.);
        EXPECT_EQ(v.imag()[1], 3.);
    }
}