Changeset 3649 for trunk/test/segment.cc


Ignore:
Timestamp:
Jun 15, 2017, 5:27:23 AM (6 years ago)
Author:
Peter
Message:

added functions includes and overlap for Segment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/segment.cc

    r3598 r3649  
    3333void test_count(test::Suite&);
    3434void test_erase(test::Suite&);
     35void test_includes(test::Suite&);
    3536void test_insert(test::Suite&);
    3637void test_insert_merge(test::Suite&);
    3738void test_make_segment(test::Suite&);
     39void test_overlap(test::Suite&);
    3840void test_segment(test::Suite& suite);
    3941void test_operator(test::Suite& suite);
     
    5153  test_count(suite);
    5254  test_erase(suite);
     55  test_includes(suite);
    5356  test_insert(suite);
    5457  test_insert_merge(suite);
    5558  test_make_segment(suite);
     59  test_overlap(suite);
    5660  test_segment(suite);
    5761  test_set_bound(suite);
     
    329333
    330334}
     335
     336
     337void test_includes(test::Suite& suite, const Segment<int>& a,
     338                   const Segment<int>& b, bool answer)
     339{
     340  if (includes(a, b) != answer) {
     341    suite.add(false);
     342    suite.err() << "error: includes: "
     343                << "[" << a.begin() << ", "
     344                << a.end() << ") "
     345                << "[" << b.begin() << ", "
     346                << b.end() << ") "
     347                << "expected: " << answer << "\n";
     348  }
     349}
     350
     351
     352void test_includes(test::Suite& suite)
     353{
     354  Segment<int> a(0, 10);
     355  Segment<int> b(0, 5);
     356  Segment<int> c(5, 10);
     357
     358  test_includes(suite, a, a, true);
     359  test_includes(suite, a, b, false);
     360  test_includes(suite, a, c, false);
     361
     362  test_includes(suite, b, a, true);
     363  test_includes(suite, b, b, true);
     364  test_includes(suite, b, c, false);
     365
     366  test_includes(suite, c, a, true);
     367  test_includes(suite, c, b, false);
     368  test_includes(suite, c, c, true);
     369}
     370
     371
     372void test_overlap(test::Suite& suite, const Segment<int>& a,
     373                  const Segment<int>& b, bool answer)
     374{
     375  if (overlap(a, b) != answer) {
     376    suite.add(false);
     377    suite.err() << "error: overlap: "
     378                << "[" << a.begin() << ", "
     379                << a.end() << ") "
     380                << "[" << b.begin() << ", "
     381                << b.end() << ") "
     382                << "expected: " << answer << "\n";
     383  }
     384}
     385
     386
     387void test_overlap(test::Suite& suite)
     388{
     389  Segment<int> a(0, 10);
     390  Segment<int> b(0, 5);
     391  Segment<int> c(5, 10);
     392
     393  test_overlap(suite, a, a, true);
     394  test_overlap(suite, a, b, true);
     395  test_overlap(suite, a, c, true);
     396
     397  test_overlap(suite, b, a, true);
     398  test_overlap(suite, b, b, true);
     399  test_overlap(suite, b, c, false);
     400
     401  test_overlap(suite, c, a, true);
     402  test_overlap(suite, c, b, false);
     403  test_overlap(suite, c, c, true);
     404}
Note: See TracChangeset for help on using the changeset viewer.