mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-05-05 17:04:25 -04:00
actually run the tests
This commit is contained in:
parent
dde48d1a62
commit
36ff514792
1 changed files with 43 additions and 42 deletions
|
|
@ -1,43 +1,42 @@
|
||||||
include (val Containers_testlib.make ~__FILE__ ())
|
include (val Containers_testlib.make ~__FILE__ ())
|
||||||
module Leb128 = Containers_leb128
|
module Leb128 = Containers_leb128
|
||||||
module Bb = CCByte_buffer
|
module Buf = CCByte_buffer
|
||||||
module Bs = CCByte_slice
|
module Slice = CCByte_slice
|
||||||
|
|
||||||
let encode_decode_u64 (i : int64) : bool =
|
let encode_decode_u64 (i : int64) : bool =
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.u64 buf i;
|
Leb128.Encode.u64 buf i;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let i', n = Leb128.Decode.u64 slice 0 in
|
let i', n = Leb128.Decode.u64 slice 0 in
|
||||||
Int64.equal i i' && n = Bs.len slice
|
Int64.equal i i' && n = Slice.len slice
|
||||||
|
|
||||||
let encode_decode_i64 (i : int64) : bool =
|
let encode_decode_i64 (i : int64) : bool =
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.i64 buf i;
|
Leb128.Encode.i64 buf i;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let i', n = Leb128.Decode.i64 slice 0 in
|
let i', n = Leb128.Decode.i64 slice 0 in
|
||||||
Int64.equal i i' && n = Bs.len slice
|
Int64.equal i i' && n = Slice.len slice
|
||||||
|
|
||||||
let encode_decode_uint (i : int) : bool =
|
let encode_decode_uint (i : int) : bool =
|
||||||
i >= 0
|
i >= 0
|
||||||
&&
|
&&
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.uint buf i;
|
Leb128.Encode.uint buf i;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let i', n = Leb128.Decode.uint_truncate slice 0 in
|
let i', n = Leb128.Decode.uint_truncate slice 0 in
|
||||||
Int.equal i i' && n = Bs.len slice
|
Int.equal i i' && n = Slice.len slice
|
||||||
|
|
||||||
let encode_decode_int (i : int) : bool =
|
let encode_decode_int (i : int) : bool =
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.int buf i;
|
Leb128.Encode.int buf i;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let i', n = Leb128.Decode.int_truncate slice 0 in
|
let i', n = Leb128.Decode.int_truncate slice 0 in
|
||||||
Int.equal i i' && n = Bs.len slice
|
Int.equal i i' && n = Slice.len slice
|
||||||
|
|
||||||
let zigzag_roundtrip (i : int64) : bool =
|
let zigzag_roundtrip (i : int64) : bool =
|
||||||
let encoded = Leb128.Encode.encode_zigzag i in
|
let encoded = Leb128.Encode.encode_zigzag i in
|
||||||
let decoded = Leb128.Decode.decode_zigzag encoded in
|
let decoded = Leb128.Decode.decode_zigzag encoded in
|
||||||
Int64.equal i decoded
|
Int64.equal i decoded
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q ~count:10_000 ~long_factor:20 Q.int64 @@ fun i ->
|
q ~count:10_000 ~long_factor:20 Q.int64 @@ fun i ->
|
||||||
|
|
@ -72,9 +71,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.u64 buf 0L;
|
Leb128.Encode.u64 buf 1L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.u64 slice 0 in
|
let v, n = Leb128.Decode.u64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string 0L v;
|
assert_equal ~printer:Int64.to_string 0L v;
|
||||||
assert_equal ~printer:string_of_int 1 n;
|
assert_equal ~printer:string_of_int 1 n;
|
||||||
|
|
@ -82,9 +81,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.u64 buf 127L;
|
Leb128.Encode.u64 buf 127L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.u64 slice 0 in
|
let v, n = Leb128.Decode.u64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string 127L v;
|
assert_equal ~printer:Int64.to_string 127L v;
|
||||||
assert_equal ~printer:string_of_int 1 n;
|
assert_equal ~printer:string_of_int 1 n;
|
||||||
|
|
@ -92,9 +91,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.u64 buf 128L;
|
Leb128.Encode.u64 buf 128L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.u64 slice 0 in
|
let v, n = Leb128.Decode.u64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string 128L v;
|
assert_equal ~printer:Int64.to_string 128L v;
|
||||||
assert_equal ~printer:string_of_int 2 n;
|
assert_equal ~printer:string_of_int 2 n;
|
||||||
|
|
@ -102,9 +101,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.u64 buf 16383L;
|
Leb128.Encode.u64 buf 16383L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.u64 slice 0 in
|
let v, n = Leb128.Decode.u64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string 16383L v;
|
assert_equal ~printer:Int64.to_string 16383L v;
|
||||||
assert_equal ~printer:string_of_int 2 n;
|
assert_equal ~printer:string_of_int 2 n;
|
||||||
|
|
@ -112,9 +111,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.u64 buf 16384L;
|
Leb128.Encode.u64 buf 16384L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.u64 slice 0 in
|
let v, n = Leb128.Decode.u64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string 16384L v;
|
assert_equal ~printer:Int64.to_string 16384L v;
|
||||||
assert_equal ~printer:string_of_int 3 n;
|
assert_equal ~printer:string_of_int 3 n;
|
||||||
|
|
@ -122,9 +121,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.i64 buf 0L;
|
Leb128.Encode.i64 buf 0L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.i64 slice 0 in
|
let v, n = Leb128.Decode.i64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string 0L v;
|
assert_equal ~printer:Int64.to_string 0L v;
|
||||||
assert_equal ~printer:string_of_int 1 n;
|
assert_equal ~printer:string_of_int 1 n;
|
||||||
|
|
@ -132,9 +131,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.i64 buf (-1L);
|
Leb128.Encode.i64 buf (-1L);
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.i64 slice 0 in
|
let v, n = Leb128.Decode.i64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string (-1L) v;
|
assert_equal ~printer:Int64.to_string (-1L) v;
|
||||||
assert_equal ~printer:string_of_int 1 n;
|
assert_equal ~printer:string_of_int 1 n;
|
||||||
|
|
@ -142,9 +141,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.i64 buf 63L;
|
Leb128.Encode.i64 buf 63L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.i64 slice 0 in
|
let v, n = Leb128.Decode.i64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string 63L v;
|
assert_equal ~printer:Int64.to_string 63L v;
|
||||||
assert_equal ~printer:string_of_int 1 n;
|
assert_equal ~printer:string_of_int 1 n;
|
||||||
|
|
@ -152,9 +151,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.i64 buf (-64L);
|
Leb128.Encode.i64 buf (-64L);
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.i64 slice 0 in
|
let v, n = Leb128.Decode.i64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string (-64L) v;
|
assert_equal ~printer:Int64.to_string (-64L) v;
|
||||||
assert_equal ~printer:string_of_int 1 n;
|
assert_equal ~printer:string_of_int 1 n;
|
||||||
|
|
@ -162,9 +161,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.i64 buf 64L;
|
Leb128.Encode.i64 buf 64L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.i64 slice 0 in
|
let v, n = Leb128.Decode.i64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string 64L v;
|
assert_equal ~printer:Int64.to_string 64L v;
|
||||||
assert_equal ~printer:string_of_int 2 n;
|
assert_equal ~printer:string_of_int 2 n;
|
||||||
|
|
@ -172,9 +171,9 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.i64 buf (-65L);
|
Leb128.Encode.i64 buf (-65L);
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v, n = Leb128.Decode.i64 slice 0 in
|
let v, n = Leb128.Decode.i64 slice 0 in
|
||||||
assert_equal ~printer:Int64.to_string (-65L) v;
|
assert_equal ~printer:Int64.to_string (-65L) v;
|
||||||
assert_equal ~printer:string_of_int 2 n;
|
assert_equal ~printer:string_of_int 2 n;
|
||||||
|
|
@ -182,19 +181,19 @@ true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.i64 buf 0L;
|
Leb128.Encode.i64 buf 0L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let skip = Leb128.Decode.skip slice 0 in
|
let skip = Leb128.Decode.skip slice 0 in
|
||||||
assert_equal ~printer:string_of_int 1 skip;
|
assert_equal ~printer:string_of_int 1 skip;
|
||||||
true
|
true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
let buf = Bb.create () in
|
let buf = Buf.create () in
|
||||||
Leb128.Encode.u64 buf 300L;
|
Leb128.Encode.u64 buf 300L;
|
||||||
Leb128.Encode.u64 buf 500L;
|
Leb128.Encode.u64 buf 500L;
|
||||||
let slice = Bb.to_slice buf in
|
let slice = Buf.to_slice buf in
|
||||||
let v1, n1 = Leb128.Decode.u64 slice 0 in
|
let v1, n1 = Leb128.Decode.u64 slice 0 in
|
||||||
let v2, n2 = Leb128.Decode.u64 slice n1 in
|
let v2, n2 = Leb128.Decode.u64 slice n1 in
|
||||||
assert_equal ~printer:Int64.to_string 300L v1;
|
assert_equal ~printer:Int64.to_string 300L v1;
|
||||||
|
|
@ -202,3 +201,5 @@ assert_equal ~printer:Int64.to_string 500L v2;
|
||||||
assert_equal ~printer:string_of_int 2 n1;
|
assert_equal ~printer:string_of_int 2 n1;
|
||||||
assert_equal ~printer:string_of_int 2 n2;
|
assert_equal ~printer:string_of_int 2 n2;
|
||||||
true
|
true
|
||||||
|
|
||||||
|
let () = Containers_testlib.run_all ~descr:"test leb128" [ get () ]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue