Changeset 25709c3 in mainline
- Timestamp:
- 2018-07-05T21:41:24Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 937de98
- Parents:
- 15f407a
- git-author:
- Dzejrou <dzejrou@…> (2018-05-15 15:44:05)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:24)
- Location:
- uspace/lib/cpp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/internal/test/tests.hpp
r15f407a r25709c3 229 229 private: 230 230 void test_algorithms(); 231 void test_complex(); 231 232 }; 232 233 } -
uspace/lib/cpp/src/internal/test/numeric.cpp
r15f407a r25709c3 27 27 */ 28 28 29 #include <iostream> // TODO: remove 30 29 31 #include <array> 32 #include <complex> 30 33 #include <initializer_list> 31 34 #include <internal/test/tests.hpp> 32 35 #include <numeric> 33 36 #include <utility> 37 38 using namespace std::literals; 39 using namespace complex_literals; 34 40 35 41 namespace std::test … … 41 47 42 48 test_algorithms(); 49 test_complex(); 43 50 44 51 return end(); … … 147 154 ); 148 155 } 156 157 void numeric_test::test_complex() 158 { 159 auto c1 = 1.f + 2.5if; 160 test_eq("complex literals pt1", c1.real(), 1.f); 161 test_eq("complex literals pt2", c1.imag(), 2.5f); 162 163 std::complex<double> c2{2.0, 0.5}; 164 test_eq("complex value initialization", c2, (2.0 + 0.5i)); 165 166 std::complex<double> c3{c2}; 167 test_eq("complex copy initialization", c3, (2.0 + 0.5i)); 168 169 std::complex<double> c4{c1}; 170 test_eq("complex conversion initialization", c4, (1.0 + 2.5i)); 171 172 test_eq("complex sum", ((1.0 + 2.5i) + (3.0 + 0.5i)), (4.0 + 3.0i)); 173 test_eq("complex sub", ((2.0 + 3.0i) - (1.0 + 5.0i)), (1.0 - 2.0i)); 174 test_eq("complex mul", ((2.0 + 2.0i) * (2.0 + 3.0i)), (-2.0 + 10.0i)); 175 test_eq("complex div", ((2.0 - 1.0i) / (3.0 + 4.0i)), (0.08 - 0.44i)); 176 test_eq("complex unary minus", -(1.0 + 1.0i), (-1.0 - 1.0i)); 177 test_eq("complex abs", std::abs(2.0 - 4.0i), 20.0); 178 test_eq("complex real", std::real(2.0 + 3.0i), 2.0); 179 test_eq("complex imag", std::imag(2.0 + 3.0i), 3.0); 180 } 149 181 } 150 182
Note:
See TracChangeset
for help on using the changeset viewer.