Skip to content

Extend BooleanAssertions with Implies #1886

@marcrocny

Description

@marcrocny

Description

Add logical implication to the available boolean assertions.

That is, a.Should().Imply(b) asserts that a → b.

This would be useful in asserting, for example, that object equality implies hash-code equality without additional logic and a better built-in "because".

Complete minimal example

Looking for something like this.

[DataTestMethod]
[DataRow(false, false)]
[DataRow(false, true)]
// failure case: [DataRow(true, false)]
[DataRow(true, true)]
public void A_Implies_B(bool a, bool b) => a.Should().Imply(b);

Note this is logically equivalent to !a || b.

Additional Information

Also volunteering to add this.

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved, it can be implemented

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions