src
test.cc
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #include "src/test/range/test.h"
5 
6 namespace re2c_test {
7 
8 static bool equal (const re2c::Range * r1, const re2c::Range * r2)
9 {
10  for (; r1 && r2; r1 = r1->next (), r2 = r2->next ())
11  {
12  if (r1->lower () != r2->lower ()
13  || r1->upper () != r2->upper ())
14  {
15  return false;
16  }
17  }
18  return !r1 && !r2;
19 }
20 
21 static void show (const re2c::Range * r)
22 {
23  if (!r)
24  {
25  fprintf (stderr, "[]");
26  }
27  for (; r; r = r->next ())
28  {
29  const uint32_t l = r->lower ();
30  const uint32_t u = r->upper () - 1;
31  if (l < u)
32  {
33  fprintf (stderr, "[%X-%X]", l, u);
34  }
35  else
36  {
37  fprintf (stderr, "[%X]", l);
38  }
39  }
40 }
41 
42 static int32_t diff
43  ( const re2c::Range * r1
44  , const re2c::Range * r2
45  , const re2c::Range * op1
46  , const re2c::Range * op2
47  , const char * op)
48 {
49  if (equal (op1, op2))
50  {
51  return 0;
52  }
53  else
54  {
55  fprintf (stderr, "%s error: ", op);
56  show (r1);
57  fprintf (stderr, " %s ", op);
58  show (r2);
59  fprintf (stderr, " ====> ");
60  show (op2);
61  fprintf (stderr, " =/= ");
62  show (op1);
63  fprintf (stderr, "\n");
64  return 1;
65  }
66 }
67 
68 static int32_t test ()
69 {
70  int32_t ok = 0;
71 
72  static const uint32_t BITS = 8;
73  static const uint32_t N = 1u << BITS;
74  for (uint32_t i = 0; i <= N; ++i)
75  {
76  for (uint32_t j = 0; j <= N; ++j)
77  {
78  re2c::Range * r1 = range<BITS> (i);
79  re2c::Range * r2 = range<BITS> (j);
80  ok |= diff (r1, r2, add<BITS> (i, j), re2c::Range::add (r1, r2), "U");
81  ok |= diff (r1, r2, sub<BITS> (i, j), re2c::Range::sub (r1, r2), "D");
82  re2c::Range::vFreeList.clear ();
83  }
84  }
85 
86  return ok;
87 }
88 
89 } // namespace re2c_test
90 
91 int main ()
92 {
93  return re2c_test::test ();
94 }
static Range * sub(const Range *r1, const Range *r2)
Definition: range.cc:61
static int32_t test()
Definition: test.cc:68
uint32_t lower() const
Definition: range.h:40
static free_list< Range * > vFreeList
Definition: range.h:18
static bool equal(const re2c::Range *r1, const re2c::Range *r2)
Definition: test.cc:8
int main()
Definition: test.cc:91
uint32_t upper() const
Definition: range.h:41
static int32_t diff(const re2c::Range *r1, const re2c::Range *r2, const re2c::Range *op1, const re2c::Range *op2, const char *op)
Definition: test.cc:43
static void show(const re2c::Range *r)
Definition: test.cc:21
Range * next() const
Definition: range.h:39
static Range * add(const Range *r1, const Range *r2)
Definition: range.cc:26