Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
(synopsis "A library for fold functions")
(description "A library for fold functions")
(depends
(alcotest :with-test)
(bisect_ppx :with-test)
(core_kernel (and (>= v0.14) (< v0.15)))
(dune :build)
Expand Down
1 change: 1 addition & 0 deletions fold_lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license: "MIT"
homepage: "https://github.com/o1labs/snarky"
bug-reports: "https://github.com/o1labs/snarky/issues"
depends: [
"alcotest" {with-test}
"bisect_ppx" {with-test}
"core_kernel" {>= "v0.14" & < "v0.15"}
"dune" {>= "3.0" & build}
Expand Down
2 changes: 0 additions & 2 deletions fold_lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
(name fold_lib)
(public_name fold_lib)
(library_flags -linkall)
(inline_tests
(flags -verbose -show-counts))
(libraries core_kernel)
(preprocess
(pps ppx_jane ppx_deriving.eq bisect_ppx -- --conditional))
Expand Down
21 changes: 0 additions & 21 deletions fold_lib/fold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ let of_list (xs : 'a list) : 'a t =
let of_array (xs : 'a array) : 'a t =
{ fold = (fun ~init ~f -> Array.fold xs ~init ~f) }

let%test_unit "fold-to-list" =
Quickcheck.test (Quickcheck.Generator.list Int.quickcheck_generator)
~f:(fun xs -> assert ([%equal: Int.t list] xs (to_list (of_list xs))))

let sexp_of_t f t = List.sexp_of_t f (to_list t)

let compose (t1 : 'a t) (t2 : 'a t) : 'a t =
Expand Down Expand Up @@ -85,23 +81,6 @@ let group3 ~default (t : 'a t) : ('a * 'a * 'a) t =
assert false )
}

let%test_unit "group3" =
Quickcheck.test (Quickcheck.Generator.list Int.quickcheck_generator)
~f:(fun xs ->
let default = 0 in
let n = List.length xs in
let tuples = to_list (group3 ~default (of_list xs)) in
let k = List.length tuples in
let r = n mod 3 in
(let padded =
xs @ if r = 0 then [] else List.init (3 - r) ~f:(fun _ -> default)
in
let concated =
List.concat_map ~f:(fun (b1, b2, b3) -> [ b1; b2; b3 ]) tuples
in
[%test_eq: int list] padded concated ) ;
assert ((n + 2) / 3 = k) )

let string_bits s =
let ith_bit_int n i = (n lsr i) land 1 = 1 in
{ fold =
Expand Down
6 changes: 6 additions & 0 deletions fold_lib/test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(test
(name test_fold_lib)
(package fold_lib)
(libraries alcotest core_kernel fold_lib)
(preprocess
(pps ppx_jane)))
35 changes: 35 additions & 0 deletions fold_lib/test/test_fold_lib.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
open Core_kernel
open Alcotest
open Fold_lib

let int_list = list int

let test_fold_to_list () =
Quickcheck.test (Quickcheck.Generator.list Int.quickcheck_generator)
~f:(fun xs ->
let result = Fold.to_list (Fold.of_list xs) in
Alcotest.(check int_list) "fold-to-list" xs result )

let test_group3 () =
Quickcheck.test (Quickcheck.Generator.list Int.quickcheck_generator)
~f:(fun xs ->
let default = 0 in
let n = List.length xs in
let tuples = Fold.to_list (Fold.group3 ~default (Fold.of_list xs)) in
let k = List.length tuples in
let r = n mod 3 in
let padded =
xs @ if r = 0 then [] else List.init (3 - r) ~f:(fun _ -> default)
in
let concated =
List.concat_map ~f:(fun (b1, b2, b3) -> [ b1; b2; b3 ]) tuples
in
Alcotest.(check int_list) "group3 padded equals concated" padded concated ;
Alcotest.(check int) "group3 length" ((n + 2) / 3) k )

let fold_tests =
[ ("fold-to-list", `Quick, test_fold_to_list)
; ("group3", `Quick, test_group3)
]

let () = Alcotest.run "Fold_lib" [ ("fold", fold_tests) ]