From 1d936eb90cae66e561259ec12850aac7f79782d8 Mon Sep 17 00:00:00 2001 From: menete Date: Tue, 31 Oct 2017 18:11:45 +0100 Subject: [PATCH] additional span tests (pointer length constructor) (#568) --- tests/span_tests.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 69a7923..bc4666b 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -183,9 +183,33 @@ TEST_CASE("from_pointer_length_constructor") int arr[4] = {1, 2, 3, 4}; { - span s{&arr[0], 2}; - CHECK((s.length() == 2 && s.data() == &arr[0])); - CHECK((s[0] == 1 && s[1] == 2)); + for(int i = 0; i<4 ; ++i) + { + { + span s = { &arr[0], i }; + CHECK(s.length() == i); + CHECK(s.data() == &arr[0]); + CHECK(s.empty() == (i == 0)); + for (int j = 0; j < i; ++j) + { + CHECK(arr[j] == s[j]); + CHECK(arr[j] == s.at(j)); + CHECK(arr[j] == s(j)); + } + } + { + span s = { &arr[i], 4-i }; + CHECK(s.length() == 4-i); + CHECK(s.data() == &arr[i]); + CHECK(s.empty() == (4-i == 0)); + for (int j = 0; j < 4-i; ++j) + { + CHECK(arr[j+i] == s[j]); + CHECK(arr[j+i] == s.at(j)); + CHECK(arr[j+i] == s(j)); + } + } + } } {