Skip to content

Commit

Permalink
SAVEPOINT
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Feb 26, 2022
1 parent 1fe9df7 commit ef64ed5
Showing 1 changed file with 282 additions and 7 deletions.
289 changes: 282 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 Cannot_compare_a_float_against_NaN()
{
// Arrange
float value = 3.4F;

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

// Assert
act
.Should().Throw<ArgumentException>()
.WithMessage(
"*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.4, but found NaN*");
}

[Fact]
public void Cannot_compare_a_double_against_NaN()
{
// Arrange
double value = 3.4F;

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

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

public class BeGreaterThanOrEqualTo
Expand Down Expand Up @@ -666,6 +781,54 @@ 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 A_float_cannot_be_greater_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*");
}
}

public class LessThanOrEqualTo
Expand Down Expand Up @@ -817,6 +980,54 @@ public void When_a_nullable_numeric_null_value_is_not_less_than_or_equal_to_it_s
.Should().Throw<XunitException>()
.WithMessage("*null*");
}

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

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

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

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

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

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

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

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

public class InRange
Expand Down Expand Up @@ -864,6 +1075,70 @@ public void When_a_nullable_numeric_null_value_is_not_in_range_it_should_throw()
.Should().Throw<XunitException>()
.WithMessage("*null*");
}

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

// Act
Action act = () => value.Should().BeInRange(4, 5);

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

[Fact]
public void A_float_can_never_be_in_a_range_containing_NaN()
{
// Arrange
float value = 4.5F;

// Act
Action act = () => value.Should().BeInRange(float.NaN, 5);

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

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

// Act
Action act = () => value.Should().BeInRange(4, 5);

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

[Fact]
public void A_double_can_never_be_in_a_range_containing_NaN()
{
// Arrange
double value = 4.5D;

// Act
Action act = () => value.Should().BeInRange(double.NaN, 5);

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

public class NotInRange
Expand Down

0 comments on commit ef64ed5

Please sign in to comment.