From d8a1e2f9b1fb221ca60c9e768c7815b7da38abd5 Mon Sep 17 00:00:00 2001 From: Felix Dilke Date: Mon, 26 Jan 2026 12:25:44 +0000 Subject: [PATCH] simplifying tests --- .../test/Test/Datalog/NaiveDatabaseSpec.hs | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs b/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs index f59ee66..79dadf0 100644 --- a/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs +++ b/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs @@ -41,6 +41,22 @@ spec = do , "parent(\"bob\", \"carol\")." ] [ "ancestor(X,Y) :- parent(X,Y)." , "ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y)." ] + let parentRelation = Relation { + _name = "parent", + _arity = 2, + _tuples = Set.fromList [ + [Var "X",Var "Z"] + ], + _rules = [] + } + let ancestorRelation = Relation { + _name = "ancestor", + _arity = 2, + _tuples = Set.fromList [ + [Var "Z",Var "Y"] + ], + _rules = [] + } constants db `shouldBe` (Set.fromList $ Sym <$> ["alice", "bob", "carol"]) relations db `shouldBe` @@ -57,26 +73,12 @@ spec = do headVariables = [ "X", "Y", "Z" ], body = [ ( - Relation { - _name = "parent", - _arity = 2, - _tuples = Set.fromList [ - [Var "X",Var "Z" ] - ], - _rules = [] - }, [ + parentRelation, [ RuleElementVariable "X", RuleElementVariable "Z" ] ),( - Relation { - _name = "ancestor", - _arity = 2, - _tuples = Set.fromList [ - [Var "Z",Var "Y"] - ], - _rules = [] - },[ + ancestorRelation,[ RuleElementVariable "Z", RuleElementVariable "Y" ] @@ -86,16 +88,7 @@ spec = do ] } ), - ("parent", - Relation { - _name = "parent", - _arity = 2, - _tuples = Set.fromList [ - [Var "X",Var "Z"] - ], - _rules = [] - } - ) + ("parent", parentRelation ) ] it "can do basic queries" $ do