Skip to content

Commit

Permalink
Merge pull request #21 from mbarbin/reduce-deps
Browse files Browse the repository at this point in the history
Reduce dependencies
  • Loading branch information
mbarbin authored Dec 28, 2024
2 parents c4b19ee + bd87891 commit 248d765
Show file tree
Hide file tree
Showing 35 changed files with 198 additions and 184 deletions.
1 change: 0 additions & 1 deletion bopkit-tests.opam
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ depends: [
"cmdliner" {>= "1.3.0"}
"comments-parser" {>= "0.2.2"}
"core" {>= "v0.17" & < "v0.18"}
"core_unix" {>= "v0.17" & < "v0.18"}
"dune-site" {>= "3.17"}
"expect_test_helpers_core" {>= "v0.17" & < "v0.18"}
"fpath" {>= "0.7.3"}
Expand Down
2 changes: 0 additions & 2 deletions bopkit.opam
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ depends: [
"cmdliner" {>= "1.3.0"}
"comments-parser" {>= "0.2.2"}
"core" {>= "v0.17" & < "v0.18"}
"core_kernel" {>= "v0.17" & < "v0.18"}
"core_unix" {>= "v0.17" & < "v0.18"}
"dune-site" {>= "3.17"}
"fpath" {>= "0.7.3"}
"fpath-base" {>= "0.2.2"}
Expand Down
20 changes: 0 additions & 20 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@
(and
(>= v0.17)
(< v0.18)))
(core_kernel
(and
(>= v0.17)
(< v0.18)))
(core_unix
(and
(>= v0.17)
(< v0.18)))
(dune-site
(>= 3.17))
(fpath
Expand Down Expand Up @@ -174,10 +166,6 @@
(and
(>= v0.17)
(< v0.18)))
(core_unix
(and
(>= v0.17)
(< v0.18)))
(dune-site
(>= 3.17))
(fpath
Expand Down Expand Up @@ -277,10 +265,6 @@
(and
(>= v0.17)
(< v0.18)))
(core_unix
(and
(>= v0.17)
(< v0.18)))
(dune-site
(>= 3.17))
(fpath
Expand Down Expand Up @@ -386,10 +370,6 @@
(and
(>= v0.17)
(< v0.18)))
(core_unix
(and
(>= v0.17)
(< v0.18)))
(dune-site
(>= 3.17))
(expect_test_helpers_core
Expand Down
22 changes: 17 additions & 5 deletions lib/bit_utils/test/dune
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
(library
(name bit_utils_test)
(public_name bopkit-tests.bit_utils_test)
(flags :standard -w +a-4-40-41-42-44-45-48-66 -warn-error +a -open Core)
(flags
:standard
-w
+a-4-40-41-42-44-45-48-66
-warn-error
+a
-open
Base
-open
Stdio
-open
Expect_test_helpers_base)
(libraries
base
bit_utils
core
core_unix
core_unix.filename_unix
expect_test_helpers_core
fpath)
expect_test_helpers_core.expect_test_helpers_base
fpath
stdio
unix)
(inline_tests)
(lint
(pps ppx_js_style -check-doc-comments))
Expand Down
14 changes: 7 additions & 7 deletions lib/bit_utils/test/test__bit_array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let%expect_test "to_string" =
[%expect {||}];
test [| true; false |];
[%expect {| 10 |}];
test (Array.init 10 ~f:(fun i -> i mod 2 = 0));
test (Array.init 10 ~f:(fun i -> i % 2 = 0));
[%expect {| 1010101010 |}]
;;

Expand All @@ -43,7 +43,7 @@ let%expect_test "to_string roundtrip" =

let%expect_test "text files" =
let test t =
let path = Filename_unix.temp_file "test__bit_array" "text" |> Fpath.v in
let path = Stdlib.Filename.temp_file "test__bit_array" "text" |> Fpath.v in
Bit_array.to_text_file t ~path;
let contents = In_channel.read_all (path |> Fpath.to_string) in
let t2 = Bit_array.of_text_file ~path in
Expand All @@ -55,13 +55,13 @@ let%expect_test "text files" =
raise_s
[%sexp "String contents not equal", { contents : string; contents2 : string }];
print_endline contents;
Core_unix.unlink (path |> Fpath.to_string)
Unix.unlink (path |> Fpath.to_string)
in
test [||];
[%expect {||}];
test [| true; true; false |];
[%expect {| 110 |}];
test (Array.init 64 ~f:(fun i -> i mod 2 = 1));
test (Array.init 64 ~f:(fun i -> i % 2 = 1));
[%expect {| 0101010101010101010101010101010101010101010101010101010101010101 |}];
()
;;
Expand All @@ -88,7 +88,7 @@ let%expect_test "to_signed_int / to_int" =
~f:(fun t ->
let len = Array.length t in
let modulo = Int.pow 2 len in
let is_negative = len > 0 && t.(pred len) in
let is_negative = len > 0 && t.(Int.pred len) in
let signed_int = Bit_array.to_signed_int t in
let int = Bit_array.to_int t in
let expected_signed_int = if is_negative then int - modulo else int in
Expand All @@ -108,7 +108,7 @@ let%expect_test "sequence" =
let j = Bit_array.to_int t in
if i <> j then raise_s [%sexp "Unexpected int", { t : Bit_array.t; i : int; j : int }];
let signed = Bit_array.to_signed_int t in
Printf.printf "%s | %02d | %02d\n" (Bit_array.to_string t) i signed
print_endline (Printf.sprintf "%s | %02d | %02d" (Bit_array.to_string t) i signed)
done;
[%expect
{|
Expand Down Expand Up @@ -161,7 +161,7 @@ let%expect_test "blit_init" =
(* Check that [f] is called from left to right. *)
assert (i = !last + 1);
last := i;
i mod 2 = 0);
i % 2 = 0);
print_endline (Bit_array.to_string t);
[%expect {| 1010101010 |}]
;;
2 changes: 1 addition & 1 deletion lib/bit_utils/test/test__bit_counter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let%expect_test "counter" =
;;

let%expect_test "counter" =
let t = Array.init 10 ~f:(fun i -> i mod 2 = 1) in
let t = Array.init 10 ~f:(fun i -> i % 2 = 1) in
let bit_counter = Bit_counter.create ~len:2 in
for _ = 0 to 9 do
Bit_counter.blit_next_value bit_counter ~dst:t ~dst_pos:5;
Expand Down
27 changes: 16 additions & 11 deletions lib/bit_utils/test/test__bit_matrix.ml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
let%expect_test "init" =
let test t = print_s [%sexp (t : Bit_matrix.t)] in
test (Bit_matrix.init_matrix_linear ~dimx:0 ~dimy:0 ~f:(const false));
test (Bit_matrix.init_matrix_linear ~dimx:0 ~dimy:0 ~f:(Fn.const false));
[%expect {| () |}];
test (Bit_matrix.init_matrix_linear ~dimx:0 ~dimy:3 ~f:(const false));
test (Bit_matrix.init_matrix_linear ~dimx:0 ~dimy:3 ~f:(Fn.const false));
[%expect {| () |}];
test (Bit_matrix.init_matrix_linear ~dimx:3 ~dimy:0 ~f:(const false));
[%expect {| (() () ()) |}];
let t = Bit_matrix.init_matrix_linear ~dimx:3 ~dimy:5 ~f:(fun i -> i mod 2 = 1) in
test (Bit_matrix.init_matrix_linear ~dimx:3 ~dimy:0 ~f:(Fn.const false));
[%expect
{|
(()
()
())
|}];
let t = Bit_matrix.init_matrix_linear ~dimx:3 ~dimy:5 ~f:(fun i -> i % 2 = 1) in
Bit_matrix.to_text_channel t stdout;
[%expect
{|
Expand All @@ -16,7 +21,7 @@ let%expect_test "init" =
;;

let%expect_test "of_bit_array" =
let bit_array = Array.init 24 ~f:(fun i -> i mod 2 = 1) in
let bit_array = Array.init 24 ~f:(fun i -> i % 2 = 1) in
let test t = Bit_matrix.to_text_channel t stdout in
(* Shorter than input *)
test (Bit_matrix.of_bit_array ~dimx:2 ~dimy:6 bit_array);
Expand All @@ -42,11 +47,11 @@ let%expect_test "of_bit_array" =
;;

let%expect_test "of_text_file" =
let path = Filename_unix.temp_file "test__bit_matrix" "text" |> Fpath.v in
let path = Stdlib.Filename.temp_file "test__bit_matrix" "text" |> Fpath.v in
Out_channel.with_file (path |> Fpath.to_string) ~f:(fun oc ->
Printf.fprintf oc "// Hello comment\n";
Printf.fprintf oc "010101010101\n";
Printf.fprintf oc "011111111110\n");
Out_channel.output_string oc "// Hello comment\n";
Out_channel.output_string oc "010101010101\n";
Out_channel.output_string oc "011111111110\n");
let test ~dimx ~dimy =
let t = Bit_matrix.of_text_file ~dimx ~dimy ~path in
Bit_matrix.to_text_channel t stdout
Expand All @@ -69,6 +74,6 @@ let%expect_test "of_text_file" =
0101
0101
0111 |}];
Core_unix.unlink (path |> Fpath.to_string);
Unix.unlink (path |> Fpath.to_string);
()
;;
7 changes: 5 additions & 2 deletions lib/bit_utils/test/test__bit_string_encoding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ let%expect_test "T encoding" =
print_s [%sexp { t : T.t; char : Char.t }]);
[%expect
{|
((t false) (char 0))
((t true) (char 1)) |}]
((t false)
(char 0))
((t true)
(char 1))
|}]
;;

