1 // -*- C++ -*-
2 /**
3 * @brief The test file of class Tensor for standard methods
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 /** TEST NUMBER ZERO : DEFAULT CONSTRUCTOR AND STRING CONVERTER */
35 fullprint << "test number zero : default constructor and string converter" << std::endl;
36
37 /* Default constructor */
38 Tensor tensor0;
39
40 /* String converter */
41 fullprint << "tensor0 = " << tensor0 << std::endl;
42
43
44 /** TEST NUMBER ONE : CONSTRUCTOR WITH SIZE, OPERATOR() AND STRING CONVERTER */
45 fullprint << "test number one : constructor with size, operator() and string converter" << std::endl;
46
47 /* Constructor with size */
48 Tensor tensor1(2, 2, 3);
49 tensor1.setName("tensor1");
50
51 /* Check operator() methods */
52 tensor1(0, 0, 0) = 1. ;
53 tensor1(1, 0, 0) = 2. ;
54 tensor1(0, 1, 0) = 3. ;
55 tensor1(1, 1, 0) = 4. ;
56 tensor1(0, 0, 1) = 5. ;
57 tensor1(1, 0, 1) = 6. ;
58 tensor1(0, 1, 1) = 7. ;
59 tensor1(1, 1, 1) = 8. ;
60 tensor1(0, 0, 2) = 9. ;
61 tensor1(1, 0, 2) = 10. ;
62 tensor1(0, 1, 2) = 11. ;
63 tensor1(1, 1, 2) = 12. ;
64
65 /* String converter */
66 fullprint << "tensor1 = " << tensor1 << std::endl;
67 fullprint << "values = " << tensor1(0, 0, 0) << " ; "
68 << tensor1(1, 0, 0) << " ; "
69 << tensor1(0, 1, 0) << " ; "
70 << tensor1(1, 1, 0) << " ; "
71 << tensor1(0, 0, 1) << " ; "
72 << tensor1(1, 0, 1) << " ; "
73 << tensor1(0, 1, 1) << " ; "
74 << tensor1(1, 1, 1) << " ; "
75 << tensor1(0, 0, 2) << " ; "
76 << tensor1(1, 0, 2) << " ; "
77 << tensor1(0, 1, 2) << " ; "
78 << tensor1(1, 1, 2) << std::endl;
79
80
81 /** TEST NUMBER TWO : COPY CONSTRUCTOR AND STRING CONVERTER */
82 fullprint << "test number two : copy constructor and string converter" << std::endl;
83
84 /* Copy constructor */
85 Tensor tensor2(tensor1);
86
87 /* String converter */
88 fullprint << "tensor2 = " << tensor2 << std::endl;
89
90
91 /** TEST NUMBER THREE : GET DIMENSIONS METHODS */
92 fullprint << "test number three : get dimensions methods" << std::endl;
93
94 /* Get dimension methods */
95 fullprint << "tensor1's nbRows = " << tensor1.getNbRows() << std::endl
96 << "tensor1's nbColumns = " << tensor1.getNbColumns() << std::endl
97 << "tensor1's nbSheets = " << tensor1.getNbSheets() << std::endl;
98
99
100
101 /** TEST NUMBER FOUR : ASSIGNMENT METHOD */
102 fullprint << "test number four : assignment method" << std::endl;
103
104 /* Assignment method */
105 Tensor tensor3 ;
106 tensor3 = tensor1 ;
107 fullprint << "tensor3 = " << tensor3 << std::endl;
108
109
110 /** TEST NUMBER FIVE : ISEMPTY METHOD */
111 fullprint << "test number five : isEmpty method" << std::endl;
112
113 /* Check method isEmpty */
114 Tensor tensor5;
115 Tensor tensor6;
116 fullprint << "tensor1 is empty = " << tensor1.isEmpty() << std::endl
117 << "tensor0 is empty = " << tensor0.isEmpty() << std::endl
118 << "tensor5 is empty = " << tensor5.isEmpty() << std::endl
119 << "tensor6 is empty = " << tensor6.isEmpty() << std::endl;
120
121 /** TEST NUMBER SIX : GETSHEET AND SETSHEET METHODS */
122 fullprint << "tensor1 = " << tensor1 << std::endl;
123 // Matrix sheet1(tensor1.getSheet(1));
124 fullprint << "tensor1.getSheet(1) = " << tensor1.getSheet(1) << std::endl;
125 Matrix sheet2(2, 2);
126 sheet2(0, 0) = 0.5;
127 sheet2(1, 0) = 0.6;
128 sheet2(0, 1) = 0.7;
129 sheet2(1, 1) = 0.8;
130 fullprint << "sheet2 = " << sheet2 << std::endl;
131 tensor1.setSheet(1, sheet2);
132 fullprint << "tensor1 = " << tensor1 << std::endl;
133
134 }
135 catch (TestFailed & ex)
136 {
137 std::cerr << ex << std::endl;
138 return ExitCode::Error;
139 }
140
141
142 return ExitCode::Success;
143 }
144