Skip to content

Add an inline Distinct test where only Distinct separates the symbols - #121

Open
HowardvanRooijen wants to merge 1 commit into
mainfrom
test/theorem-smoke-gaps
Open

HowardvanRooijen wants to merge 1 commit into
mainfrom
test/theorem-smoke-gaps

Conversation

@HowardvanRooijen

Copy link
Copy Markdown
Member

Summary

This PR adds one test to DistinctInlineArrayTheoremTests.cs. The test comes from a review of the external PR #111.

The new test is Distinct_InlineSymbolsFreeInASharedRange_ForcesThemApart. The two symbols have the same range of two values, and no constraint sets their values. Only Z3Methods.Distinct keeps the two values different.

The existing satisfiable test, Distinct_InlineDistinctSymbols_Solves, sets the two symbols to different values. Thus, that test passes without Distinct. The new test fails without Distinct.

The test obeys the determinism rule of the suite. Two models satisfy the theorem: (0, 1) and (1, 0). Thus, the test checks only that the values are different and in the range. It does not check which model Z3 gives.

Why this PR does not add the other tests from #111

PR #111 adds 10 tests in a new file, BasicTheoremTests.cs. The suite on main already has tests for these behaviors. The links go to commit 964f177.

Tests that have almost the same test on main

Test in #111 Test on main Comparison
Optimize_Maximize_ReturnsUpperBound OptimizationTests.cs:42 Optimize_Maximize_ReturnsTheLargestSatisfyingValue Range 5 to 9. Maximize. The result is 9.
Optimize_Minimize_ReturnsLowerBound OptimizationTests.cs:214 Optimize_MinimizingIsNotJustTheFirstSatisfyingModel The same range (5 to 100) and the same result (5). This test also does a check of the maximum.
Solve_ContradictoryConstraints_ReturnsNull UnsatisfiabilityTests.cs:122 TrySolve_UnsatisfiableReferenceTypeTheorem_ReturnsFalse The same contradiction in one && (X1 > 4 && X1 < 2).
TheoremSolveTests.cs:51 Solve_UnsatisfiableTheorem_ReturnsNull The same contradiction in two where clauses. Solve() gives null.
Solve_ChainedWhereClauses_Conjoin OptimizationTests.cs:237 Optimize_CalledTwiceOnTheSameTheorem_LeavesItReusable The same shape: .Where(>= 1).Where(<= 4).Solve(), then ShouldBeInRange(1, 4).
TheoremCompositionTests.cs:65 Where_OriginalTheorem_RemainsIndependentlySolvable A stronger test. A second Where that contradicts the first Where gives null. The test in #111 passes also if the code does not use the second Where.
NewTheorem_DummyOverload_SolvesLikeParameterless TheoremCompositionTests.cs:168 NewTheorem_WithATemplateInstance_InfersTheEnvironmentType An anonymous template with fixed values. The test in #111 does not compare the result with the parameterless overload.

Tests that a set of tests on main covers

Test in #111 Tests on main What each test covers
Solve_IntTheorem_ReturnsModelInRange DistinctSelectorTheoremTests.cs:30 Distinct_SelectorProducingDistinctTerms_Solves An open integer range (X1 > 10 && X1 < 14) with ShouldBeInRange(11, 13).
TheoremCompositionTests.cs:168 NewTheorem_WithATemplateInstance_InfersTheEnvironmentType An anonymous type with query syntax.
Solve_TupleTheorem_ReadsBackEverySymbol EnvironmentTypeTests.cs:290 Solve_ValueTupleWithDouble_PopulatesEveryField and :309 Solve_ValueTupleWithString_PopulatesEveryField The solution gives the values of the value tuple fields.
TheoremSolveTests.cs:196 Solve_LinearSystemWithForcedDifference_ForcesTheSameValuesInEveryModel A check of a relation between two symbols. No constraint sets the value of one symbol.
Solve_BoolTheorem_SatisfiesProposition TheoremSolveTests.cs:67 Solve_ContradictoryBooleanTheorem_ReturnsNull A Boolean symbol in an anonymous type, with && and !.
EnvironmentTypeTests.cs:93 Solve_AnonymousTypeEnvironment_PopulatesEveryProperty The solution gives the value true for a Boolean property of an anonymous type.
EnvironmentTypeTests.cs:326 Solve_RecordEnvironment_PopulatesEveryProperty The constraints X and !Y give true and false. This test uses a record.
Solve_Distinct_ForcesDifferentValues DistinctInlineArrayTheoremTests.cs:25 Distinct_InlineDistinctSymbols_Solves A satisfiable inline Distinct.
DistinctInlineArrayTheoremTests.cs:42 Distinct_InlineSymbolsConstrainedEqual_IsUnsatisfiable Distinct together with X1 == X2 gives null.
The new test in this PR Distinct is the only constraint that keeps the two values different.
Optimize_Minimize_OverTupleObjective_Solves OptimizationTests.cs:185 Optimize_LinearProgramOverDoubles_FindsTheKnownOptimum orderby minimizes an objective of two fields (20.0 * t.sa + 15.0 * t.vz) on a (double sa, double vz) tuple.
OptimizationTests.cs:82 OrderBy_ProducesTheSameResultAsMinimize orderby gives the same result as Optimize(Optimization.Minimize, ...).
OptimizationTests.cs:164 Optimize_ObjectiveOverSeveralSymbols_MinimizesTheirCombination Optimize minimizes X1 + X2. The test checks only the sum.