let%expect_test "T_opt encoding" =
Expand Down
19 changes: 13 additions & 6 deletions lib/bit_utils/test/test__partial_bit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ end
let%expect_test "conflicts" =
List.iter T_opt.all ~f:(fun t_opt ->
List.iter T.all ~f:(fun t ->
Printf.printf
"%c conflicts with:%c => %b\n"
(Bit_string_encoding.Bit_option.to_char t_opt)
(Bit_string_encoding.Bit.to_char t)
(Partial_bit.conflicts t_opt ~with_:t)));
print_endline
(Printf.sprintf
"%c conflicts with:%c => %b\n"
(Bit_string_encoding.Bit_option.to_char t_opt)
(Bit_string_encoding.Bit.to_char t)
(Partial_bit.conflicts t_opt ~with_:t))));
[%expect
{|
* conflicts with:0 => false

* conflicts with:1 => false

0 conflicts with:0 => false

0 conflicts with:1 => true

1 conflicts with:0 => true
1 conflicts with:1 => false |}]

1 conflicts with:1 => false
|}]
;;
42 changes: 33 additions & 9 deletions lib/bit_utils/test/test__partial_bit_array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,37 @@ let%expect_test "of_01star_chars_in_string" =
test "";
[%expect {| () |}];
test "010";
[%expect {| ((false) (true) (false)) |}];
[%expect
{|
((false)
(true)
(false))
|}];
test "010\n";
[%expect {| ((false) (true) (false)) |}];
[%expect
{|
((false)
(true)
(false))
|}];
test "//010 and some other characters followed by 11";
[%expect {| ((false) (true) (false) (true) (true)) |}];
[%expect
{|
((false)
(true)
(false)
(true)
(true))
|}];
test "*010*\n";
[%expect {| (() (false) (true) (false) ()) |}]
[%expect
{|
(()
(false)
(true)
(false)
())
|}]
;;

