source: trunk/test/segment_test.cc @ 2296

Last change on this file since 2296 was 2296, checked in by Peter, 12 years ago

class SegmentSet?: added function clear and fixed bug in insert. Divided test into subtests. refs #635

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1// $Id: segment_test.cc 2296 2010-07-08 19:39:42Z peter $
2
3/*
4  Copyright (C) 2010 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Suite.h"
23
24#include "yat/utility/Segment.h"
25#include "yat/utility/SegmentSet.h"
26
27using namespace theplu::yat;
28using namespace utility;
29void test_count(test::Suite&);
30void test_insert(test::Suite&);
31void test_insert_merge(test::Suite&);
32void test_segment(test::Suite& suite);
33void test_set_bound(test::Suite&);
34
35int main(int argc, char* argv[])
36{ 
37  test::Suite suite(argc, argv);
38
39  test_count(suite);
40  test_insert(suite);
41  test_insert_merge(suite);
42  test_segment(suite);
43  test_set_bound(suite);
44
45  return suite.return_value();
46}
47
48void test_insert(test::Suite& suite)
49{
50  Segment<double> segment;
51  Segment<double> segment2(0,2);
52
53  SegmentSet<double> set;
54  if (set.size()!=0) {
55    suite.add(false);
56    suite.err() << "expected size 0\n";
57  }
58  set.insert(segment2);
59  if (set.size()!=1) {
60    suite.add(false);
61    suite.err() << "expected size 1\n";
62  }
63  set.insert(segment2);
64  if (set.size()!=1) {
65    suite.add(false);
66    suite.err() << "expected size 1\n";
67  }
68  set.insert(Segment<double>(1,3));
69  if (set.size()!=1) {
70    suite.add(false);
71    suite.err() << "expected size 1\n";
72  }
73  if (!suite.add(set.find(0)!=set.end()))
74    suite.err() << "error: set.find(0): expected not end()\n";
75} 
76
77void test_count(test::Suite& suite)
78{
79  SegmentSet<double> set;
80  set.insert(Segment<double>(0,2));
81  // test count
82  if (!suite.add(set.count(0)==1))
83    suite.err() << "error: set.count(0): expected 1\n";
84  if (!suite.add(set.count(1)==1))
85    suite.err() << "error: set.count(1): expected 1\n";
86  if (!suite.add(set.count(2)==0))
87    suite.err() << "error: set.count(2): expected 0\n";
88}
89
90void test_insert_merge(test::Suite& suite)
91{
92  SegmentSet<double> set;
93  set.insert(Segment<double>(0,2));
94  set.insert_merge(Segment<double>(3,5));
95  if (!suite.add(set.size()==2))
96    suite.err() << "error: set.size(): expected 2\n";
97
98  set.insert_merge(Segment<double>(12,13));
99  if (!suite.add(set.size()==3))
100    suite.err() << "error: set.size(): expected 3\n";
101
102  set.insert_merge(Segment<double>(1,4));
103  if (!suite.add(set.size()==2))
104    suite.err() << "error: set.size(): " << set.size() << " expected 2\n";
105
106  set.insert_merge(Segment<double>(0,100));
107  if (!suite.add(set.size()==1))
108    suite.err() << "error: set.size(): " << set.size() << " expected 1\n";
109}
110
111void test_set_bound(test::Suite& suite)
112{
113  SegmentSet<double> set;
114  set.insert(Segment<double>(0,2));
115  set.begin();
116  set.end();
117  if (!suite.add(set.lower_bound(Segment<double>(-1,2))==set.begin()))
118    suite.err() << "error: expected set.lower_bound to return begin()\n";
119  if (!suite.add(set.upper_bound(Segment<double>(-1,2))==set.end()))
120    suite.err() << "error: expected set.upper_bound to return end()\n";
121  set.clear();
122}
123
124void test_segment(test::Suite& suite)
125{
126  Segment<double> segment12(0,2);
127  Segment<double> segment13(1,3);
128  Segment<double> segment14 = intersection(segment12, segment13);
129  suite.add(segment14.begin()==1);
130  suite.add(segment14.end()==2);
131
132  if (!suite.add(compare(Segment<double>(0,2), Segment<double>(3,4))))
133    suite.err() << "error: compare: expected 1\n";
134  if (!suite.add(compare_3way(Segment<double>(0,2), Segment<double>(3,4))==-1))
135    suite.err() << "error: compare_3way: expected -1\n";
136
137  if (!suite.add(compare(Segment<double>(0,2), Segment<double>(1,2))==false))
138    suite.err() << "error: compare: expected 0\n";
139  if (!suite.add(compare_3way(Segment<double>(0,2), Segment<double>(1,2))==0))
140    suite.err() << "error: compare_3way: expected 0\n";
141
142  if (!suite.add(compare(Segment<double>(3,4), Segment<double>(0,2))==false))
143    suite.err() << "error: compare: expected 0\n";
144  if (!suite.add(compare_3way(Segment<double>(3,4), Segment<double>(0,2))==1))
145    suite.err() << "error: compare_3way: expected 1\n";
146
147}
Note: See TracBrowser for help on using the repository browser.