Skip to content

[64.1] StrategyExtensions: add C# 14 extension properties for int, string, and IList<T> #124

@kommundsen

Description

@kommundsen

Part of #64.

Dependencies

Implement

File: src/Conjecture.Core/StrategyExtensions.cs — append C# 14 extension blocks:

extension(Strategy<int> s)
{
    public Strategy<int> Positive => s.Where(x => x > 0);
    public Strategy<int> Negative => s.Where(x => x < 0);
    public Strategy<int> NonZero  => s.Where(x => x != 0);
}

extension(Strategy<string> s)
{
    public Strategy<string> NonEmpty => s.Where(x => x.Length > 0);
}

extension(Strategy<IList<T>> s)
{
    public Strategy<IList<T>> NonEmpty => s.Where(x => x.Count > 0);
}

Add XML doc comments to each property noting the filter-budget caveat: for tight value ranges, prefer a targeted strategy (e.g. Generate.Integers(1, 100)) over chaining .Where().

Update src/Conjecture.Core/PublicAPI.Unshipped.txt with the new public symbols.

Test

File: src/Conjecture.Core.Tests/StrategyExtensionsTests.cs — new test class ExtensionPropertyTests:

  • Positive_ReturnsOnlyPositiveIntegers
  • Negative_ReturnsOnlyNegativeIntegers
  • NonZero_NeverReturnsZero
  • String_NonEmpty_NeverReturnsEmptyString
  • List_NonEmpty_NeverReturnsEmptyList
  • ExtensionProperties_ComposeWithSelectAndZip — verify chaining with other combinators works

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions