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
|
(* Compare bitstrings.
* $Id$
*)
open Printf
let sgn = function
| 0 -> 0
| i when i > 0 -> 1
| _ -> -1
let () =
for i = 0 to 33 do
for j = 0 to 33 do
let bits1 = Bitstring.ones_bitstring i
and bits2 = Bitstring.ones_bitstring j in
let r = Bitstring.compare bits1 bits2 in
if sgn r <> sgn (compare i j) then (
eprintf "ones compare failed %d %d %d\n" i j r;
exit 1
)
done
done;
for i = 0 to 33 do
for j = 0 to 33 do
let bits1 = Bitstring.zeroes_bitstring i
and bits2 = Bitstring.zeroes_bitstring j in
let r = Bitstring.compare bits1 bits2 in
if sgn r <> sgn (compare i j) then (
eprintf "zeroes compare failed %d %d %d\n" i j r;
exit 1
)
done
done;
for i = 0 to 33 do
for j = 0 to 33 do
let bits1 = Bitstring.make_bitstring i '\x55'
and bits2 = Bitstring.make_bitstring j '\x55' in
let r = Bitstring.compare bits1 bits2 in
if sgn r <> sgn (compare i j) then (
eprintf "x55 compare failed %d %d %d\n" i j r;
exit 1
)
done
done;
for i = 0 to 33 do
for j = 0 to 33 do
let bits1 = Bitstring.make_bitstring i '\x55' in
let bits2 = Bitstring.make_bitstring i '\x55' in
let bits2 = Bitstring.concat [Bitstring.zeroes_bitstring j; bits2] in
assert (Bitstring.bitstring_length bits2 = j+i);
let bits2 = Bitstring.dropbits j bits2 in
assert (Bitstring.bitstring_length bits2 = i);
let r = Bitstring.compare bits1 bits2 in
if r <> 0 then (
eprintf "x55 non-aligned compare failed %d %d %d\n" i j r;
exit 1
)
done
done
|