libStatGen Software  1
TestPosList.cpp
1 /*
2  * Copyright (C) 2011 Regents of the University of Michigan
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include "TestPosList.h"
18 #include <assert.h>
19 #include <stdexcept>
20 
21 
22 void testPosList()
23 {
24  TestPosList posListTest;
25  posListTest.testPosList();
26 }
27 
28 TestPosList::TestPosList()
29 {
30 }
31 
32 
33 TestPosList::~TestPosList()
34 {
35 }
36 
37 
38 void TestPosList::testPosList()
39 {
40  assert(myPosList.size() == 24);
41 
42  for(int i = 0; i < 24; i++)
43  {
44  assert(myPosList.at(i).size() == 100);
45  }
46 
47  bool caught = false;
48  try
49  {
50  myPosList.at(24);
51  }
52  catch(std::out_of_range& oor)
53  {
54  caught = true;
55  }
56 
57  assert(caught == true);
58 
59  //////////////////////////////
60  // Test accessing
61  for(int i = 0; i < 24; i++)
62  {
63  for(int j = 0; j < 100; j++)
64  {
65  assert(!hasPosition(i, j));
66  }
67  }
68 
69  //////////////////////////////
70  // Test setting all
71  for(int i = 0; i < 24; i++)
72  {
73  for(int j = 0; j < 100; j++)
74  {
75  addPosition(i, j);
76  }
77  }
78  for(int i = 0; i < 24; i++)
79  {
80  for(int j = 0; j < 100; j++)
81  {
82  assert(hasPosition(i, j));
83  }
84  }
85 
86 
87 
88 
89  //////////////////////////////
90  // Test accessing out of range
91  assert(!hasPosition(-1, 0));
92  assert(!hasPosition(0, -1));
93  assert(!hasPosition(100, 0));
94  assert(!hasPosition(0, 1000));
95 
96  //////////////////////////////
97  // Test adding more to ref 4,
98  // but skipping positions.
99  for(int j = 300; j < 350; j++)
100  {
101  addPosition(4, j);
102  }
103  for(int j = 0; j < 100; j++)
104  {
105  assert(hasPosition(4, j));
106  }
107  for(int j = 100; j < 300; j++)
108  {
109  assert(!hasPosition(4, j));
110  }
111  for(int j = 300; j < 350; j++)
112  {
113  assert(hasPosition(4, j));
114  }
115 
116  // Test adding a new reference, 30,
117  // position 16.
118  addPosition(30, 16);
119 
120  // Check the size now.
121  assert(myPosList.size() == 31);
122 
123  for(int i = 0; i < 24; i++)
124  {
125  if(i != 4)
126  {
127  assert(myPosList.at(i).size() == 100);
128  }
129  else
130  {
131  assert(myPosList.at(i).size() == 350);
132  }
133  }
134 
135  for(int i = 24; i < 31; i++)
136  {
137  assert(myPosList.at(i).size() == 350);
138  }
139 
140  //////////////////////////////
141  // Test accessing
142  for(int i = 24; i < 30; i++)
143  {
144  for(int j = 0; j < 350; j++)
145  {
146  assert(!hasPosition(i, j));
147  }
148  }
149  for(int j = 0; j < 350; j++)
150  {
151  if(j != 16)
152  {
153  assert(!hasPosition(30, j));
154  }
155  else
156  {
157  assert(hasPosition(30, 16));
158  }
159  }
160 }
TestPosList
Definition: TestPosList.h:23
PosList::hasPosition
bool hasPosition(int refID, int refPosition)
Return whether or not this list contains the specified reference ID and position (negative values wil...
Definition: PosList.cpp:81
PosList::addPosition
void addPosition(int refID, int refPosition)
Add the specified reference id/position (negative values will not be added).
Definition: PosList.cpp:42