You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.8 KiB

/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include "RectangleTest.h"
#include <sstream>
#include "Rectangle.h"
CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::RectangleTest)
namespace Magnum { namespace Math { namespace Geometry { namespace Test {
typedef Geometry::Rectangle<float> Rectangle;
typedef Geometry::Rectangle<std::int32_t> Rectanglei;
typedef Vector2<std::int32_t> Vector2i;
RectangleTest::RectangleTest() {
addTests(&RectangleTest::access,
&RectangleTest::compare,
&RectangleTest::construct,
&RectangleTest::size,
&RectangleTest::debug);
}
void RectangleTest::access() {
Rectanglei rect({34, 23}, {47, 30});
const Rectanglei crect({34, 23}, {47, 30});
CORRADE_COMPARE(rect.bottomLeft(), Vector2i(34, 23));
CORRADE_COMPARE(rect.topRight(), Vector2i(47, 30));
CORRADE_COMPARE(rect.bottom(), 23);
CORRADE_COMPARE(rect.top(), 30);
CORRADE_COMPARE(rect.left(), 34);
CORRADE_COMPARE(rect.right(), 47);
CORRADE_COMPARE(crect.bottomLeft(), Vector2i(34, 23));
CORRADE_COMPARE(crect.topRight(), Vector2i(47, 30));
CORRADE_COMPARE(crect.bottom(), 23);
CORRADE_COMPARE(crect.top(), 30);
CORRADE_COMPARE(crect.left(), 34);
CORRADE_COMPARE(crect.right(), 47);
}
void RectangleTest::compare() {
CORRADE_VERIFY(Rectanglei({34, 23}, {47, 30}) == Rectanglei({34, 23}, {47, 30}));
CORRADE_VERIFY(Rectanglei({34, 23}, {47, 30}) != Rectanglei({34, 23}, {48, 30}));
CORRADE_VERIFY(Rectanglei({34, 23}, {47, 30}) != Rectanglei({35, 23}, {47, 30}));
}
void RectangleTest::construct() {
CORRADE_COMPARE(Rectanglei(), Rectanglei({0, 0}, {0, 0}));
CORRADE_COMPARE(Rectanglei::fromSize({3, 5}, {23, 78}), Rectanglei({3, 5}, {26, 83}));
CORRADE_COMPARE(Rectanglei::from(Rectangle({1.3f, 2.7f}, {-15.0f, 7.0f})),
Rectanglei({1, 2}, {-15, 7}));
}
void RectangleTest::size() {
Rectanglei rect({34, 23}, {47, 30});
CORRADE_COMPARE(rect.size(), Vector2i(13, 7));
CORRADE_COMPARE(rect.width(), 13);
CORRADE_COMPARE(rect.height(), 7);
}
void RectangleTest::debug() {
std::ostringstream o;
Corrade::Utility::Debug(&o) << Rectanglei({34, 23}, {47, 30});
CORRADE_COMPARE(o.str(), "Rectangle({34, 23}, {47, 30})\n");
}
}}}}