source: trunk/test/segment_test.cc @ 2294

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

refs #635. fix return type (int) in compare_3way and add some more test for Segment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1// $Id: segment_test.cc 2294 2010-07-07 18:19:22Z 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
27int main(int argc, char* argv[])
28{ 
29  using namespace theplu::yat::utility;
30  theplu::yat::test::Suite suite(argc, argv);
31
32  Segment<double> segment;
33  Segment<double> segment2(0,2);
34
35  SegmentSet<double> set;
36  if (set.size()!=0) {
37    suite.add(false);
38    suite.err() << "expected size 0\n";
39  }
40  set.insert(segment2);
41  if (set.size()!=1) {
42    suite.add(false);
43    suite.err() << "expected size 1\n";
44  }
45  set.insert(segment2);
46  if (set.size()!=1) {
47    suite.add(false);
48    suite.err() << "expected size 1\n";
49  }
50  if (!suite.add(set.find(0)!=set.end()))
51    suite.err() << "error: set.find(0): expected not end()\n";
52 
53  // test count
54  if (!suite.add(set.count(0)==1))
55    suite.err() << "error: set.count(0): expected 1\n";
56  if (!suite.add(set.count(1)==1))
57    suite.err() << "error: set.count(1): expected 1\n";
58  if (!suite.add(set.count(2)==0))
59    suite.err() << "error: set.count(2): expected 0\n";
60
61  set.insert_merge(Segment<double>(3,5));
62  if (!suite.add(set.size()==2))
63    suite.err() << "error: set.size(): expected 2\n";
64
65  set.insert_merge(Segment<double>(12,13));
66  if (!suite.add(set.size()==3))
67    suite.err() << "error: set.size(): expected 3\n";
68
69  set.insert_merge(Segment<double>(1,4));
70  if (!suite.add(set.size()==2))
71    suite.err() << "error: set.size(): " << set.size() << " expected 2\n";
72
73  set.insert_merge(Segment<double>(0,100));
74  if (!suite.add(set.size()==1))
75    suite.err() << "error: set.size(): " << set.size() << " expected 1\n";
76
77  set.begin();
78  set.end();
79  if (!suite.add(set.lower_bound(Segment<double>(-1,2))==set.begin()))
80    suite.err() << "error: expected set.lower_bound to return begin()\n";
81  if (!suite.add(set.upper_bound(Segment<double>(-1,2))==set.end()))
82    suite.err() << "error: expected set.upper_bound to return end()\n";
83
84  Segment<double> segment12(0,2);
85  Segment<double> segment13(1,3);
86  Segment<double> segment14 = intersection(segment12, segment13);
87  suite.add(segment14.begin()==1);
88  suite.add(segment14.end()==2);
89
90  if (!suite.add(compare(Segment<double>(0,2), Segment<double>(3,4))))
91    suite.err() << "error: compare: expected 1\n";
92  if (!suite.add(compare_3way(Segment<double>(0,2), Segment<double>(3,4))==-1))
93    suite.err() << "error: compare_3way: expected -1\n";
94
95  if (!suite.add(compare(Segment<double>(0,2), Segment<double>(1,2))==false))
96    suite.err() << "error: compare: expected 0\n";
97  if (!suite.add(compare_3way(Segment<double>(0,2), Segment<double>(1,2))==0))
98    suite.err() << "error: compare_3way: expected 0\n";
99
100  if (!suite.add(compare(Segment<double>(3,4), Segment<double>(0,2))==false))
101    suite.err() << "error: compare: expected 0\n";
102  if (!suite.add(compare_3way(Segment<double>(3,4), Segment<double>(0,2))==1))
103    suite.err() << "error: compare_3way: expected 1\n";
104
105  return suite.return_value();
106}
Note: See TracBrowser for help on using the repository browser.