LEFT | RIGHT |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 2020 Daniel Eble <dan@faithful.be> | 4 Copyright (C) 2020 Daniel Eble <dan@faithful.be> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 147 } |
148 | 148 |
149 TEST (Rational_test, init_float_zero) | 149 TEST (Rational_test, init_float_zero) |
150 { | 150 { |
151 const Rational r (0.0); | 151 const Rational r (0.0); |
152 EQUAL (0, r.sign ()); | 152 EQUAL (0, r.sign ()); |
153 EQUAL (0, r.num ()); | 153 EQUAL (0, r.num ()); |
154 EQUAL (1, r.den ()); | 154 EQUAL (1, r.den ()); |
155 } | 155 } |
156 | 156 |
157 #if 0 // TODO: debug initialization by infinities | |
158 TEST (Rational_test, init_float_pos_inf) | 157 TEST (Rational_test, init_float_pos_inf) |
159 { | 158 { |
160 const Rational r (INFINITY); | 159 const Rational r (INFINITY); |
161 EQUAL (1, r.sign ()); | 160 EQUAL (1, r.sign ()); |
162 CHECK (r.is_infinity ()); | 161 CHECK (r.is_infinity ()); |
163 CHECK (std::isinf (static_cast<double> (r))); | 162 |
| 163 const auto d = static_cast<double> (r); |
| 164 CHECK (std::isinf (d)); |
| 165 CHECK (!std::signbit (d)); |
164 } | 166 } |
165 | 167 |
166 TEST (Rational_test, init_float_neg_inf) | 168 TEST (Rational_test, init_float_neg_inf) |
167 { | 169 { |
168 const Rational r (-INFINITY); | 170 const Rational r (-INFINITY); |
169 EQUAL (-1, r.sign ()); | 171 EQUAL (-1, r.sign ()); |
170 CHECK (r.is_infinity ()); | 172 CHECK (r.is_infinity ()); |
171 CHECK (std::isinf (static_cast<double> (r))); | 173 |
172 } | 174 const auto d = static_cast<double> (r); |
173 #endif | 175 CHECK (std::isinf (d)); |
| 176 CHECK (std::signbit (d)); |
| 177 } |
174 | 178 |
175 TEST (Rational_test, trunc_int) | 179 TEST (Rational_test, trunc_int) |
176 { | 180 { |
177 for (int i = -6; i <= 6; ++i) | 181 for (int i = -6; i <= 6; ++i) |
178 { | 182 { |
179 EQUAL (i / 2, Rational (i, 2).trunc_int ()); | 183 EQUAL (i / 2, Rational (i, 2).trunc_int ()); |
180 EQUAL (i / 3, Rational (i, 3).trunc_int ()); | 184 EQUAL (i / 3, Rational (i, 3).trunc_int ()); |
181 } | 185 } |
182 | 186 |
183 // truncate a very low value | 187 // truncate a very low value |
184 { | 188 { |
185 // TODO: Program takes a lot of time without the +1. Investigate. | 189 // TODO: Program takes a lot of time without the +1. Investigate. |
186 const auto L = std::numeric_limits<int64_t>::lowest () + 1; | 190 const auto L = std::numeric_limits<int64_t>::lowest () + 1; |
187 for (int i = 1; i <= 3; ++i) | 191 for (int i = 1; i <= 3; ++i) |
188 { | 192 { |
189 EQUAL (L / i, Rational (L, i).trunc_int ()); | 193 EQUAL (L / i, Rational (L, i).trunc_int ()); |
190 } | 194 } |
191 } | 195 } |
192 | 196 |
193 // truncate a very high value | 197 // truncate a very high value |
194 { | 198 { |
195 const auto H = std::numeric_limits<int64_t>::max (); | 199 const auto H = std::numeric_limits<int64_t>::max (); |
196 for (int i = 1; i <= 3; ++i) | 200 for (int i = 1; i <= 3; ++i) |
197 { | 201 { |
198 EQUAL (H / i, Rational (H, i).trunc_int ()); | 202 EQUAL (H / i, Rational (H, i).trunc_int ()); |
199 } | 203 } |
200 } | 204 } |
201 } | 205 } |
LEFT | RIGHT |