2015-08-20 21:09:14 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// This code is licensed under the MIT License (MIT).
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <UnitTest++/UnitTest++.h>
|
2015-11-04 15:42:27 -05:00
|
|
|
#include <span.h>
|
2015-08-20 21:09:14 -04:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace std;
|
2015-09-29 19:41:37 -04:00
|
|
|
using namespace gsl;;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2015-10-15 17:29:35 -04:00
|
|
|
void use(std::ptrdiff_t&) {}
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SUITE(bounds_test)
|
|
|
|
{
|
|
|
|
TEST(basic_bounds)
|
|
|
|
{
|
2015-10-15 17:29:35 -04:00
|
|
|
for (auto point : static_bounds<dynamic_range, 3, 4 > { 2 })
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
2015-11-12 22:27:53 -05:00
|
|
|
for (decltype(point)::size_type j = 0;
|
|
|
|
j < static_cast<decltype(point)::size_type>(decltype(point)::rank);
|
|
|
|
j++)
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
|
|
|
use(j);
|
|
|
|
use(point[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(bounds_basic)
|
|
|
|
{
|
2015-10-15 17:29:35 -04:00
|
|
|
static_bounds<3, 4, 5> b;
|
2015-08-20 21:09:14 -04:00
|
|
|
auto a = b.slice();
|
2015-11-12 22:27:53 -05:00
|
|
|
(void)a;
|
2015-10-15 17:29:35 -04:00
|
|
|
static_bounds<4, dynamic_range, 2> x{ 4 };
|
2015-08-20 21:09:14 -04:00
|
|
|
x.slice().slice();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST (arrayview_iterator)
|
|
|
|
{
|
2015-10-15 17:29:35 -04:00
|
|
|
static_bounds<4, dynamic_range, 2> bounds{ 3 };
|
2015-08-20 21:09:14 -04:00
|
|
|
|
|
|
|
auto itr = bounds.begin();
|
2015-11-12 22:27:53 -05:00
|
|
|
(void)itr;
|
2015-08-20 21:09:14 -04:00
|
|
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
2016-02-24 13:29:29 -05:00
|
|
|
multi_span<int, 4, dynamic_range, 2> av(nullptr, bounds);
|
2015-08-20 21:09:14 -04:00
|
|
|
|
|
|
|
auto itr2 = av.cbegin();
|
|
|
|
|
2015-10-15 17:29:35 -04:00
|
|
|
for (auto& v : av) {
|
2015-08-20 21:09:14 -04:00
|
|
|
v = 4;
|
|
|
|
}
|
|
|
|
fill(av.begin(), av.end(), 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST (bounds_convertible)
|
|
|
|
{
|
2015-10-15 17:29:35 -04:00
|
|
|
static_bounds<7, 4, 2> b1;
|
|
|
|
static_bounds<7, dynamic_range, 2> b2 = b1;
|
2015-11-12 22:27:53 -05:00
|
|
|
(void)b2;
|
2015-08-20 21:09:14 -04:00
|
|
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
2015-10-15 17:29:35 -04:00
|
|
|
static_bounds<7, dynamic_range, 1> b4 = b2;
|
2015-08-20 21:09:14 -04:00
|
|
|
#endif
|
|
|
|
|
2015-10-15 17:29:35 -04:00
|
|
|
static_bounds<dynamic_range, dynamic_range, dynamic_range> b3 = b1;
|
|
|
|
static_bounds<7, 4, 2> b4 = b3;
|
2015-11-12 22:27:53 -05:00
|
|
|
(void)b4;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2015-10-15 17:29:35 -04:00
|
|
|
static_bounds<dynamic_range> b11;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2015-10-15 17:29:35 -04:00
|
|
|
static_bounds<dynamic_range> b5;
|
|
|
|
static_bounds<34> b6;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2015-10-15 17:29:35 -04:00
|
|
|
b5 = static_bounds<20>();
|
2015-08-20 21:09:14 -04:00
|
|
|
CHECK_THROW(b6 = b5, fail_fast);
|
2015-10-15 17:29:35 -04:00
|
|
|
b5 = static_bounds<34>();
|
2015-08-20 21:09:14 -04:00
|
|
|
b6 = b5;
|
|
|
|
|
|
|
|
CHECK(b5 == b6);
|
|
|
|
CHECK(b5.size() == b6.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int, const char *[])
|
|
|
|
{
|
|
|
|
return UnitTest::RunAllTests();
|
|
|
|
}
|