File: TestHSet.cpp

package info (click to toggle)
scipy 1.16.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 236,092 kB
  • sloc: cpp: 503,720; python: 345,302; ansic: 195,677; javascript: 89,566; fortran: 56,210; cs: 3,081; f90: 1,150; sh: 857; makefile: 792; pascal: 284; csh: 135; lisp: 134; xml: 56; perl: 51
file content (80 lines) | stat: -rw-r--r-- 2,188 bytes parent folder | download | duplicates (6)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "HCheckConfig.h"
#include "catch.hpp"
#include "util/HSet.h"

const bool dev_run = false;

TEST_CASE("HSet", "[highs_test_hset]") {
  const HighsInt size = 5;
  const HighsInt max_entry = 10;
  HSet set;
  REQUIRE(!set.setup(-1, max_entry));
  REQUIRE(!set.setup(0, max_entry));
  REQUIRE(!set.setup(size, -1));
  bool debug = true;
  // Don't allow asserts so that debugging can be tested without
  // triggering an assert!
  bool allow_assert = false;
  FILE* log_file = NULL;
  if (dev_run) log_file = stdout;
  bool output_flag = false;
  if (dev_run) output_flag = true;
  REQUIRE(
      set.setup(size, max_entry, output_flag, log_file, debug, allow_assert));
  //  set.print();
  REQUIRE(!set.add(-1));
  REQUIRE(set.add(0));
  REQUIRE(set.add(1));
  REQUIRE(!set.add(1));
  //  set.print();
  REQUIRE(set.add(3));
  REQUIRE(set.add(8));
  REQUIRE(set.add(7));
  REQUIRE(set.add(5));
  //  set.print();
  REQUIRE(set.add(11));
  //  set.print();
  REQUIRE(set.add(99));
  //  set.print();
  REQUIRE(!set.remove(4));
  REQUIRE(set.remove(3));
  //  set.print();
  REQUIRE(set.remove(11));
  REQUIRE(set.remove(0));
  // Confirm that 8 is in the set
  REQUIRE(set.in(8));
  REQUIRE(set.remove(8));
  // Confirm that 8 is not in the set
  REQUIRE(!set.in(8));
  // Confirm that entry too small is not in the set
  REQUIRE(!set.in(-1));
  // Confirm that entry too big is not in the set
  REQUIRE(!set.in(999));
  REQUIRE(set.remove(5));
  REQUIRE(set.remove(99));
  REQUIRE(set.remove(1));
  REQUIRE(set.remove(7));
  //  set.print();
  set.clear();
  REQUIRE(set.add(3));
  REQUIRE(set.add(8));
  REQUIRE(set.add(7));
  REQUIRE(set.add(5));
  set.print();
  const HighsInt& count = set.count();
  const vector<HighsInt>& entry = set.entry();
  HighsInt entry_size = entry.size();
  REQUIRE(count == 4);
  REQUIRE(entry_size == 8);
  REQUIRE(entry[0] == 3);
  REQUIRE(entry[1] == 8);
  REQUIRE(entry[2] == 7);
  REQUIRE(entry[3] == 5);
  if (dev_run) {
    printf("Set(%" HIGHSINT_FORMAT ", %" HIGHSINT_FORMAT ")\nEntries: ",
           entry_size, count);
    for (HighsInt ix = 0; ix < count; ix++)
      printf(" %" HIGHSINT_FORMAT "", entry[ix]);
    printf("\n");
  }
}