Skip to content

Strengthen sortBy/maxBy/minBy tests with two distinct projections - #248

Merged
gdziadkiewicz merged 2 commits into
repo-assist/improve-nonemptylist-and-seq-tests-8fbc6ac826d39964from
copilot/sub-pr-229
Mar 14, 2026
Merged

Strengthen sortBy/maxBy/minBy tests with two distinct projections#248
gdziadkiewicz merged 2 commits into
repo-assist/improve-nonemptylist-and-seq-tests-8fbc6ac826d39964from
copilot/sub-pr-229

Conversation

Copilot AI commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Tests for sortBy, maxBy, and minBy were using id as the projection, which can't detect bugs where the projection is silently ignored (e.g., sortBy behaving as sort).

Each function now has two property-based tests using opposite projections:

// identity projection — ascending order / max / min
NonEmptyList.sortBy id nel = List.sortBy id list
NonEmptyList.maxBy id nel = List.max list
NonEmptyList.minBy id nel = List.min list

// negation projection — descending order / min / max
NonEmptyList.sortBy (fun x -> -x) nel = List.sortBy (fun x -> -x) list
NonEmptyList.maxBy (fun x -> -x) nel = List.min list   // projection flips comparison
NonEmptyList.minBy (fun x -> -x) nel = List.max list

The negation projection verifies the projection is genuinely applied, since a correct maxBy (fun x -> -x) must return the minimum element.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: gdziadkiewicz <8547855+gdziadkiewicz@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on NonEmptyList functions and tests Strengthen sortBy/maxBy/minBy tests with two distinct projections Mar 14, 2026
Copilot AI requested a review from gdziadkiewicz March 14, 2026 12:05
@gdziadkiewicz
gdziadkiewicz marked this pull request as ready for review March 14, 2026 12:26
@gdziadkiewicz
gdziadkiewicz merged commit 91d7a00 into repo-assist/improve-nonemptylist-and-seq-tests-8fbc6ac826d39964 Mar 14, 2026
@gdziadkiewicz
gdziadkiewicz deleted the copilot/sub-pr-229 branch March 14, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants