-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
253 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
profile = janestreet | ||
module-item-spacing=sparse | ||
version = 0.26.2 | ||
version = 0.27.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
(library | ||
(name year_2015) | ||
(libraries point_2d parse reader) | ||
(libraries knife point_2d parse reader) | ||
(modes melange native)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
(library | ||
(name year_2024) | ||
(libraries parse reader) | ||
(libraries knife parse reader) | ||
(modes melange native)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(test | ||
(name test_knife) | ||
(libraries alcotest knife)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
module List_suite = struct | ||
let test_indices name xs expected = | ||
let run () = | ||
Alcotest.(check (list int)) | ||
"are equal" | ||
expected | ||
(xs |> Knife.List.indices |> List.of_seq) | ||
in | ||
Alcotest.test_case name `Quick run | ||
;; | ||
|
||
let indices_suite = | ||
( "List.indices" | ||
, [ test_indices "empty list" [] [] | ||
; test_indices "non empty list" [ 1; 2; 3 ] [ 0; 1; 2 ] | ||
] ) | ||
;; | ||
|
||
let test_remove_at name index xs expected = | ||
let run () = | ||
Alcotest.(check (list int)) "are equal" expected (Knife.List.remove_at ~index xs) | ||
in | ||
Alcotest.test_case name `Quick run | ||
;; | ||
|
||
let remove_at_suite = | ||
( "List.remove_at" | ||
, [ test_remove_at "empty list" 10 [] [] | ||
; test_remove_at "out of range" 10 [ 1; 2; 3 ] [ 1; 2; 3 ] | ||
; test_remove_at "negative index" (-1) [ 1; 2; 3 ] [ 1; 2; 3 ] | ||
; test_remove_at "in range" 3 [ 0; 10; 20; 30; 40; 50 ] [ 0; 10; 20; 40; 50 ] | ||
] ) | ||
;; | ||
|
||
let suites = [ indices_suite; remove_at_suite ] | ||
end | ||
|
||
module Seq_suite = struct | ||
let test_exists name f s expected = | ||
let run () = Alcotest.(check bool) "are equal" expected (Knife.Seq.exists ~f s) in | ||
Alcotest.test_case name `Quick run | ||
;; | ||
|
||
let exists_suite = | ||
let s = Seq.ints 0 |> Seq.take 5 in | ||
( "Seq.exists" | ||
, [ test_exists "has no matched element" (Stdlib.( = ) 10) s false | ||
; test_exists "has matched element" (Stdlib.( = ) 3) s true | ||
; test_exists "has matched elements" (Stdlib.( > ) 3) s true | ||
] ) | ||
;; | ||
|
||
let test_indices name s expected = | ||
let run () = | ||
Alcotest.(check (list int)) | ||
"are equal" | ||
expected | ||
(s |> Knife.Seq.indices |> List.of_seq) | ||
in | ||
Alcotest.test_case name `Quick run | ||
;; | ||
|
||
let indices_suite = | ||
( "Seq.indices" | ||
, [ test_indices "empty sequence" Seq.empty [] | ||
; test_indices "non empty sequence" (Seq.ints 0 |> Seq.take 3) [ 0; 1; 2 ] | ||
] ) | ||
;; | ||
|
||
let test_sum name s expected = | ||
let run () = Alcotest.(check int) "are equal" expected (Knife.Seq.sum s) in | ||
Alcotest.test_case name `Quick run | ||
;; | ||
|
||
let sum_suite = | ||
( "Seq.sum" | ||
, [ test_sum "empty sequence" Seq.empty 0 | ||
; test_sum "non empty sequence" (Seq.ints 0 |> Seq.take 4) 6 | ||
] ) | ||
;; | ||
|
||
let test_pairs_of name s expected = | ||
let run () = | ||
Alcotest.(check (list (pair int int))) | ||
"are equal" | ||
expected | ||
(s |> Knife.Seq.pairs_of |> List.of_seq) | ||
in | ||
Alcotest.test_case name `Quick run | ||
;; | ||
|
||
let pairs_of_suite = | ||
( "Seq.pairs_of" | ||
, [ test_pairs_of "empty sequence" Seq.empty [] | ||
; test_pairs_of "single item sequence" (Seq.return 1) [] | ||
; test_pairs_of | ||
"multiple items sequence" | ||
(Seq.ints 0 |> Seq.take 5) | ||
[ 0, 1; 1, 2; 2, 3; 3, 4 ] | ||
] ) | ||
;; | ||
|
||
let test_triples_of name s expected = | ||
let run () = | ||
Alcotest.(check (list (triple int int int))) | ||
"are equal" | ||
expected | ||
(s |> Knife.Seq.triples_of |> List.of_seq) | ||
in | ||
Alcotest.test_case name `Quick run | ||
;; | ||
|
||
let triples_of_suite = | ||
( "Seq.triples_of" | ||
, [ test_triples_of "empty sequence" Seq.empty [] | ||
; test_triples_of "single item sequence" (Seq.return 1) [] | ||
; test_triples_of "double items sequence" (Seq.ints 0 |> Seq.take 2) [] | ||
; test_triples_of | ||
"multiple items sequence" | ||
(Seq.ints 0 |> Seq.take 5) | ||
[ 0, 1, 2; 1, 2, 3; 2, 3, 4 ] | ||
] ) | ||
;; | ||
|
||
let suites = | ||
[ exists_suite; indices_suite; sum_suite; pairs_of_suite; triples_of_suite ] | ||
;; | ||
end | ||
|
||
module String_suite = struct | ||
let test_indices name xs expected = | ||
let run () = | ||
Alcotest.(check (list int)) | ||
"are equal" | ||
expected | ||
(xs |> Knife.String.indices |> List.of_seq) | ||
in | ||
Alcotest.test_case name `Quick run | ||
;; | ||
|
||
let indices_suite = | ||
( "String.indices" | ||
, [ test_indices "empty string" "" [] | ||
; test_indices "non empty string" "abc" [ 0; 1; 2 ] | ||
] ) | ||
;; | ||
|
||
let suites = [ indices_suite ] | ||
end | ||
|
||
let () = | ||
let open Alcotest in | ||
run "Knife" (List_suite.suites @ Seq_suite.suites @ String_suite.suites) | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(library | ||
(name knife) | ||
(modes melange native)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module List = List | ||
module Seq = Seq | ||
module String = String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
type 'a t = 'a list | ||
|
||
let indices xs = Utils.indices_of Stdlib.List.length xs | ||
|
||
let remove_at ~index = | ||
let remove it _ = it <> index in | ||
Stdlib.List.filteri remove | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type 'a t = 'a list | ||
|
||
val indices : 'a list -> int Seq.t | ||
|
||
val remove_at : index:int -> 'a list -> 'a list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type 'a t = 'a Stdlib.Seq.t | ||
|
||
let exists ~f = Stdlib.Seq.exists f | ||
|
||
let indices s = Stdlib.Seq.mapi Utils.index s | ||
|
||
let sum = Stdlib.Seq.fold_left ( + ) 0 | ||
|
||
let pairs_of s = | ||
let open Stdlib.Seq in | ||
zip s (drop 1 s) | ||
;; | ||
|
||
let triples_of s = | ||
let open Stdlib.Seq in | ||
let triple_of (x, y) z = x, y, z in | ||
map2 triple_of (pairs_of s) (drop 2 s) | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type 'a t = 'a Stdlib.Seq.t | ||
|
||
val exists : f:('a -> bool) -> 'a t -> bool | ||
|
||
val indices : 'a t -> int t | ||
|
||
val sum : int t -> int | ||
|
||
val pairs_of : 'a t -> ('a * 'a) t | ||
|
||
val triples_of : 'a t -> ('a * 'a * 'a) t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type t = string | ||
|
||
let indices s = Utils.indices_of Stdlib.String.length s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type t = string | ||
|
||
val indices : t -> int Seq.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
let bool_of_option = function | ||
| Some _ -> true | ||
| None -> false | ||
;; | ||
|
||
let indices_of length_of xs = | ||
let open Stdlib.Seq in | ||
ints 0 |> take (length_of xs) | ||
;; | ||
|
||
let index index _ = index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
val bool_of_option : 'a option -> bool | ||
|
||
val indices_of : ('a -> int) -> 'a -> int Stdlib.Seq.t | ||
|
||
val index : int -> 'a -> int |