Skip to content

Commit

Permalink
SAVEPOINT
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Feb 23, 2022
1 parent 1fe9df7 commit 9935484
Showing 1 changed file with 146 additions and 7 deletions.
153 changes: 146 additions & 7 deletions Tests/FluentAssertions.Specs/Numeric/NumericAssertionSpecs.cs
Expand Up @@ -38,7 +38,7 @@ public void When_a_negative_value_is_positive_it_should_throw()
public void When_a_zero_value_is_positive_it_should_throw()
{
// Arrange
int value = 0;
double value = double.NaN;

// Act
Action act = () => value.Should().BePositive();
Expand All @@ -47,6 +47,32 @@ public void When_a_zero_value_is_positive_it_should_throw()
act.Should().Throw<XunitException>();
}

[Fact]
public void NaN_is_never_a_positive_float()
{
// Arrange
float value = float.NaN;

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

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

[Fact]
public void Nan_is_never_a_positive_double()
{
// Arrange
double value = double.NaN;

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

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

[Fact]
public void When_a_negative_value_is_positive_it_should_throw_with_descriptive_message()
{
Expand All @@ -62,6 +88,21 @@ public void When_a_negative_value_is_positive_it_should_throw_with_descriptive_m
.WithMessage("Expected value to be positive because we want to test the failure message, but found -1.");
}

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

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

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

[Fact]
public void When_a_negative_value_is_negative_it_should_not_throw()
{
Expand Down Expand Up @@ -132,18 +173,29 @@ public void When_a_nullable_numeric_null_value_is_not_negative_it_should_throw()
}

[Fact]
public void When_a_nullable_numeric_null_value_is_not_positive_it_should_throw()
public void NaN_is_never_a_negative_float()
{
// Arrange
int? value = null;
float value = float.NaN;

// Act
Action act = () => value.Should().BePositive();
Action act = () => value.Should().BeNegative();

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

[Fact]
public void NaN_is_never_a_negative_double()
{
// Arrange
double value = double.NaN;

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

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

Expand Down Expand Up @@ -513,6 +565,69 @@ public void When_asserting_that_a_null_decimal_value_is_equal_to_some_value_it_s
.Should().Throw<XunitException>()
.WithMessage("Expected value to be*3.5*, but found <null>.");
}

[Fact]
public void Nan_is_never_equal_to_another_float()
{
// Arrange
float value = float.NaN;

// Act
Action act = () => value.Should().Be(3.4F);

// Assert
act
.Should().Throw<XunitException>()
.WithMessage(
"Expected value to be *3.4F, but found NaN*");
}

[Fact]
public void Comparing_a_float_to_NaN_is_invalid()
{
// Arrange
float value = float.NaN;

// Act
Action act = () => value.Should().Be(float.NaN);

// Assert
act
.Should().Throw<ArgumentException>()
.WithMessage(
"Cannot compare a float to NaN");
}

[Fact]
public void Nan_is_never_equal_to_another_double()
{
// Arrange
double value = double.NaN;

// Act
Action act = () => value.Should().Be(3.4D);

// Assert
act
.Should().Throw<XunitException>()
.WithMessage("Expected value to be *3.4D, but found NaN*");
}

[Fact]
public void Comparing_a_double_to_NaN_is_invalid()
{
// Arrange
double value = double.NaN;

// Act
Action act = () => value.Should().Be(double.NaN);

// Assert
act
.Should().Throw<ArgumentException>()
.WithMessage(
"Cannot compare a float to NaN");
}
}

public class BeGreaterThanOrEqualTo
Expand Down Expand Up @@ -666,6 +781,30 @@ public void When_a_nullable_numeric_null_value_is_not_greater_than_or_equal_to_i
.Should().Throw<XunitException>()
.WithMessage("*null*");
}

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

// Assert
act
.Should().Throw<XunitException>()
.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*");
}
}

public class LessThanOrEqualTo
Expand Down

0 comments on commit 9935484

Please sign in to comment.