Update coverage report.
[ocaml-bitstring.git] / tests / 32_bitstring_compare.ml
1 (* Compare bitstrings.
2  * $Id$
3  *)
4
5 open Printf
6
7 let sgn = function
8   | 0 -> 0
9   | i when i > 0 -> 1
10   | _ -> -1
11
12 let () =
13   for i = 0 to 33 do
14     for j = 0 to 33 do
15       let bits1 = Bitstring.ones_bitstring i
16       and bits2 = Bitstring.ones_bitstring j in
17       let r = Bitstring.compare bits1 bits2 in
18       if sgn r <> sgn (compare i j) then (
19         eprintf "ones compare failed %d %d %d\n" i j r;
20         exit 1
21       )
22     done
23  done;
24  for i = 0 to 33 do
25    for j = 0 to 33 do
26      let bits1 = Bitstring.zeroes_bitstring i
27      and bits2 = Bitstring.zeroes_bitstring j in
28      let r = Bitstring.compare bits1 bits2 in
29      if sgn r <> sgn (compare i j) then (
30        eprintf "zeroes compare failed %d %d %d\n" i j r;
31        exit 1
32      )
33    done
34  done;
35  for i = 0 to 33 do
36    for j = 0 to 33 do
37      let bits1 = Bitstring.make_bitstring i '\x55'
38      and bits2 = Bitstring.make_bitstring j '\x55' in
39      let r = Bitstring.compare bits1 bits2 in
40      if sgn r <> sgn (compare i j) then (
41        eprintf "x55 compare failed %d %d %d\n" i j r;
42        exit 1
43      )
44    done
45  done;
46  for i = 0 to 33 do
47    for j = 0 to 33 do
48      let bits1 = Bitstring.make_bitstring i '\x55' in
49      let bits2 = Bitstring.make_bitstring i '\x55' in
50      let bits2 = Bitstring.concat [Bitstring.zeroes_bitstring j; bits2] in
51      assert (Bitstring.bitstring_length bits2 = j+i);
52      let bits2 = Bitstring.dropbits j bits2 in
53      assert (Bitstring.bitstring_length bits2 = i);
54      let r = Bitstring.compare bits1 bits2 in
55      if r <> 0 then (
56        eprintf "x55 non-aligned compare failed %d %d %d\n" i j r;
57        exit 1
58      )
59    done
60  done