1
/******************************************************************************
2
* Copyright © 2012-2014 Institut für Nachrichtentechnik, Universität Rostock *
3
* Copyright © 2006-2012 Quality & Usability Lab, *
4
* Telekom Innovation Laboratories, TU Berlin *
6
* This file is part of the Audio Processing Framework (APF). *
8
* The APF is free software: you can redistribute it and/or modify it under *
9
* the terms of the GNU General Public License as published by the Free *
10
* Software Foundation, either version 3 of the License, or (at your option) *
11
* any later version. *
13
* The APF is distributed in the hope that it will be useful, but WITHOUT ANY *
14
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
15
* FOR A PARTICULAR PURPOSE. *
16
* See the GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License along *
19
* with this program. If not, see <http://www.gnu.org/licenses/>. *
21
* http://AudioProcessingFramework.github.com *
22
******************************************************************************/
24
// Tests for stride_iterator.
26
#define APF_STRIDE_ITERATOR_DEFAULT_STRIDE 1
27
#include "apf/iterator.h" // for stride_iterator
28
#include "iterator_test_macros.h"
30
#include "catch/catch.hpp"
32
using si = apf::stride_iterator<int*>;
34
TEST_CASE("iterators/stride_iterator", "Test all functions of stride_iterator")
37
// First, the straightforward functions (with a default stride of 1)
39
ITERATOR_TEST_SECTION_BASE(si, int)
40
ITERATOR_TEST_SECTION_DEFAULT_CTOR(si)
41
ITERATOR_TEST_SECTION_COPY_ASSIGNMENT(si, int)
42
ITERATOR_TEST_SECTION_DEREFERENCE(si, int, 5)
43
ITERATOR_TEST_SECTION_OFFSET_DEREFERENCE(si, int, 5, 6)
44
ITERATOR_TEST_SECTION_EQUALITY(si, int)
45
ITERATOR_TEST_SECTION_INCREMENT(si, int)
46
ITERATOR_TEST_SECTION_DECREMENT(si, int)
47
ITERATOR_TEST_SECTION_PLUS_MINUS(si, int)
48
ITERATOR_TEST_SECTION_LESS(si, int)
50
// ... then the specific stride_iterator stuff
52
SECTION("stride", "Test if stride works.")
56
auto iter = si(array, 2);
58
CHECK(iter.base() == &array[0]);
59
CHECK(iter.step_size() == 2);
62
CHECK(iter.base() == &array[2]);
65
CHECK(iter.base() == &array[4]);
67
CHECK((iter + 2).base() == &array[8]);
68
CHECK((2 + iter).base() == &array[8]);
71
CHECK(iter.base() == &array[8]);
74
CHECK(iter.base() == &array[6]);
77
CHECK(iter.base() == &array[4]);
79
CHECK((iter - 2).base() == &array[0]);
82
CHECK(iter.base() == &array[0]);
85
SECTION("special constructor"
86
, "Test if constructor from another stride_iterator works.")
90
auto iter1 = si(array, 2);
91
CHECK(iter1.step_size() == 2);
93
auto iter2 = si(iter1, 3);
94
CHECK(iter2.step_size() == 6);
98
CHECK(iter2.base() == &array[6]);
103
// Settings for Vim (http://www.vim.org/), please do not remove:
104
// vim:softtabstop=2:shiftwidth=2:expandtab:textwidth=80:cindent