Skip to content

Instantly share code, notes, and snippets.

@nonnb
Created January 7, 2015 15:13
Show Gist options
  • Save nonnb/d50e5efabbd4ceefad70 to your computer and use it in GitHub Desktop.
Save nonnb/d50e5efabbd4ceefad70 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace ClassLibrary1
{
public static class SillyClass
{
public static bool IsNaNOrInfinity(this double foo)
{
return (double.IsNaN(foo)) || (double.IsInfinity(foo));
}
}
class CUT
{
public void Foo(double bar, double bar2, double bar3, double bar4)
{
if (bar.IsNaNOrInfinity()) throw new ArgumentOutOfRangeException();
if (bar2.IsNaNOrInfinity()) throw new ArgumentOutOfRangeException();
if (bar3.IsNaNOrInfinity()) throw new ArgumentOutOfRangeException();
if (bar4.IsNaNOrInfinity()) throw new ArgumentOutOfRangeException();
}
}
[TestFixture]
public class FooTests
{
[Datapoints]
private double[] _permutations = new[]
{
double.PositiveInfinity,
double.NegativeInfinity,
double.NaN
};
[Theory]
public void EnsureInvalidDoublesAreThrown(double bar, double bar2, double bar3, double bar4)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new CUT().Foo(bar, bar2, bar3, bar4));
}
}
}
@nonnb
Copy link
Author

nonnb commented Jan 7, 2015

Here we use NUnit's Theories along with an array of DataPoints, which when run with a decent TestRunner (I used Resharper) will generate all permutations of the parameters and pass them into test Theories which are matched by parameter type (double). The above generates 3 ^ 4 = 81 invocations of the Unit test EnsureInvalidDoublesAreThrown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment