~ubuntu-branches/ubuntu/vivid/soundscaperenderer/vivid

« back to all changes in this revision

Viewing changes to apf/unit_tests/test_stride_iterator.cpp

  • Committer: Package Import Robot
  • Author(s): IOhannes m zmölnig (Debian/GNU)
  • Date: 2014-05-08 16:58:09 UTC
  • Revision ID: package-import@ubuntu.com-20140508165809-7tz9dhu5pvo5wy25
Tags: upstream-0.4.1~dfsg
Import upstream version 0.4.1~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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           *
 
5
 *                                                                            *
 
6
 * This file is part of the Audio Processing Framework (APF).                 *
 
7
 *                                                                            *
 
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.                                                         *
 
12
 *                                                                            *
 
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.                       *
 
17
 *                                                                            *
 
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/>.            *
 
20
 *                                                                            *
 
21
 *                                 http://AudioProcessingFramework.github.com *
 
22
 ******************************************************************************/
 
23
 
 
24
// Tests for stride_iterator.
 
25
 
 
26
#define APF_STRIDE_ITERATOR_DEFAULT_STRIDE 1
 
27
#include "apf/iterator.h"  // for stride_iterator
 
28
#include "iterator_test_macros.h"
 
29
 
 
30
#include "catch/catch.hpp"
 
31
 
 
32
using si = apf::stride_iterator<int*>;
 
33
 
 
34
TEST_CASE("iterators/stride_iterator", "Test all functions of stride_iterator")
 
35
{
 
36
 
 
37
// First, the straightforward functions (with a default stride of 1)
 
38
 
 
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)
 
49
 
 
50
// ... then the specific stride_iterator stuff
 
51
 
 
52
SECTION("stride", "Test if stride works.")
 
53
{
 
54
  int array[9];
 
55
 
 
56
  auto iter = si(array, 2);
 
57
 
 
58
  CHECK(iter.base() == &array[0]);
 
59
  CHECK(iter.step_size() == 2);
 
60
 
 
61
  ++iter;
 
62
  CHECK(iter.base() == &array[2]);
 
63
 
 
64
  iter++;
 
65
  CHECK(iter.base() == &array[4]);
 
66
 
 
67
  CHECK((iter + 2).base() == &array[8]);
 
68
  CHECK((2 + iter).base() == &array[8]);
 
69
 
 
70
  iter += 2;
 
71
  CHECK(iter.base() == &array[8]);
 
72
 
 
73
  iter--;
 
74
  CHECK(iter.base() == &array[6]);
 
75
 
 
76
  --iter;
 
77
  CHECK(iter.base() == &array[4]);
 
78
 
 
79
  CHECK((iter - 2).base() == &array[0]);
 
80
 
 
81
  iter -= 2;
 
82
  CHECK(iter.base() == &array[0]);
 
83
}
 
84
 
 
85
SECTION("special constructor"
 
86
    , "Test if constructor from another stride_iterator works.")
 
87
{
 
88
  int array[9];
 
89
 
 
90
  auto iter1 = si(array, 2);
 
91
  CHECK(iter1.step_size() == 2);
 
92
 
 
93
  auto iter2 = si(iter1, 3);
 
94
  CHECK(iter2.step_size() == 6);
 
95
 
 
96
  ++iter2;
 
97
 
 
98
  CHECK(iter2.base() == &array[6]);
 
99
}
 
100
 
 
101
} // TEST_CASE
 
102
 
 
103
// Settings for Vim (http://www.vim.org/), please do not remove:
 
104
// vim:softtabstop=2:shiftwidth=2:expandtab:textwidth=80:cindent