mirror of
https://github.com/boostorg/gil.git
synced 2026-02-19 14:32:10 +00:00
Motivation: - state clearly what is covered with tests without reading non-trivial code - avoid cleverness - tests should be no-brainer - get closer to one test case targets one feature/beaviour with one check - replace obscure `throw std::exception` with diagnostics that are actually useful to pin-point failure cause and location - makes CI logs useful. - allow to select and run specific tests - make tests maintenance easy, quick and fun Propose new structure of tests that reflects the previous tests hierarchy, but organizes channel tests in test/channel directory with test programs each covering specific library feature (or set of closely related features). The refactored tests cover 100% of checks from the old `channel.cpp`, plus it refines or adds a bunch more. NOTE: old test/channel.cpp has not been removed yet. Common definitions from the single test/channel.cpp moved to channel_test_fixtures.hpp and namespace boost::gil::test::fixture: Classes and typedefs: - `do_test` as `fixture::channel` - `value_core` as `fixture::channel_value` - `reference_core` as `fixture::channel_reference` - `packed_reference_core` as `fixture::packed_channel_reference` - `packed_dynamic_reference_core` as `fixture::packed_dynamic_channel_reference` - `channel_archetype` and relatives to `channel_concepts.cpp` which is compile test in Jamfile - `test_packed_channel_reference()` parts as `fixture::packed_channels565` - `test_packed_dynamic_channel_reference()` parts as `fixture::packed_dynamic_channels565` Test case functions called from `do_test<T>::test_all`: - `test_channel_invert()` to `algorithm_channel_invert.cpp` suite - `test_channel_convert()` to `algorithm_channel_convert.cpp` suite - `test_channel_multiply()` to `algorithm_channel_multiply.cpp` suite - `test_channel_math()` split to `algorithm_channel_relation.cpp` and `algorithm_channel_arithmetic.cpp` Add test cases for each channel value type T as used to run from `test_channel_value_impl<T>`, `test_packed_channel_reference<T>` and `test_packed_dynamic_channel_reference<T>`. Add list of possible T-s defined as type-lists `fixture::channel_byte_types`, `fixture::channel_integer_types`, `channel_float_types` and `channel_bitfield_types` which used with `BOOST_AUTO_TEST_CASE_TEMPLATE` generate all possible combination of inputs. Add new `channel_test_fixture.cpp` is a self-test suite verifying the fixtures.
56 lines
2.2 KiB
C++
56 lines
2.2 KiB
C++
//
|
|
// Copyright 2005-2007 Adobe Systems Incorporated
|
|
// Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
|
|
//
|
|
// Distribtted under the Boost Software License, Version 1.0
|
|
// See accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt
|
|
//
|
|
#include <boost/gil/channel.hpp>
|
|
#include <boost/gil/channel_algorithm.hpp>
|
|
#include <boost/gil/typedefs.hpp>
|
|
#include <cstdint>
|
|
#include <limits>
|
|
|
|
#define BOOST_TEST_MODULE test_scoped_channel_value
|
|
#include <gil_test_common.hpp>
|
|
|
|
namespace gil = boost::gil;
|
|
|
|
BOOST_AUTO_TEST_CASE(scoped_channel_float32_t)
|
|
{
|
|
auto const tolerance = btt::tolerance(std::numeric_limits<float>::epsilon());
|
|
// min
|
|
BOOST_TEST(gil::float_point_zero<float>::apply() == 0.0, tolerance);
|
|
BOOST_TEST(gil::channel_traits<gil::float32_t>::min_value() == 0.0);
|
|
// max
|
|
BOOST_TEST(gil::float_point_one<float>::apply() == 1.0, tolerance);
|
|
BOOST_TEST(gil::channel_traits<gil::float32_t>::max_value() == 1.0);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(scoped_channel_float64_t)
|
|
{
|
|
auto const tolerance = btt::tolerance(std::numeric_limits<double>::epsilon());
|
|
// min
|
|
BOOST_TEST(gil::float_point_zero<double>::apply() == 0.0, tolerance);
|
|
BOOST_TEST(gil::channel_traits<gil::float64_t>::min_value() == 0.0, tolerance);
|
|
// max
|
|
BOOST_TEST(gil::float_point_one<double>::apply() == 1.0, tolerance);
|
|
BOOST_TEST(gil::channel_traits<gil::float64_t>::max_value() == 1.0, tolerance);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(scoped_channel_halfs)
|
|
{
|
|
// Create a double channel with range [-0.5 .. 0.5]
|
|
struct minus_half { static double apply() { return -0.5; } };
|
|
struct plus_half { static double apply() { return 0.5; } };
|
|
using halfs = gil::scoped_channel_value<double, minus_half, plus_half>;
|
|
|
|
auto const tolerance = btt::tolerance(std::numeric_limits<double>::epsilon());
|
|
BOOST_TEST(gil::channel_traits<halfs>::min_value() == minus_half::apply(), tolerance);
|
|
BOOST_TEST(gil::channel_traits<halfs>::max_value() == plus_half::apply(), tolerance);
|
|
// scoped channel maximum should map to the maximum
|
|
BOOST_TEST(gil::channel_convert<std::uint16_t>(
|
|
gil::channel_traits<halfs>::max_value()) == 65535, tolerance);
|
|
}
|