Skip to content

Commit

Permalink
Split NumericAssertionSpecs
Browse files Browse the repository at this point in the history
  • Loading branch information
vbreuss committed Nov 1, 2023
1 parent bd2a041 commit 0779a9f
Show file tree
Hide file tree
Showing 13 changed files with 4,075 additions and 3,968 deletions.
537 changes: 537 additions & 0 deletions Tests/FluentAssertions.Specs/Numeric/NumericAssertionSpecs.Be.cs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1,479 changes: 1,479 additions & 0 deletions Tests/FluentAssertions.Specs/Numeric/NumericAssertionSpecs.BeCloseTo.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using Xunit;
using Xunit.Sdk;

namespace FluentAssertions.Specs.Numeric;

public partial class NumericAssertionSpecs
{
public class BeGreaterThan
{
[Fact]
public void When_a_value_is_greater_than_smaller_value_it_should_not_throw()
{
// Arrange
int value = 2;
int smallerValue = 1;

// Act
Action act = () => value.Should().BeGreaterThan(smallerValue);

// Assert
act.Should().NotThrow();
}

[Fact]
public void When_a_value_is_greater_than_greater_value_it_should_throw()
{
// Arrange
int value = 2;
int greaterValue = 3;

// Act
Action act = () => value.Should().BeGreaterThan(greaterValue);

// Assert
act.Should().Throw<XunitException>();
}

[Fact]
public void When_a_value_is_greater_than_same_value_it_should_throw()
{
// Arrange
int value = 2;
int sameValue = 2;

// Act
Action act = () => value.Should().BeGreaterThan(sameValue);

// Assert
act.Should().Throw<XunitException>();
}

[Fact]
public void When_a_value_is_greater_than_greater_value_it_should_throw_with_descriptive_message()
{
// Arrange
int value = 2;
int greaterValue = 3;

// Act
Action act = () =>
value.Should().BeGreaterThan(greaterValue, "because we want to test the failure {0}", "message");

// Assert
act
.Should().Throw<XunitException>()
.WithMessage("Expected value to be greater than 3 because we want to test the failure message, but found 2.");
}

[Fact]
public void NaN_is_never_greater_than_another_float()
{
// Act
Action act = () => float.NaN.Should().BeGreaterThan(0);

// Assert
act
.Should().Throw<XunitException>()
.WithMessage("*NaN*");
}

[Fact]
public void A_float_cannot_be_greater_than_NaN()
{
// Act
Action act = () => 3.4F.Should().BeGreaterThan(float.NaN);

// Assert
act
.Should().Throw<ArgumentException>()
.WithMessage("*NaN*");
}

[Fact]
public void NaN_is_never_greater_than_another_double()
{
// Act
Action act = () => double.NaN.Should().BeGreaterThan(0);

// Assert
act
.Should().Throw<XunitException>()
.WithMessage("*NaN*");
}

[Fact]
public void A_double_can_never_be_greater_than_NaN()
{
// Act
Action act = () => 3.4D.Should().BeGreaterThan(double.NaN);

// Assert
act
.Should().Throw<ArgumentException>()
.WithMessage("*NaN*");
}

[Fact]
public void When_a_nullable_numeric_null_value_is_not_greater_than_it_should_throw()
{
// Arrange
int? value = null;

// Act
Action act = () => value.Should().BeGreaterThan(0);

// Assert
act
.Should().Throw<XunitException>()
.WithMessage("*null*");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System;
using Xunit;
using Xunit.Sdk;

namespace FluentAssertions.Specs.Numeric;

public partial class NumericAssertionSpecs
{
public class BeGreaterThanOrEqualTo
{
[Fact]
public void When_a_value_is_greater_than_or_equal_to_smaller_value_it_should_not_throw()
{
// Arrange
int value = 2;
int smallerValue = 1;

// Act
Action act = () => value.Should().BeGreaterThanOrEqualTo(smallerValue);

// Assert
act.Should().NotThrow();
}

[Fact]
public void When_a_value_is_greater_than_or_equal_to_same_value_it_should_not_throw()
{
// Arrange
int value = 2;
int sameValue = 2;

// Act
Action act = () => value.Should().BeGreaterThanOrEqualTo(sameValue);

// Assert
act.Should().NotThrow();
}

[Fact]
public void When_a_value_is_greater_than_or_equal_to_greater_value_it_should_throw()
{
// Arrange
int value = 2;
int greaterValue = 3;

// Act
Action act = () => value.Should().BeGreaterThanOrEqualTo(greaterValue);

// Assert
act.Should().Throw<XunitException>();
}

[Fact]
public void When_a_value_is_greater_than_or_equal_to_greater_value_it_should_throw_with_descriptive_message()
{
// Arrange
int value = 2;
int greaterValue = 3;

// Act
Action act =
() => value.Should()
.BeGreaterThanOrEqualTo(greaterValue, "because we want to test the failure {0}", "message");

// Assert
act
.Should().Throw<XunitException>()
.WithMessage(
"Expected value to be greater than or equal to 3 because we want to test the failure message, but found 2.");
}

[Fact]
public void When_a_nullable_numeric_null_value_is_not_greater_than_or_equal_to_it_should_throw()
{
// Arrange
int? value = null;

// Act
Action act = () => value.Should().BeGreaterThanOrEqualTo(0);

// Assert
act
.Should().Throw<XunitException>()
.WithMessage("*null*");
}

[Fact]
public void NaN_is_never_greater_than_or_equal_to_another_float()
{
// Act
Action act = () => float.NaN.Should().BeGreaterThanOrEqualTo(0);

// Assert
act
.Should().Throw<XunitException>()
.WithMessage("*NaN*");
}

[Fact]
public void A_float_cannot_be_greater_than_or_equal_to_NaN()
{
// Act
Action act = () => 3.4F.Should().BeGreaterThanOrEqualTo(float.NaN);

// Assert
act
.Should().Throw<ArgumentException>()
.WithMessage("*NaN*");
}

[Fact]
public void NaN_is_never_greater_or_equal_to_another_double()
{
// Act
Action act = () => double.NaN.Should().BeGreaterThanOrEqualTo(0);

// Assert
act
.Should().Throw<XunitException>()
.WithMessage("*NaN*");
}

[Fact]
public void A_double_can_never_be_greater_or_equal_to_NaN()
{
// Act
Action act = () => 3.4D.Should().BeGreaterThanOrEqualTo(double.NaN);

// Assert
act
.Should().Throw<ArgumentException>()
.WithMessage("*NaN*");
}

[Fact]
public void Chaining_after_one_assertion()
{
// Arrange
int value = 2;
int smallerValue = 1;

// Act / Assert
value.Should().BeGreaterThanOrEqualTo(smallerValue).And.Be(2);
}
}
}

0 comments on commit 0779a9f

Please sign in to comment.