Skip to content

Commit

Permalink
code formatting to match project style
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderDennis committed Oct 4, 2010
1 parent dde7617 commit 2ff42d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Shouldly/ShouldBeEnumerableTestExtensions.cs
Expand Up @@ -22,12 +22,14 @@ public static void ShouldNotContain<T>(this IEnumerable<T> actual, T expected)
throw new AssertionException(new ShouldlyMessage(expected, actual).ToString());
}

public static void ShouldContain(this IEnumerable<float> actual, float expected, double tolerance) {
public static void ShouldContain(this IEnumerable<float> actual, float expected, double tolerance)
{
if (actual.Where(a => Math.Abs(expected - a) < tolerance).Count() < 1)
throw new AssertionException(new ShouldlyMessage(expected, actual).ToString());
}

public static void ShouldContain(this IEnumerable<double> actual, double expected, double tolerance) {
public static void ShouldContain(this IEnumerable<double> actual, double expected, double tolerance)
{
if (actual.Where(a => Math.Abs(expected - a) < tolerance).Count() < 1)
throw new AssertionException(new ShouldlyMessage(expected, actual).ToString());
}
Expand Down
7 changes: 5 additions & 2 deletions src/Tests/ShouldBeEnumerableTests.cs
Expand Up @@ -36,20 +36,23 @@ public void ShouldNotContain_WhenFalse_ShouldErrorWithMessage()
}

[Test]
public void ShouldContain_WithNumbersWhenTrue_ShouldAllowTolerance() {
public void ShouldContain_WithNumbersWhenTrue_ShouldAllowTolerance()
{
new[] { 1.0, 2.1, Math.PI, 4.321, 5.4321 }.ShouldNotContain(3.14);
new[] { 1.0, 2.1, Math.PI, 4.321, 5.4321 }.ShouldContain(3.14, 0.01);
new[] { 1.0f, 2.1f, (float)Math.PI, 4.321f, 5.4321f }.ShouldContain(3.14f, 0.01);
}

[Test]
public void ShouldContain_WithNumbersWhenFalse_ShouldErrorWithMessage() {
public void ShouldContain_WithNumbersWhenFalse_ShouldErrorWithMessage()
{
Should.Error(() =>
new[] { 1.0, 2.1, Math.PI, 4.321, 5.4321 }.ShouldContain(3.14, 0.001),
"new[] { 1.0, 2.1, Math.PI, 4.321, 5.4321 } should contain 3.14 but was [1, 2.1, 3.14159265358979, 4.321, 5.4321]");
Should.Error(() =>
new[] { 1.0f, 2.1f, (float)Math.PI, 4.321f, 5.4321f }.ShouldContain(3.14f, 0.001),
"new[] { 1.0f, 2.1f, (float)Math.PI, 4.321f, 5.4321f } should contain 3.14 but was [1, 2.1, 3.141593, 4.321, 5.4321]");
}

}
}

0 comments on commit 2ff42d7

Please sign in to comment.