1 // -*- C++ -*-
2 /**
3 * @brief The test file of class Sample of big size
4 *
5 * Copyright 2005-2021 Airbus-EDF-IMACS-ONERA-Phimeca
6 *
7 * This library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21 #include "openturns/OT.hxx"
22 #include "openturns/OTtestcode.hxx"
23
24 using namespace OT;
25 using namespace OT::Test;
26
main(int,char * [])27 int main(int, char *[])
28 {
29 TESTPREAMBLE;
30 OStream fullprint(std::cout);
31
32 try
33 {
34
35 #ifdef DEBUG_MEMORY
36 std::cerr << "Memory usage std=" << GetMemoryUsage() << " full=" << GetFullMemoryUsage() << std::endl;
37 #endif
38
39 {
40 // We create an empty Sample
41 Sample sample(0, 2);
42 sample.setName("EmptySample");
43 fullprint << "sample=" << sample << std::endl;
44
45 try
46 {
47 // We access the element of the sample
48 Point p(sample.at(0));
49 fullprint << "p=" << p << std::endl;
50
51 // We should NEVER go here
52 throw TestFailed("Exception NOT thrown");
53 }
54 catch (OutOfBoundException &)
55 {
56 // Nothing to do
57 }
58 }
59
60 #ifdef DEBUG_MEMORY
61 std::cerr << "Memory usage std=" << GetMemoryUsage() << " full=" << GetFullMemoryUsage() << std::endl;
62 #endif
63
64 {
65 // We create an small Sample
66 Sample sample(1, 2);
67 sample.setName("SmallSample");
68 fullprint << "sample=" << sample << std::endl;
69
70 // We access the element of the sample
71 Point p(sample[0]);
72 fullprint << "p=" << p << std::endl;
73 try
74 {
75 // We try to access past the last element of the point
76 Point err( sample.at(2) );
77
78 // We should NEVER go here
79 throw TestFailed("Exception NOT thrown");
80 }
81 catch (OutOfBoundException &)
82 {
83 // Nothing to do
84 }
85 }
86
87 #ifdef DEBUG_MEMORY
88 std::cerr << "Memory usage std=" << GetMemoryUsage() << " full=" << GetFullMemoryUsage() << std::endl;
89 #endif
90
91 {
92 // We create a big Sample
93 Sample sample(1000000, 2);
94 sample.setName("BigSample");
95
96 #ifdef DEBUG_MEMORY
97 std::cerr << "Memory usage std=" << GetMemoryUsage() << " full=" << GetFullMemoryUsage() << std::endl;
98 printMemoryUsage();
99 #endif
100
101 // We populate the sample
102 UnsignedInteger size = sample.getSize();
103 for(UnsignedInteger i = 0; i < size; i++)
104 {
105 sample(i, 0) = i;
106 sample(i, 1) = i;
107 }
108
109 Point mean = sample.computeMean();
110
111 fullprint << "sample first point=" << sample[0] << std::endl;
112 fullprint << "sample last point=" << sample[size - 1] << std::endl;
113 fullprint << "sample mean value=" << mean << std::endl;
114
115 #ifdef DEBUG_MEMORY
116 std::cerr << "Memory usage std=" << GetMemoryUsage() << " full=" << GetFullMemoryUsage() << std::endl;
117 #endif
118 }
119
120 }
121 catch (TestFailed & ex)
122 {
123 std::cerr << ex << std::endl;
124 return ExitCode::Error;
125 }
126
127
128 return ExitCode::Success;
129 }
130
131