diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-11-10 12:01:44 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-11-10 12:01:44 +0100 |
| commit | 18ca1fc67ccc7bf176287f7b2908a33a597ec67a (patch) | |
| tree | 930e1604156d6b8957d8c01786a18f670a202bc3 /cpp02/ex02 | |
| parent | 9dd7a48967f99793b818f7362ac8e95717186774 (diff) | |
| download | piscine_cpp-18ca1fc67ccc7bf176287f7b2908a33a597ec67a.tar.gz piscine_cpp-18ca1fc67ccc7bf176287f7b2908a33a597ec67a.tar.bz2 piscine_cpp-18ca1fc67ccc7bf176287f7b2908a33a597ec67a.zip | |
Added more tests for cpp02/02
Diffstat (limited to 'cpp02/ex02')
| -rw-r--r-- | cpp02/ex02/Fixed.cpp | 16 | ||||
| -rw-r--r-- | cpp02/ex02/Fixed.hpp | 8 | ||||
| -rw-r--r-- | cpp02/ex02/main.cpp | 30 | ||||
| -rw-r--r-- | cpp02/ex02/main_DO_NOT_TURN_ME_IN.cpp | 106 |
4 files changed, 115 insertions, 45 deletions
diff --git a/cpp02/ex02/Fixed.cpp b/cpp02/ex02/Fixed.cpp index 7769083..085b16f 100644 --- a/cpp02/ex02/Fixed.cpp +++ b/cpp02/ex02/Fixed.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 11:45:18 by charles #+# #+# */ -/* Updated: 2020/10/19 12:41:30 by cacharle ### ########.fr */ +/* Updated: 2020/11/10 12:00:43 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,14 +64,12 @@ Fixed& Fixed::operator--() { m_value++; return *this; } Fixed Fixed::operator++(int) { Fixed copy(*this); m_value++; return copy; } Fixed Fixed::operator--(int) { Fixed copy(*this); m_value--; return copy; } -bool Fixed::operator<(Fixed const& other) const { return m_value < other.m_value; } -bool Fixed::operator>(Fixed const& other) const { return m_value > other.m_value; } -bool Fixed::operator<=(Fixed const& other) const { return !(*this > other); } -bool Fixed::operator>=(Fixed const& other) const { return !(*this < other); } -bool Fixed::operator==(Fixed const& other) const { return m_value == other.m_value; } -bool Fixed::operator!=(Fixed const& other) const { return !(*this == other); } - -int Fixed::getFractionalBits() { return m_fractionalBits; } +bool Fixed::operator<(Fixed const& other) const { return m_value < other.m_value; } +bool Fixed::operator>(Fixed const& other) const { return m_value > other.m_value; } +bool Fixed::operator<=(Fixed const& other) const { return *this < other || *this == other; } +bool Fixed::operator>=(Fixed const& other) const { return *this > other || *this == other; } +bool Fixed::operator==(Fixed const& other) const { return m_value == other.m_value; } +bool Fixed::operator!=(Fixed const& other) const { return !(*this == other); } Fixed& Fixed::max(Fixed& a, Fixed& b) { return a > b ? a : b; } Fixed& Fixed::min(Fixed& a, Fixed& b) { return a < b ? a : b; } diff --git a/cpp02/ex02/Fixed.hpp b/cpp02/ex02/Fixed.hpp index d839260..fe63381 100644 --- a/cpp02/ex02/Fixed.hpp +++ b/cpp02/ex02/Fixed.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 11:40:49 by charles #+# #+# */ -/* Updated: 2020/10/19 12:41:46 by cacharle ### ########.fr */ +/* Updated: 2020/11/10 11:06:40 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,15 +55,11 @@ public: static const Fixed& max(Fixed const& a, Fixed const& b); static const Fixed& min(Fixed const& a, Fixed const& b); - static int getFractionalBits(); - private: - int m_value; + int m_value; static int const m_fractionalBits = 8; }; std::ostream& operator<<(std::ostream& out, Fixed const& f); - - #endif diff --git a/cpp02/ex02/main.cpp b/cpp02/ex02/main.cpp deleted file mode 100644 index 7625260..0000000 --- a/cpp02/ex02/main.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* main.cpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/04/13 11:51:15 by charles #+# #+# */ -/* Updated: 2020/10/19 12:42:08 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include <iostream> -#include "Fixed.hpp" - -int main(void) -{ - Fixed a; - Fixed const b(Fixed(5.05f) * Fixed(2)); - - std::cout << a << std::endl; - std::cout << ++a << std::endl; - std::cout << a << std::endl; - std::cout << a++ << std::endl; - std::cout << a << std::endl; - std::cout << b << std::endl; - std::cout << Fixed::max(a, b) << std::endl; - - return 0; -} diff --git a/cpp02/ex02/main_DO_NOT_TURN_ME_IN.cpp b/cpp02/ex02/main_DO_NOT_TURN_ME_IN.cpp new file mode 100644 index 0000000..c7477e6 --- /dev/null +++ b/cpp02/ex02/main_DO_NOT_TURN_ME_IN.cpp @@ -0,0 +1,106 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main_DO_NOT_TURN_ME_IN.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 11:51:15 by charles #+# #+# */ +/* Updated: 2020/11/10 11:58:30 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <iostream> +#include "Fixed.hpp" + +int main(void) +{ + std::cout << "=== SUBJECT TESTS ===" << std::endl; + Fixed a; + Fixed const b(Fixed(5.05f) * Fixed(2)); + std::cout << a << std::endl; + std::cout << ++a << std::endl; + std::cout << a << std::endl; + std::cout << a++ << std::endl; + std::cout << a << std::endl; + std::cout << b << std::endl; + std::cout << Fixed::max(a, b) << std::endl; + + std::cout << std::endl << "=== SUBJECT 01 TESTS ===" << std::endl; + Fixed e; + Fixed const f(10); + Fixed const c(42.42f); + Fixed const d(b); + e = Fixed(1234.4321f); + std::cout << "e is " << e << std::endl; + std::cout << "f is " << f << std::endl; + std::cout << "c is " << c << std::endl; + std::cout << "d is " << d << std::endl; + std::cout << "e is " << e.toInt() << " as integer" << std::endl; + std::cout << "f is " << f.toInt() << " as integer" << std::endl; + std::cout << "c is " << c.toInt() << " as integer" << std::endl; + std::cout << "d is " << d.toInt() << " as integer" << std::endl; + + std::cout << std::boolalpha; + std::cout << std::endl << "=== OPERATORS TESTS ===" << std::endl; + Fixed x(3.3f); + Fixed y(3.5f); + std::cout << "x is " << x << std::endl; + std::cout << "y is " << y << std::endl; + std::cout << "x + y = " << (x + y) << std::endl; + std::cout << "x - y = " << (x - y) << std::endl; + std::cout << "x * y = " << (x * y) << std::endl; + std::cout << "x / y = " << (x / y) << std::endl; + + std::cout << std::endl << "=== COMPARISON TESTS ===" << std::endl; + Fixed z(x); + std::cout << "x is " << x << std::endl; + std::cout << "y is " << y << std::endl; + std::cout << "z is " << z << std::endl; + std::cout << "x > y = " << (x > y)<< std::endl; + std::cout << "x < y = " << (x < y)<< std::endl; + std::cout << "x >= y = " << (x >= y)<< std::endl; + std::cout << "x <= y = " << (x <= y)<< std::endl; + std::cout << "x == y = " << (x == y)<< std::endl; + std::cout << "x != y = " << (x != y)<< std::endl; + std::cout << std::endl; + std::cout << "x > z = " << (x > z)<< std::endl; + std::cout << "x < z = " << (x < z)<< std::endl; + std::cout << "x >= z = " << (x >= z)<< std::endl; + std::cout << "x <= z = " << (x <= z)<< std::endl; + std::cout << "x == z = " << (x == z)<< std::endl; + std::cout << "x != z = " << (x != z)<< std::endl; + std::cout << std::endl; + std::cout << "y > z = " << (y > z)<< std::endl; + std::cout << "y < z = " << (y < z)<< std::endl; + std::cout << "y >= z = " << (y >= z)<< std::endl; + std::cout << "y <= z = " << (y <= z)<< std::endl; + std::cout << "y == z = " << (y == z)<< std::endl; + std::cout << "y != z = " << (y != z)<< std::endl; + + std::cout << std::endl << "=== MAX/MIN TESTS ===" << std::endl; + std::cout << "x is " << x << std::endl; + std::cout << "y is " << y << std::endl; + std::cout << "z is " << z << std::endl; + std::cout << "Fixed::max(x, y): " << Fixed::max(x, y) << std::endl; + std::cout << "Fixed::max(x, z): " << Fixed::max(x, z) << std::endl; + std::cout << "Fixed::max(y, z): " << Fixed::max(y, z) << std::endl; + std::cout << "Fixed::min(x, y): " << Fixed::min(x, y) << std::endl; + std::cout << "Fixed::min(x, z): " << Fixed::min(x, z) << std::endl; + std::cout << "Fixed::min(y, z): " << Fixed::min(y, z) << std::endl; + + const Fixed cx(x); + const Fixed cy(y); + const Fixed cz(z); + std::cout << "cx is " << cx << std::endl; + std::cout << "cy is " << cy << std::endl; + std::cout << "cz is " << cz << std::endl; + std::cout << "Fixed::max(cx, cy): " << Fixed::max(cx, cy) << std::endl; + std::cout << "Fixed::max(cx, cz): " << Fixed::max(cx, cz) << std::endl; + std::cout << "Fixed::max(cy, cz): " << Fixed::max(cy, cz) << std::endl; + std::cout << "Fixed::min(cx, cy): " << Fixed::min(cx, cy) << std::endl; + std::cout << "Fixed::min(cx, cz): " << Fixed::min(cx, cz) << std::endl; + std::cout << "Fixed::min(cy, cz): " << Fixed::min(cy, cz) << std::endl; + + return 0; +} |
