view tests/libmlk/rectangle/main.cpp @ 215:268b66d72ec0 default tip @

misc: remove Javascript bindings, closes #2402
author David Demelier <markand@malikania.fr>
date Thu, 10 Oct 2019 13:52:57 +0200
parents 209bdaa13a49
children
line wrap: on
line source

/*
 * main.cpp -- test mlk::client::rectangle
 *
 * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#define BOOST_TEST_MODULE "Rectangle"
#include <boost/test/unit_test.hpp>

#include <malikania/rectangle.hpp>

namespace mlk {

auto operator<<(std::ostream& out, const rectangle& rectangle) -> std::ostream&
{
	out << "{";
	out << rectangle.width << ", " << rectangle.height << ", ";
	out << rectangle.x << ", " << rectangle.y;
	out << "}";

	return out;
}

namespace {

BOOST_AUTO_TEST_CASE(none)
{
	rectangle rectangle;

	BOOST_TEST(rectangle.x == 0);
	BOOST_TEST(rectangle.y == 0);
	BOOST_TEST(rectangle.width == 0U);
	BOOST_TEST(rectangle.height == 0U);
}

BOOST_AUTO_TEST_CASE(null)
{
	BOOST_TEST(rectangle().is_null());
	BOOST_TEST((!rectangle{0, 0, 10, 0}.is_null()));
	BOOST_TEST((!rectangle{0, 0, 0, 10}.is_null()));
	BOOST_TEST((!rectangle{0, 0, 10, 10}.is_null()));
}

BOOST_AUTO_TEST_CASE(standard)
{
	rectangle rectangle{10, 20, 30, 40};

	BOOST_TEST(rectangle.x == 10);
	BOOST_TEST(rectangle.y == 20);
	BOOST_TEST(rectangle.width == 30U);
	BOOST_TEST(rectangle.height == 40U);
}

BOOST_AUTO_TEST_CASE(operator_eq)
{
	rectangle rectangle1, rectangle2;

	BOOST_TEST(rectangle1 == rectangle2);
}

BOOST_AUTO_TEST_CASE(operator_eq1)
{
	rectangle rectangle1{10, 20, 30, 40};
	rectangle rectangle2{10, 20, 30, 40};

	BOOST_TEST(rectangle1 == rectangle2);
}

BOOST_AUTO_TEST_CASE(operator_neq)
{
	BOOST_TEST((rectangle{10} != rectangle{20}));
	BOOST_TEST((rectangle{10, 10} != rectangle{10, 20}));
	BOOST_TEST((rectangle{10, 10, 10} != rectangle{10, 10, 20}));
	BOOST_TEST((rectangle{10, 10, 10, 10} != rectangle{10, 10, 10, 20}));
}

} // !namespace

} // !mlk::client