diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-25 21:51:33 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-25 21:51:33 -0300 |
| commit | 584fbca6d920e9a9f91d451667f9380714ac2175 (patch) | |
| tree | a163b916a6f8cb550c8b38ceb01ab01558687a40 /test | |
| parent | c7b754e96714eeeb9d315ee3de402d73a27d47db (diff) | |
| download | RNT-584fbca6d920e9a9f91d451667f9380714ac2175.tar.gz RNT-584fbca6d920e9a9f91d451667f9380714ac2175.zip | |
dune fmt
Diffstat (limited to 'test')
| -rw-r--r-- | test/Helpers.ml | 14 | ||||
| -rw-r--r-- | test/integration/Registration.ml | 14 | ||||
| -rw-r--r-- | test/unit/backend/Storage.ml | 8 | ||||
| -rw-r--r-- | test/unit/concepts/Cardinality.ml | 1 | ||||
| -rw-r--r-- | test/unit/evaluators/FOL.ml | 15 | ||||
| -rw-r--r-- | test/unit/evaluators/Lambda.ml | 39 | ||||
| -rw-r--r-- | test/unit/kernel/EphemeralRelation.ml | 36 | ||||
| -rw-r--r-- | test/unit/kernel/Merkle.ml | 60 | ||||
| -rw-r--r-- | test/unit/kernel/SubstantialRelation.ml | 12 |
9 files changed, 98 insertions, 101 deletions
diff --git a/test/Helpers.ml b/test/Helpers.ml index e859932..42cf8a5 100644 --- a/test/Helpers.ml +++ b/test/Helpers.ml @@ -34,17 +34,17 @@ module Storage = struct module SI = Kernel.Storage.Make (S) let store_schema tx attributes = - Concepts.Encoding.Bencode.(Dict (List.map (fun a -> (a, String "string")) attributes) |> to_blob) + Concepts.Encoding.Bencode.(Dict (List.map (fun a -> a, String "string") attributes) |> to_blob) |> SI.store_blob tx let with_connection f dir () = with_temporary_directory dir begin fun dir -> - begin - let open Utilities.Result in - let* conn = S.connect (C.configure dir) in - Ok (Fun.protect ~finally:(fun () -> S.disconnect conn) (fun () -> f conn)) - end - |> condition_as_failure + begin + let open Utilities.Result in + let* conn = S.connect (C.configure dir) in + Ok (Fun.protect ~finally:(fun () -> S.disconnect conn) (fun () -> f conn)) + end + |> condition_as_failure end end end diff --git a/test/integration/Registration.ml b/test/integration/Registration.ml index daecc22..9ac26f4 100644 --- a/test/integration/Registration.ml +++ b/test/integration/Registration.ml @@ -2,7 +2,6 @@ open Rnt module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = struct open Alcotest - module H = Helpers.Storage.Make (S) (C) module I = Kernel.Initialization.Make (S) module B = Kernel.Branch.Make (S) @@ -14,13 +13,18 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = let* root = I.initialize ~evaluators:["fol", Evaluators.FOL.make ()] conn in let* multigroup = M.make conn in let* branch = B.make conn in - let* branch' = Kernel.Path.(assoc branch ("multigroup" @/ this) "library" (Some multigroup)) in + let* branch' = + Kernel.Path.(assoc branch ("multigroup" @/ this) "library" (Some multigroup)) + in Kernel.Path.(update root ("branch" @/ this) "master" None (Some branch')) end - |> Helpers.condition_as_failure |> ignore; + |> Helpers.condition_as_failure + |> ignore; begin let* root = I.initialize ~evaluators:["fol", Evaluators.FOL.make ()] conn in - let* _ = Kernel.Path.(lookup root ("branch" @/ "master" @/ "multigroup" @/ "library" @/ this)) in + let* _ = + Kernel.Path.(lookup root ("branch" @/ "master" @/ "multigroup" @/ "library" @/ this)) + in let* _ = Kernel.Path.(lookup root ("evaluator" @/ "fol" @/ this)) in Ok () end @@ -28,7 +32,7 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = let suite prefix = ( "registration/" ^ prefix, - [test_case "registration tests" `Quick (H.with_connection run "registration-test")]) + [test_case "registration tests" `Quick (H.with_connection run "registration-test")] ) end module LMDB = Make (Rnt.Backend.Storage.LMDB) (Helpers.Storage.LMDB_Configurator) diff --git a/test/unit/backend/Storage.ml b/test/unit/backend/Storage.ml index a6765bf..b7a5a65 100644 --- a/test/unit/backend/Storage.ml +++ b/test/unit/backend/Storage.ml @@ -2,11 +2,12 @@ open Rnt module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = struct open Alcotest - module H = Helpers.Storage.Make (S) (C) let storage_and_retrieval conn = - let key = Concepts.Value.String "value" |> Concepts.Encoding.blob_of_value |> Concepts.Hash.hash_of_blob in + let key = + Concepts.Value.String "value" |> Concepts.Encoding.blob_of_value |> Concepts.Hash.hash_of_blob + in let value = Concepts.Value.Integer 42 in let blob = Concepts.Encoding.blob_of_value value in let v, v' = @@ -26,7 +27,8 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = let suite prefix = ( "storage/" ^ prefix, - [test_case "storage-and-retrieval" `Quick (H.with_connection storage_and_retrieval "storage-test")] ) + [ test_case "storage-and-retrieval" `Quick + (H.with_connection storage_and_retrieval "storage-test") ] ) end module LMDB = Make (Rnt.Backend.Storage.LMDB) (Helpers.Storage.LMDB_Configurator) diff --git a/test/unit/concepts/Cardinality.ml b/test/unit/concepts/Cardinality.ml index a60c472..b77e12c 100644 --- a/test/unit/concepts/Cardinality.ml +++ b/test/unit/concepts/Cardinality.ml @@ -1,5 +1,4 @@ open Alcotest - module C = Rnt.Concepts.Cardinality let klass = testable (fun ppf c -> Format.pp_print_string ppf (C.to_string c)) C.equal diff --git a/test/unit/evaluators/FOL.ml b/test/unit/evaluators/FOL.ml index 9cfeb84..404e7a4 100644 --- a/test/unit/evaluators/FOL.ml +++ b/test/unit/evaluators/FOL.ml @@ -2,15 +2,13 @@ open Rnt module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = struct open Alcotest - module H = Helpers.Storage.Make (S) (C) module SR = Rnt.Kernel.SubstantialRelation.Make (S) let alaric = - { Concepts.Tuple.type_ = "employee"; - attributes = - BatMap.String.empty - |> BatMap.String.add "name" (Concepts.Value.String "Alaric") } + { Concepts.Tuple.type_= "employee"; + attributes= BatMap.String.empty |> BatMap.String.add "name" (Concepts.Value.String "Alaric") + } let not_a_directory () = Concepts.Condition.condition "not-a-directory" @@ -41,8 +39,7 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = let* found = Protocols.Directory.find directory "fol" in let* evaluator = Option.to_result ~none:(not_a_program ()) found in let* interpreter = - Rnt.Evaluators.FOL.Program.from evaluator - |> Option.to_result ~none:(not_a_program ()) + Rnt.Evaluators.FOL.Program.from evaluator |> Option.to_result ~none:(not_a_program ()) in let* cursor = Rnt.Evaluators.FOL.Program.invoke interpreter (Rnt.Evaluators.FOL.Base employee) @@ -58,8 +55,8 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = check bool "the tuple that was asserted" true (List.for_all (fun tuple -> - Concepts.Hash.hash_equals (Concepts.Tuple.hash tuple) (Concepts.Tuple.hash alaric)) - scanned) + Concepts.Hash.hash_equals (Concepts.Tuple.hash tuple) (Concepts.Tuple.hash alaric) ) + scanned ) let suite prefix = ( "fol/" ^ prefix, diff --git a/test/unit/evaluators/Lambda.ml b/test/unit/evaluators/Lambda.ml index 5866411..ee15c16 100644 --- a/test/unit/evaluators/Lambda.ml +++ b/test/unit/evaluators/Lambda.ml @@ -2,21 +2,18 @@ open Rnt module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = struct open Alcotest - module H = Helpers.Storage.Make (S) (C) module SR = Rnt.Kernel.SubstantialRelation.Make (S) let datum = - { Concepts.Tuple.type_ = "noun"; - attributes = - BatMap.String.empty - |> BatMap.String.add "lemma" (Concepts.Value.String "datum") } + { Concepts.Tuple.type_= "noun"; + attributes= BatMap.String.empty |> BatMap.String.add "lemma" (Concepts.Value.String "datum") + } let reticulare = - { Concepts.Tuple.type_ = "verb"; - attributes = - BatMap.String.empty - |> BatMap.String.add "lemma" (Concepts.Value.String "rēticulāre") } + { Concepts.Tuple.type_= "verb"; + attributes= + BatMap.String.empty |> BatMap.String.add "lemma" (Concepts.Value.String "rēticulāre") } let not_a_directory () = Concepts.Condition.condition "not-a-directory" @@ -48,18 +45,13 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = [ Kernel.Prototype.Directory.of_properties ["noun", noun; "verb", verb; "lambda", Rnt.Evaluators.Lambda.make ()] ] in - let* directory = - Protocols.Directory.from root |> Option.to_result ~none:(not_a_directory ()) - in + let* directory = Protocols.Directory.from root |> Option.to_result ~none:(not_a_directory ()) in let* found = Protocols.Directory.find directory "lambda" in let* evaluator = Option.to_result ~none:(not_a_program ()) found in let* interpreter = - Rnt.Evaluators.Lambda.Program.from evaluator - |> Option.to_result ~none:(not_a_program ()) - in - let* cursor = - Rnt.Evaluators.Lambda.(Program.invoke interpreter (Program (term, directory))) + Rnt.Evaluators.Lambda.Program.from evaluator |> Option.to_result ~none:(not_a_program ()) in + let* cursor = Rnt.Evaluators.Lambda.(Program.invoke interpreter (Program (term, directory))) in let* scan = Protocols.Cursor.require cursor in let* tuples = Protocols.Cursor.drain scan () in Protocols.Handle.release cursor; @@ -81,8 +73,7 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = let identity_applied_to_a_relation conn = let open Rnt.Evaluators.Lambda in let scanned = - evaluate conn (Apply (Abstract ("x", Name "x"), Name "noun")) - |> Helpers.condition_as_failure + evaluate conn (Apply (Abstract ("x", Name "x"), Name "noun")) |> Helpers.condition_as_failure in check int "one tuple scanned" 1 (List.length scanned); check bool "the tuple that was asserted" true (List.for_all (is datum) scanned) @@ -94,8 +85,8 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = let scanned = evaluate conn (Apply - ( Apply (Abstract ("x", Abstract ("y", Name "x")), Name "noun"), - Abstract ("z", Name "z") )) + (Apply (Abstract ("x", Abstract ("y", Name "x")), Name "noun"), Abstract ("z", Name "z")) + ) |> Helpers.condition_as_failure in check int "one tuple scanned" 1 (List.length scanned); @@ -124,9 +115,9 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = let open Rnt.Evaluators.Lambda in match evaluate conn (Abstract ("x", Name "x")) with | Error condition -> - check bool "unapplied abstraction" true - (String.starts_with ~prefix:"unapplied-abstraction" - (Concepts.Condition.to_string_hum condition)) + check bool "unapplied abstraction" true + (String.starts_with ~prefix:"unapplied-abstraction" + (Concepts.Condition.to_string_hum condition) ) | Ok _ -> fail "an abstraction was enumerated" let suite prefix = diff --git a/test/unit/kernel/EphemeralRelation.ml b/test/unit/kernel/EphemeralRelation.ml index a72409b..f75fd0d 100644 --- a/test/unit/kernel/EphemeralRelation.ml +++ b/test/unit/kernel/EphemeralRelation.ml @@ -1,5 +1,4 @@ open Alcotest - module Concepts = Rnt.Concepts module Protocols = Rnt.Protocols @@ -14,8 +13,8 @@ module Derivation = struct let describe _ = Ok (BatMap.String.singleton "value" - { Protocols.Schematics.domain = "integer"; - provenance = [{Protocols.Schematics.source = ["example"]; attribute = "value"}] } ) + { Protocols.Schematics.domain= "integer"; + provenance= [{Protocols.Schematics.source= ["example"]; attribute= "value"}] } ) let modes {declared; _} = Ok declared @@ -31,13 +30,13 @@ end module Derived = Rnt.Kernel.EphemeralRelation.Make (Derivation) let member n = - { Concepts.Tuple.type_ = "example"; - attributes = BatMap.String.singleton "value" (Concepts.Value.Integer n) } + { Concepts.Tuple.type_= "example"; + attributes= BatMap.String.singleton "value" (Concepts.Value.Integer n) } let plan_over cardinality = - { Derivation.name = "the-derivation"; - members = [member 1; member 2; member 3]; - declared = + { Derivation.name= "the-derivation"; + members= [member 1; member 2; member 3]; + declared= Concepts.Mode.of_list [Concepts.Mode.enumerable cardinality; Concepts.Mode.decides_when ["value"]] } @@ -46,9 +45,9 @@ let derive plan = Derived.derive plan |> Helpers.condition_as_failure let values tuples = BatFingerTree.to_list tuples |> List.filter_map (fun tuple -> - match BatMap.String.find_opt "value" tuple.Concepts.Tuple.attributes with - | Some (Concepts.Value.Integer n) -> Some n - | _ -> None ) + match BatMap.String.find_opt "value" tuple.Concepts.Tuple.attributes with + | Some (Concepts.Value.Integer n) -> Some n + | _ -> None ) |> List.sort compare let commit = Concepts.Hash.hash_of_bytes (Bytes.of_string "a-commit") @@ -92,8 +91,7 @@ let a_countable_derivation_decides_only () = end |> Helpers.condition_as_failure in - check bool "no enumeration is offered" false - (Option.is_some (Protocols.Enumerable.from derived)); + check bool "no enumeration is offered" false (Option.is_some (Protocols.Enumerable.from derived)); check bool "membership is still decided" true holds; check bool "and still refused" false rejects @@ -115,10 +113,11 @@ let a_derivation_describes_itself () = ( BatMap.String.values description |> BatList.of_enum |> List.concat_map (fun attribute -> - attribute.Protocols.Schematics.provenance - |> List.map (fun origin -> - String.concat "/" origin.Protocols.Schematics.source - ^ "/" ^ origin.Protocols.Schematics.attribute ) ) ) + attribute.Protocols.Schematics.provenance + |> List.map (fun origin -> + String.concat "/" origin.Protocols.Schematics.source + ^ "/" + ^ origin.Protocols.Schematics.attribute ) ) ) | _ -> fail "a derived relation describes itself as a relation" let releasing_a_derivation_releases_its_inputs () = @@ -143,8 +142,7 @@ let releasing_a_derivation_releases_its_inputs () = let suites () = [ ( "kernel/ephemeral-relation", [ test_case "identity-is-the-derivation" `Quick identity_is_the_derivation; - test_case "an-exhaustible-derivation-enumerates" `Quick - an_exhaustible_derivation_enumerates; + test_case "an-exhaustible-derivation-enumerates" `Quick an_exhaustible_derivation_enumerates; test_case "a-countable-derivation-decides-only" `Quick a_countable_derivation_decides_only; test_case "a-derivation-describes-itself" `Quick a_derivation_describes_itself; test_case "releasing-a-derivation-releases-its-inputs" `Quick diff --git a/test/unit/kernel/Merkle.ml b/test/unit/kernel/Merkle.ml index 85c756c..eaff92d 100644 --- a/test/unit/kernel/Merkle.ml +++ b/test/unit/kernel/Merkle.ml @@ -2,9 +2,10 @@ open Rnt module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = struct open Alcotest - module H = Helpers.Storage.Make (S) (C) - module T = Rnt.Kernel.Merkle.Interface (S) (Rnt.Kernel.Merkle.StringKey) (Rnt.Kernel.Merkle.StringKey) + + module T = + Rnt.Kernel.Merkle.Interface (S) (Rnt.Kernel.Merkle.StringKey) (Rnt.Kernel.Merkle.StringKey) (* TODO: be a bit more comprehensive (ideally, we want to test splits as well) *) let insert_and_lookup conn = @@ -12,10 +13,11 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = begin let open Utilities.Result in let* tx = S.start conn in - let* node = T.empty - |> T.insert tx "k1" "v1" - |> fmap (T.insert tx "k2" "v2") - |> fmap (T.insert tx "k3" "v3") + let* node = + T.empty + |> T.insert tx "k1" "v1" + |> fmap (T.insert tx "k2" "v2") + |> fmap (T.insert tx "k3" "v3") in let* node' = T.insert tx "k3" "toodles" node in let* v1 = T.lookup tx "k1" node in @@ -31,7 +33,8 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = check (option string) "that in-memory reads from the first write work properly" (Some "v1") v1; check (option string) "that in-memory reads from the second write work properly" (Some "v2") v2; check (option string) "that in-memory reads from the third write work properly" (Some "v3") v3; - check (option string) "that in-memory reads from a value replacement work properly" (Some "toodles") v3'; + check (option string) "that in-memory reads from a value replacement work properly" + (Some "toodles") v3'; check (option string) "that in-memory reads from a non-existent key returns nothing" None bogus let batching conn = @@ -40,10 +43,12 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = let open Utilities.Result in let* tx = S.start conn in let intermediate = ref None in - let* final = T.with_batch tx (fun () -> - let* i = T.empty |> T.insert tx "tree" "maple" in - intermediate := Some (T.hash_of i); - T.insert tx "tree" "spruce" i) in + let* final = + T.with_batch tx (fun () -> + let* i = T.empty |> T.insert tx "tree" "maple" in + intermediate := Some (T.hash_of i); + T.insert tx "tree" "spruce" i ) + in let* () = S.commit tx in Ok (Option.get !intermediate, T.hash_of final) end @@ -62,16 +67,16 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = check bool "that the intermediate node does not get persisted" true (Option.is_none i_node); check bool "that the final node does get persisted" true (Option.is_some f_node) - let persistence conn = let addr = begin let open Utilities.Result in let* tx = S.start conn in - let* node = T.empty - |> T.insert tx "k1" "v1" - |> fmap (T.insert tx "k2" "v2") - |> fmap (T.insert tx "k3" "v3") + let* node = + T.empty + |> T.insert tx "k1" "v1" + |> fmap (T.insert tx "k2" "v2") + |> fmap (T.insert tx "k3" "v3") in let* () = S.commit tx in Ok (T.hash_of node) @@ -99,10 +104,11 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = begin let open Utilities.Result in let* tx = S.start conn in - let* node = T.empty - |> T.insert tx "k1" "v1" - |> fmap (T.insert tx "k2" "v2") - |> fmap (T.insert tx "k3" "v3") + let* node = + T.empty + |> T.insert tx "k1" "v1" + |> fmap (T.insert tx "k2" "v2") + |> fmap (T.insert tx "k3" "v3") in let* keys = T.fold_left tx (fun acc k _ -> k :: acc) [] node |> Result.map List.rev in let* values = T.fold_left tx (fun acc _ v -> v :: acc) [] node |> Result.map List.rev in @@ -111,8 +117,10 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = end |> Helpers.condition_as_failure in - check (list string) "that keys are properly enumerated from left to right" ["k1"; "k2"; "k3"] keys; - check (list string) "that values are properly enumerated from left to right" ["v1"; "v2"; "v3"] values + check (list string) "that keys are properly enumerated from left to right" ["k1"; "k2"; "k3"] + keys; + check (list string) "that values are properly enumerated from left to right" ["v1"; "v2"; "v3"] + values (* TODO: this will need `remove` *) (* let determinism _conn = *) @@ -120,10 +128,10 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = let suite prefix = ( "merkle/" ^ prefix, - [test_case "insert-and-lookup" `Quick (H.with_connection insert_and_lookup "merkle-test"); - test_case "batching" `Quick (H.with_connection batching "merkle-test"); - test_case "persistence" `Quick (H.with_connection persistence "merkle-test"); - test_case "iteration" `Quick (H.with_connection iteration "merkle-test")]) + [ test_case "insert-and-lookup" `Quick (H.with_connection insert_and_lookup "merkle-test"); + test_case "batching" `Quick (H.with_connection batching "merkle-test"); + test_case "persistence" `Quick (H.with_connection persistence "merkle-test"); + test_case "iteration" `Quick (H.with_connection iteration "merkle-test") ] ) end module LMDB = Make (Rnt.Backend.Storage.LMDB) (Helpers.Storage.LMDB_Configurator) diff --git a/test/unit/kernel/SubstantialRelation.ml b/test/unit/kernel/SubstantialRelation.ml index f639599..db13026 100644 --- a/test/unit/kernel/SubstantialRelation.ml +++ b/test/unit/kernel/SubstantialRelation.ml @@ -2,16 +2,14 @@ open Rnt module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = struct open Alcotest - module H = Helpers.Storage.Make (S) (C) module SR = Rnt.Kernel.SubstantialRelation.Make (S) - let hash s = - Concepts.Blob.blob_of_bytes (Bytes.of_string s) |> Concepts.Hash.hash_of_blob + let hash s = Concepts.Blob.blob_of_bytes (Bytes.of_string s) |> Concepts.Hash.hash_of_blob let alaric = - { Concepts.Tuple.type_ = "employee"; - attributes = + { Concepts.Tuple.type_= "employee"; + attributes= BatMap.String.empty |> BatMap.String.add "name" (Concepts.Value.String "Alaric") |> BatMap.String.add "age" (Concepts.Value.Integer 42) } @@ -40,8 +38,8 @@ module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = check bool "the tuple that was asserted" true (List.for_all (fun tuple -> - Concepts.Hash.hash_equals (Concepts.Tuple.hash tuple) (Concepts.Tuple.hash alaric)) - enumerated) + Concepts.Hash.hash_equals (Concepts.Tuple.hash tuple) (Concepts.Tuple.hash alaric) ) + enumerated ) let suite prefix = ( "substantial-relation/" ^ prefix, |
