From 6a1186cd4d44767363cc1b75e4fb819b4f4d99ae Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Sun, 3 Jul 2016 16:46:18 -0700 Subject: [PATCH 1/4] Swap two test functions to match the order in the test suite --- .../Distribution/Solver/Modular/Solver.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs index c0bb1f442c6..1db73ac8802 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs @@ -885,15 +885,6 @@ dbBuildable1 = [ , Right $ exAv "flag2-false" 1 [] ] --- | Package databases for testing @pkg-config@ dependencies. -dbPC1 :: ExampleDb -dbPC1 = [ - Right $ exAv "A" 1 [ExPkg ("pkgA", 1)] - , Right $ exAv "B" 1 [ExPkg ("pkgB", 1), ExAny "A"] - , Right $ exAv "B" 2 [ExPkg ("pkgB", 2), ExAny "A"] - , Right $ exAv "C" 1 [ExAny "B"] - ] - -- | cabal must pick B-2 to avoid the unknown dependency. dbBuildable2 :: ExampleDb dbBuildable2 = [ @@ -906,6 +897,15 @@ dbBuildable2 = [ , Right $ exAv "B" 3 [ExAny "unknown"] ] +-- | Package databases for testing @pkg-config@ dependencies. +dbPC1 :: ExampleDb +dbPC1 = [ + Right $ exAv "A" 1 [ExPkg ("pkgA", 1)] + , Right $ exAv "B" 1 [ExPkg ("pkgB", 1), ExAny "A"] + , Right $ exAv "B" 2 [ExPkg ("pkgB", 2), ExAny "A"] + , Right $ exAv "C" 1 [ExAny "B"] + ] + {------------------------------------------------------------------------------- Simple databases for the illustrations for the backjumping blog post -------------------------------------------------------------------------------} From d5fa5deee796a215481ff67cc4647ba56a65e61c Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Sun, 3 Jul 2016 16:46:52 -0700 Subject: [PATCH 2/4] Specify solver goal order in unit test "indepGoals5" --- .../Distribution/Solver/Modular/Solver.hs | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs index 1db73ac8802..867c469a72d 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs @@ -137,7 +137,7 @@ tests = [ , runTest $ testIndepGoals2 "indepGoals2" , runTest $ testIndepGoals3 "indepGoals3" , runTest $ testIndepGoals4 "indepGoals4" - , runTest $ indep $ mkTest db23 "indepGoals5" ["X", "Y"] (SolverSuccess [("A", 1), ("A", 2), ("B", 1), ("C", 1), ("C", 2), ("X", 1), ("Y", 1)]) + , runTest $ testIndepGoals5 "indepGoals5" , runTest $ indep $ mkTest db24 "indepGoals6" ["X", "Y"] (SolverSuccess [("A", 1), ("A", 2), ("B", 1), ("B", 2), ("X", 1), ("Y", 1)]) ] -- Tests designed for the backjumping blog post @@ -804,18 +804,36 @@ db22 = [ -- be found, because without the SIR, linking is always optional, but never -- necessary. -- -db23 :: ExampleDb -db23 = [ - Right $ exAv "X" 1 [ExFix "C" 2, ExAny "A"] - , Right $ exAv "Y" 1 [ExFix "C" 1, ExFix "A" 2] - , Right $ exAv "A" 1 [] - , Right $ exAv "A" 2 [ExAny "B"] - , Right $ exAv "B" 1 [ExAny "C"] - , Right $ exAv "C" 1 [] - , Right $ exAv "C" 2 [] - ] +testIndepGoals5 :: String -> SolverTest +testIndepGoals5 name = + goalOrder goals $ indep $ + mkTest db name ["X", "Y"] $ + SolverSuccess [("A", 1), ("A", 2), ("B", 1), ("C", 1), ("C", 2), ("X", 1), ("Y", 1)] + where + db :: ExampleDb + db = [ + Right $ exAv "X" 1 [ExFix "C" 2, ExAny "A"] + , Right $ exAv "Y" 1 [ExFix "C" 1, ExFix "A" 2] + , Right $ exAv "A" 1 [] + , Right $ exAv "A" 2 [ExAny "B"] + , Right $ exAv "B" 1 [ExAny "C"] + , Right $ exAv "C" 1 [] + , Right $ exAv "C" 2 [] + ] + + goals :: [ExampleVar] + goals = [ + P (Indep 0) "X" + , P (Indep 0) "A" + , P (Indep 0) "B" + , P (Indep 0) "C" + , P (Indep 1) "Y" + , P (Indep 1) "A" + , P (Indep 1) "B" + , P (Indep 1) "C" + ] --- | A simplified version of 'db23'. +-- | A simplified version of 'testIndepGoals5'. db24 :: ExampleDb db24 = [ Right $ exAv "X" 1 [ExFix "B" 2, ExAny "A"] From 7cd312a518314fd4e71b17fcba2190599259efb7 Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Sun, 3 Jul 2016 16:47:16 -0700 Subject: [PATCH 3/4] Specify solver goal order in unit test "indepGoals6" --- .../Distribution/Solver/Modular/Solver.hs | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs index 867c469a72d..db96ca351d2 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs @@ -138,7 +138,7 @@ tests = [ , runTest $ testIndepGoals3 "indepGoals3" , runTest $ testIndepGoals4 "indepGoals4" , runTest $ testIndepGoals5 "indepGoals5" - , runTest $ indep $ mkTest db24 "indepGoals6" ["X", "Y"] (SolverSuccess [("A", 1), ("A", 2), ("B", 1), ("B", 2), ("X", 1), ("Y", 1)]) + , runTest $ testIndepGoals6 "indepGoals6" ] -- Tests designed for the backjumping blog post , testGroup "Backjumping" [ @@ -834,15 +834,31 @@ testIndepGoals5 name = ] -- | A simplified version of 'testIndepGoals5'. -db24 :: ExampleDb -db24 = [ - Right $ exAv "X" 1 [ExFix "B" 2, ExAny "A"] - , Right $ exAv "Y" 1 [ExFix "B" 1, ExFix "A" 2] - , Right $ exAv "A" 1 [] - , Right $ exAv "A" 2 [ExAny "B"] - , Right $ exAv "B" 1 [] - , Right $ exAv "B" 2 [] - ] +testIndepGoals6 :: String -> SolverTest +testIndepGoals6 name = + goalOrder goals $ indep $ + mkTest db name ["X", "Y"] $ + SolverSuccess [("A", 1), ("A", 2), ("B", 1), ("B", 2), ("X", 1), ("Y", 1)] + where + db :: ExampleDb + db = [ + Right $ exAv "X" 1 [ExFix "B" 2, ExAny "A"] + , Right $ exAv "Y" 1 [ExFix "B" 1, ExFix "A" 2] + , Right $ exAv "A" 1 [] + , Right $ exAv "A" 2 [ExAny "B"] + , Right $ exAv "B" 1 [] + , Right $ exAv "B" 2 [] + ] + + goals :: [ExampleVar] + goals = [ + P (Indep 0) "X" + , P (Indep 0) "A" + , P (Indep 0) "B" + , P (Indep 1) "Y" + , P (Indep 1) "A" + , P (Indep 1) "B" + ] dbExts1 :: ExampleDb dbExts1 = [ From 9d7ffb32234f4b51856573f62e840908d64669a2 Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Mon, 4 Jul 2016 10:36:40 -0700 Subject: [PATCH 4/4] Test default as well as fixed goal order --- .../Distribution/Solver/Modular/Solver.hs | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs index db96ca351d2..fcc6d350a70 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs @@ -137,8 +137,10 @@ tests = [ , runTest $ testIndepGoals2 "indepGoals2" , runTest $ testIndepGoals3 "indepGoals3" , runTest $ testIndepGoals4 "indepGoals4" - , runTest $ testIndepGoals5 "indepGoals5" - , runTest $ testIndepGoals6 "indepGoals6" + , runTest $ testIndepGoals5 "indepGoals5 - fixed goal order" FixedGoalOrder + , runTest $ testIndepGoals5 "indepGoals5 - default goal order" DefaultGoalOrder + , runTest $ testIndepGoals6 "indepGoals6 - fixed goal order" FixedGoalOrder + , runTest $ testIndepGoals6 "indepGoals6 - default goal order" DefaultGoalOrder ] -- Tests designed for the backjumping blog post , testGroup "Backjumping" [ @@ -169,6 +171,8 @@ indep test = test { testIndepGoals = IndependentGoals True } goalOrder :: [ExampleVar] -> SolverTest -> SolverTest goalOrder order test = test { testGoalOrder = Just order } +data GoalOrder = FixedGoalOrder | DefaultGoalOrder + {------------------------------------------------------------------------------- Solver tests -------------------------------------------------------------------------------} @@ -804,12 +808,17 @@ db22 = [ -- be found, because without the SIR, linking is always optional, but never -- necessary. -- -testIndepGoals5 :: String -> SolverTest -testIndepGoals5 name = - goalOrder goals $ indep $ - mkTest db name ["X", "Y"] $ - SolverSuccess [("A", 1), ("A", 2), ("B", 1), ("C", 1), ("C", 2), ("X", 1), ("Y", 1)] +testIndepGoals5 :: String -> GoalOrder -> SolverTest +testIndepGoals5 name fixGoalOrder = + case fixGoalOrder of + FixedGoalOrder -> goalOrder goals test + DefaultGoalOrder -> test where + test :: SolverTest + test = indep $ mkTest db name ["X", "Y"] $ + SolverSuccess + [("A", 1), ("A", 2), ("B", 1), ("C", 1), ("C", 2), ("X", 1), ("Y", 1)] + db :: ExampleDb db = [ Right $ exAv "X" 1 [ExFix "C" 2, ExAny "A"] @@ -834,12 +843,17 @@ testIndepGoals5 name = ] -- | A simplified version of 'testIndepGoals5'. -testIndepGoals6 :: String -> SolverTest -testIndepGoals6 name = - goalOrder goals $ indep $ - mkTest db name ["X", "Y"] $ - SolverSuccess [("A", 1), ("A", 2), ("B", 1), ("B", 2), ("X", 1), ("Y", 1)] +testIndepGoals6 :: String -> GoalOrder -> SolverTest +testIndepGoals6 name fixGoalOrder = + case fixGoalOrder of + FixedGoalOrder -> goalOrder goals test + DefaultGoalOrder -> test where + test :: SolverTest + test = indep $ mkTest db name ["X", "Y"] $ + SolverSuccess + [("A", 1), ("A", 2), ("B", 1), ("B", 2), ("X", 1), ("Y", 1)] + db :: ExampleDb db = [ Right $ exAv "X" 1 [ExFix "B" 2, ExAny "A"]