|
2 | 2 | #include <cstdlib>
|
3 | 3 | #include <iostream>
|
4 | 4 |
|
5 |
| -#include <iostream> |
6 |
| -int main(void) { |
7 |
| - Fixed a; |
8 |
| - Fixed const b(Fixed(5.05f) * Fixed(2)); |
| 5 | +void testOperators(void) { |
| 6 | + if (Fixed(2) > Fixed(1)) |
| 7 | + std::cout << "test greater" << std::endl; |
| 8 | + if (Fixed(1) < Fixed(2)) |
| 9 | + std::cout << "test lesser" << std::endl; |
| 10 | + if (Fixed(2) >= Fixed(1)) |
| 11 | + std::cout << "test greater equal" << std::endl; |
| 12 | + if (Fixed(1) <= Fixed(1)) |
| 13 | + std::cout << "test lesser equal" << std::endl; |
| 14 | + if (Fixed(2) == Fixed(2)) |
| 15 | + std::cout << "test equal" << std::endl; |
| 16 | + if (Fixed(2) != Fixed(1)) |
| 17 | + std::cout << "test different" << std::endl; |
| 18 | +} |
| 19 | + |
| 20 | +void testIncrement(Fixed &a, Fixed const &b) { |
9 | 21 | std::cout << a << std::endl;
|
10 | 22 | std::cout << ++a << std::endl;
|
11 | 23 | std::cout << a << std::endl;
|
12 | 24 | std::cout << a++ << std::endl;
|
13 | 25 | std::cout << a << std::endl;
|
14 | 26 | std::cout << b << std::endl;
|
15 | 27 | std::cout << Fixed::max(a, b) << std::endl;
|
| 28 | +} |
| 29 | + |
| 30 | +void testArithmeticOperators(void) { |
| 31 | + |
| 32 | + std::cout << "Sum 2 + 3 = " << (Fixed(2) + Fixed(3)) << std::endl; |
| 33 | + std::cout << "Sub 2 - 3 = " << (Fixed(2) - Fixed(3)) << std::endl; |
| 34 | + std::cout << "Div 2 / 3 = " << (Fixed(2) / Fixed(3)) << std::endl; |
| 35 | + std::cout << "Mult 2 * 3 = " << (Fixed(2) * Fixed(3)) << std::endl; |
| 36 | +} |
| 37 | + |
| 38 | +int main(void) { |
| 39 | + Fixed a; |
| 40 | + Fixed const b(Fixed(5.05f) * Fixed(2)); |
| 41 | + testOperators(); |
| 42 | + testArithmeticOperators(); |
| 43 | + testIncrement(a, b); |
| 44 | + |
16 | 45 | return EXIT_SUCCESS;
|
17 | 46 | }
|
0 commit comments