Skip to content

Commit

Permalink
Parametrizes solver test
Browse files Browse the repository at this point in the history
  • Loading branch information
brunolange committed Nov 10, 2023
1 parent d8047d4 commit b4ee03e
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,19 @@ def test_deep_build():
assert results["c"] == "c"


def test_solvers():
@pytest.mark.parametrize("solver", ["linear", "bfs", "bfs_parallel", "async"])
def test_solver(solver):
def subtract(p, q):
return p - q

solvers = ["linear", "bfs", "bfs_parallel", "async"]
results = [
build(
{
"a": -11,
"b": 7.5,
"a - b": At("a", "b", subtract),
"b - a": At("b", "a", subtract),
},
solver=solver,
)
for solver in solvers
]

# make sure we have as many results as there are solvers
assert len(results) == len(solvers)

# serialize results and add them to set
# if results are the same, there should be only one element in the set
result_set = set(json.dumps(result, sort_keys=True) for result in results)
assert len(result_set) == 1
result = build(
{
"a": -11,
"b": 7.5,
"a - b": At("a", "b", subtract),
"b - a": At("b", "a", subtract),
},
solver=solver,
)

result = json.loads(next(iter(result_set)))
assert result["a - b"] == -18.5
assert result["b - a"] == 18.5
assert result == {"a": -11, "b": 7.5, "a - b": -18.5, "b - a": 18.5}

0 comments on commit b4ee03e

Please sign in to comment.