The tuple test in #111 uses int fields. The test at OptimizationTests.cs:185 uses double fields. The two types use the same code for the objective and the tuple. Thus, an int version adds no coverage.

Test results

  • dotnet build solutions/Z3.Linq.slnx: 0 warnings, 0 errors.
  • Without Distinct, the new test fails. Z3 gives the same value to X1 and X2.
  • With Distinct, all tests pass: 369 passed, 0 failed.

🤖 Generated with Claude Code

The existing satisfiable inline test sets the two symbols to different
values, so it passes without Distinct. In the new test, the two symbols
have the same range of two values. Only Distinct keeps them different.

The test comes from a review of #111. The other tests in #111 duplicate
tests that are already in the suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 11:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the added model-independent regression coverage of inline Z3Methods.Distinct.

No open issues 🎉

What changed in this PR

Adds focused regression coverage for inline Z3Methods.Distinct, complementing existing tests with a case where neither symbol is fixed to a particular value.

Changes:

  • Adds a test with two integer symbols sharing the range [0, 1], where only Distinct requires different values.
  • Checks non-null results, inequality, and range membership without depending on which satisfying model Z3 returns.
File Description
solutions/​Z3.Linq.Tests/​DistinctInlineArrayTheoremTests.cs Adds a model-independent test of Distinct over two symbols sharing a range.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Code Coverage Summary Report - Linux (No TFM)

Summary
Generated on: 11/05/2026 - 11:32:00
Parser: Cobertura
Assemblies: 2
Classes: 19
Files: 16
Line coverage: 91.3% (887 of 971)
Covered lines: 887
Uncovered lines: 84
Coverable lines: 971
Total lines: 2958
Branch coverage: 80.5% (619 of 768)
Covered branches: 619
Total branches: 768
Method coverage: Feature is only available for sponsors

Coverage

Z3.Linq - 93.6%
Name Line Branch
Z3.Linq 93.6% 81.5%
Z3.Linq.Environment 100%
Z3.Linq.ExpressionVisitor 95.1% 81.5%
Z3.Linq.SolveableExtensions 100% 100%
Z3.Linq.Symbols 100% 66.6%
Z3.Linq.Theorem 92.2% 80.7%
Z3.Linq.Theorem.DeferredSolvable 100%
Z3.Linq.Theorem.TypeMappingEntry 100%
Z3.Linq.Theorem<T, TResult> 92.2% 80.7%
Z3.Linq.Theorem 100%
Z3.Linq.TheoremGlobalRewriterAttribute 100%
Z3.Linq.TheoremPredicateRewriterAttribute 100%
Z3.Linq.TheoremUndecidedException 100%
Z3.Linq.TheoremVariableTypeMappingAttribute 100%
Z3.Linq.Z3Context 100% 100%
Z3.Linq.Z3Methods 100%
Z3.Linq.Examples - 70.7%
Name Line Branch
Z3.Linq.Examples 70.7% 50%
Z3.Linq.Examples.RiverCrossing.MissionariesAndCannibals 87.5% 66.6%
Z3.Linq.Examples.Sudoku.SudokuTable 0% 0%
Z3.Linq.Examples.Sudoku.SudokuTheorem 100% 100%
Z3.Linq.Examples.Sudoku.SudokuTheoremRewriter 100%

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Test Results

  1 files  ±0    1 suites  ±0   11s ⏱️ -2s
348 tests +1  348 ✅ +1  0 💤 ±0  0 ❌ ±0 
369 runs  +1  369 ✅ +1  0 💤 ±0  0 ❌ ±0 

Results for commit 95893a2. ± Comparison against base commit 964f177.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants