Changeset 2296


Ignore:
Timestamp:
Jul 8, 2010, 9:39:42 PM (11 years ago)
Author:
Peter
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/segment_test.cc

    r2294 r2296  
    2525#include "yat/utility/SegmentSet.h"
    2626
     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
    2735int main(int argc, char* argv[])
    2836
    29   using namespace theplu::yat::utility;
    30   theplu::yat::test::Suite suite(argc, argv);
     37  test::Suite suite(argc, argv);
    3138
     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{
    3250  Segment<double> segment;
    3351  Segment<double> segment2(0,2);
     
    4866    suite.err() << "expected size 1\n";
    4967  }
     68  set.insert(Segment<double>(1,3));
     69  if (set.size()!=1) {
     70    suite.add(false);
     71    suite.err() << "expected size 1\n";
     72  }
    5073  if (!suite.add(set.find(0)!=set.end()))
    5174    suite.err() << "error: set.find(0): expected not end()\n";
    52  
     75}
     76
     77void test_count(test::Suite& suite)
     78{
     79  SegmentSet<double> set;
     80  set.insert(Segment<double>(0,2));
    5381  // test count
    5482  if (!suite.add(set.count(0)==1))
     
    5886  if (!suite.add(set.count(2)==0))
    5987    suite.err() << "error: set.count(2): expected 0\n";
     88}
    6089
     90void test_insert_merge(test::Suite& suite)
     91{
     92  SegmentSet<double> set;
     93  set.insert(Segment<double>(0,2));
    6194  set.insert_merge(Segment<double>(3,5));
    6295  if (!suite.add(set.size()==2))
     
    74107  if (!suite.add(set.size()==1))
    75108    suite.err() << "error: set.size(): " << set.size() << " expected 1\n";
     109}
    76110
     111void test_set_bound(test::Suite& suite)
     112{
     113  SegmentSet<double> set;
     114  set.insert(Segment<double>(0,2));
    77115  set.begin();
    78116  set.end();
     
    81119  if (!suite.add(set.upper_bound(Segment<double>(-1,2))==set.end()))
    82120    suite.err() << "error: expected set.upper_bound to return end()\n";
     121  set.clear();
     122}
    83123
     124void test_segment(test::Suite& suite)
     125{
    84126  Segment<double> segment12(0,2);
    85127  Segment<double> segment13(1,3);
     
    103145    suite.err() << "error: compare_3way: expected 1\n";
    104146
    105   return suite.return_value();
    106147}
  • trunk/yat/utility/SegmentSet.h

    r2292 r2296  
    7878     */
    7979    iterator begin(void) { return set_.begin(); }
     80
     81    /**
     82       \brief erases all the segments
     83     */
     84    void clear(void) { set_.clear(); }
    8085
    8186    /**
     
    216221  SegmentSet<T, Compare>::insert(const value_type& segment)
    217222  {
    218     iterator iter = set_.lower_bound(segment);
    219     return set_.insert(segment);
     223    std::pair<iterator, iterator> p = overlap_range(segment);
     224    std::pair<typename SegmentSet<T, Compare>::iterator, bool> result;
     225    if (p.first==p.second) {
     226      result.first = set_.insert(p.first, segment);
     227      result.second = true;
     228      return result;
     229    }
     230    result.first = p.first;
     231    result.second = false;
     232    return result;
    220233  }
    221234
Note: See TracChangeset for help on using the changeset viewer.