let%expect_test "to_string" =
Expand All @@ -21,7 +45,7 @@ let%expect_test "to_string" =
[%expect {||}];
test [| Some true; Some false; None |];
[%expect {| 10* |}];
test (Array.init 10 ~f:(fun i -> if i mod 2 = 0 then Some (i mod 3 = 0) else None));
test (Array.init 10 ~f:(fun i -> if i % 2 = 0 then Some (i % 3 = 0) else None));
[%expect {| 1*0*0*1*0* |}]
;;

Expand All @@ -44,7 +68,7 @@ let%expect_test "to_string roundtrip" =

let%expect_test "text files" =
let test t =
let path = Filename_unix.temp_file "test__bit_array" "text" |> Fpath.v in
let path = Stdlib.Filename.temp_file "test__bit_array" "text" |> Fpath.v in
Partial_bit_array.to_text_file t ~path;
let contents = In_channel.read_all (path |> Fpath.to_string) in
let t2 = Partial_bit_array.of_text_file ~path in
Expand All @@ -60,13 +84,13 @@ let%expect_test "text files" =
raise_s
[%sexp "String contents not equal", { contents : string; contents2 : string }];
print_endline contents;
Core_unix.unlink (path |> Fpath.to_string)
Unix.unlink (path |> Fpath.to_string)
in
test [||];
[%expect {||}];
test [| Some true; Some true; None; Some false |];
[%expect {| 11*0 |}];
test (Array.init 64 ~f:(fun i -> if i mod 7 = 1 then None else Some (i mod 3 = 1)));
test (Array.init 64 ~f:(fun i -> if i % 7 = 1 then None else Some (i % 3 = 1)));
[%expect {| 0*001001*010010*100100*001001*010010*100100*001001*010010*100100 |}];
()
;;
Expand All @@ -78,7 +102,7 @@ let%expect_test "conflicts" =
(Partial_bit_array.of_01star_chars_in_string a)
~with_:(Bit_array.of_01_chars_in_string b)
in
Printf.printf "%S conflicts with:%S => %b\n" a b conflicts
print_endline (Printf.sprintf "%S conflicts with:%S => %b\n" a b conflicts)
in
test "" "";
[%expect {| "" conflicts with:"" => false |}];
Expand Down
12 changes: 6 additions & 6 deletions lib/bit_utils/test/test__partial_bit_matrix.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let%expect_test "of_partial_bit_array" =
let partial_bit_array =
Array.init 24 ~f:(fun i -> if i mod 5 = 1 then None else Some (i mod 2 = 1))
Array.init 24 ~f:(fun i -> if i % 5 = 1 then None else Some (i % 2 = 1))
in
let test t = Partial_bit_matrix.to_text_channel t stdout in
(* Shorter than input *)
Expand All @@ -27,11 +27,11 @@ let%expect_test "of_partial_bit_array" =
;;

let%expect_test "of_text_file" =
let path = Filename_unix.temp_file "test__bit_matrix" "text" |> Fpath.v in
let path = Stdlib.Filename.temp_file "test__bit_matrix" "text" |> Fpath.v in
Out_channel.with_file (path |> Fpath.to_string) ~f:(fun oc ->
Printf.fprintf oc "// Hello comment\n";
Printf.fprintf oc "010*010*01*1\n";
Printf.fprintf oc "0**111*11110\n");
Out_channel.output_string oc "// Hello comment\n";
Out_channel.output_string oc "010*010*01*1\n";
Out_channel.output_string oc "0**111*11110\n");
let test ~dimx ~dimy =
let t = Partial_bit_matrix.of_text_file ~dimx ~dimy ~path in
Partial_bit_matrix.to_text_channel t stdout
Expand All @@ -54,6 +54,6 @@ let%expect_test "of_text_file" =
010*
01*1
0**1 |}];
Core_unix.unlink (path |> Fpath.to_string);
Unix.unlink (path |> Fpath.to_string);
()
;;
Loading

0 comments on commit 248d765

Please sign in to comment.