Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion pkg/deppy/solver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// A successful execution of the solver can still end in an error when no solution can
// be found.
type Solution struct {
err deppy.NotSatisfiable
err error
selection map[deppy.Identifier]deppy.Variable
variables []deppy.Variable
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/deppy/solver/solver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var _ = Describe("Entity", func() {
so := solver.NewDeppySolver(s, s)
solution, err := so.Solve(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(solution.Error()).ToNot(HaveOccurred())
Expect(solution.SelectedVariables()).To(MatchAllKeys(Keys{
deppy.Identifier("1"): Equal(input.NewSimpleVariable("1", constraint.Mandatory())),
deppy.Identifier("2"): Equal(input.NewSimpleVariable("2", constraint.Mandatory())),
Expand All @@ -86,12 +87,30 @@ var _ = Describe("Entity", func() {
so := solver.NewDeppySolver(s, s)
solution, err := so.Solve(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(solution.Error()).ToNot(HaveOccurred())
Expect(solution.SelectedVariables()).To(MatchAllKeys(Keys{
deppy.Identifier("1"): Equal(input.NewSimpleVariable("1", constraint.Mandatory(), constraint.Dependency("2"))),
deppy.Identifier("2"): Equal(input.NewSimpleVariable("2")),
}))
})

It("should return untyped nil error from solution.Error() when there is a solution", func() {
variables := []deppy.Variable{
input.NewSimpleVariable("1", constraint.Mandatory()),
}
s := NewEntitySource(variables)
so := solver.NewDeppySolver(s, s)
solution, err := so.Solve(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(solution).ToNot(BeNil())

// Using this style for the assertion to ensure that gomega
// doesn't equate nil errors of different types.
if err := solution.Error(); err != nil {
Fail(fmt.Sprintf("expected solution.Error() to be untyped nil, got %#v", solution.Error()))
}
})

It("should place resolution errors in the solution", func() {
variables := []deppy.Variable{
input.NewSimpleVariable("1", constraint.Mandatory(), constraint.Dependency("2")),
Expand Down Expand Up @@ -123,6 +142,7 @@ var _ = Describe("Entity", func() {
so := solver.NewDeppySolver(s, s)
solution, err := so.Solve(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(solution.Error()).ToNot(HaveOccurred())
Expect(solution.SelectedVariables()).To(MatchAllKeys(Keys{
deppy.Identifier("1"): Equal(input.NewSimpleVariable("1", constraint.Mandatory(), constraint.Dependency("2"))),
deppy.Identifier("2"): Equal(input.NewSimpleVariable("2")),
Expand All @@ -139,6 +159,7 @@ var _ = Describe("Entity", func() {
so := solver.NewDeppySolver(s, s)
solution, err := so.Solve(context.Background(), solver.AddAllVariablesToSolution())
Expect(err).ToNot(HaveOccurred())
Expect(solution.Error()).ToNot(HaveOccurred())
Expect(solution.AllVariables()).To(Equal([]deppy.Variable{
input.NewSimpleVariable("1", constraint.Mandatory(), constraint.Dependency("2")),
input.NewSimpleVariable("2"),
Expand All @@ -157,6 +178,7 @@ var _ = Describe("Entity", func() {
so := solver.NewDeppySolver(s, s)
solution, err := so.Solve(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(solution.Error()).ToNot(HaveOccurred())
Expect(solution.SelectedVariables()).To(MatchAllKeys(Keys{
deppy.Identifier("2"): Equal(input.NewSimpleVariable("2", constraint.Dependency("4"))),
deppy.Identifier("4"): Equal(input.NewSimpleVariable("4")),
Expand All @@ -174,6 +196,7 @@ var _ = Describe("Entity", func() {
so := solver.NewDeppySolver(s, s)
solution, err := so.Solve(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(solution.Error()).ToNot(HaveOccurred())
Expect(solution.SelectedVariables()).To(MatchAllKeys(Keys{
deppy.Identifier("2"): Equal(input.NewSimpleVariable("2", constraint.Dependency("3"))),
deppy.Identifier("3"): Equal(input.NewSimpleVariable("3", constraint.AtMost(1, "3", "4"))),
Expand All @@ -193,6 +216,7 @@ var _ = Describe("Entity", func() {
so := solver.NewDeppySolver(s, s)
solution, err := so.Solve(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(solution.Error()).ToNot(HaveOccurred())
Expect(solution.SelectedVariables()).To(MatchAllKeys(Keys{
deppy.Identifier("2"): Equal(input.NewSimpleVariable("2", constraint.Dependency("4"), constraint.Dependency("5"))),
deppy.Identifier("4"): Equal(input.NewSimpleVariable("4", constraint.Dependency("6"))),
Expand Down