| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // bound_number.t.h
- // limit
- //
- // Created by Sam Jaffe on 2/3/17.
- //
- #pragma once
- #include "bound_number.hpp"
- #include <cxxtest/TestSuite.h>
- class bound_number_TestSuite : public CxxTest::TestSuite {
- public:
- using number_t = bound_number<int, -5, +7>;
-
- // Fails to compile because of well-ordered principle
- // void test_bounds_compiler_error() {
- // bound_number<int, 0, -1>(0);
- // }
-
- void test_number_construct_inbounds() {
- number_t n{0};
- TS_ASSERT_EQUALS(n, 0);
- }
-
- void test_number_validate_oob_low() {
- TS_ASSERT_THROWS((number_t{check_bounds, -6}), std::out_of_range);
- }
- void test_number_validate_oob_high() {
- TS_ASSERT_THROWS((number_t{check_bounds, +8}), std::out_of_range);
- }
- void test_number_cannot_construct_oob_low() {
- number_t n{-6};
- TS_ASSERT_EQUALS(n, number_t::min);
- }
-
- void test_number_cannot_construct_oob_high() {
- number_t n{10};
- TS_ASSERT_EQUALS(n, number_t::max);
- }
-
- void test_number_cannot_increment_above_limit() {
- number_t n{+7};
- TS_ASSERT_EQUALS(n++, number_t::max);
- TS_ASSERT_EQUALS(n, number_t::max);
- }
- void test_number_cannot_decrement_below_limit() {
- number_t n{-5};
- TS_ASSERT_EQUALS(n--, number_t::min);
- TS_ASSERT_EQUALS(n, number_t::min);
- }
- };
|