File: interval_union.cpp

package info (click to toggle)
cbmc 6.6.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,852 kB
  • sloc: cpp: 386,459; ansic: 114,466; java: 28,405; python: 6,003; yacc: 4,552; makefile: 4,041; lex: 2,487; xml: 2,388; sh: 2,050; perl: 557; pascal: 184; javascript: 163; ada: 36
file content (55 lines) | stat: -rw-r--r-- 2,068 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Author: Diffblue Limited

#include <testing-utils/use_catch.h>

#include <util/interval_union.h>

TEST_CASE("interval_union", "[core][test-gen-util][interval_union]")
{
  // Define interval union [:-10][-5:0][5:10]
  interval_uniont first =
    interval_uniont::smaller_or_equal(-10)
      .make_union(interval_uniont::greater_or_equal(-5).make_intersection(
        interval_uniont::smaller_or_equal(0)))
      .make_union(interval_uniont::greater_or_equal(5))
      .make_intersection(interval_uniont::smaller_or_equal(10));

  REQUIRE(first.to_string() == "[:-10][-5:0][5:10]");

  // Define interval union [:-15][-8:-6][1:2][4:5][8:]
  interval_uniont second =
    interval_uniont::smaller_or_equal(-15)
      .make_union(interval_uniont::greater_or_equal(-8).make_intersection(
        interval_uniont::smaller_or_equal(-6)))
      .make_union(interval_uniont::greater_or_equal(1).make_intersection(
        interval_uniont::smaller_or_equal(2)))
      .make_union(interval_uniont::greater_or_equal(4).make_intersection(
        interval_uniont::smaller_or_equal(5)))
      .make_union(interval_uniont::greater_or_equal(8));

  REQUIRE(second.to_string() == "[:-15][-8:-6][1:2][4:5][8:]");

  // Define interval union [12:]
  interval_uniont third = interval_uniont::greater_or_equal(12);
  REQUIRE(third.to_string() == "[12:]");

  REQUIRE_FALSE(first.is_empty());
  REQUIRE(first.maximum().has_value());
  REQUIRE(first.maximum().value() == 10);
  REQUIRE_FALSE(first.minimum().has_value());

  REQUIRE_FALSE(second.is_empty());
  REQUIRE_FALSE(second.maximum().has_value());
  REQUIRE_FALSE(second.minimum().has_value());

  REQUIRE_FALSE(third.is_empty());
  REQUIRE_FALSE(third.maximum().has_value());
  REQUIRE(third.minimum().has_value());
  REQUIRE(third.minimum().value() == 12);

  REQUIRE(first.make_union(second).to_string() == "[:-10][-8:2][4:]");
  REQUIRE(first.make_intersection(second).to_string() == "[:-15][5:5][8:10]");

  REQUIRE(first.make_intersection(third).is_empty());
  REQUIRE(first.make_intersection(third).to_string() == "[]");
}