title: How can I use NUnit's EqualTo().Within() constraint with a custom data type?
body: <p>I love NUnit's constraint-based API.  I often use floating point comparison like this:</p>
  
  <pre><code>double d = foo.SomeComputedProperty;
  
  Assert.That(d, Is.EqualTo(42.0).Within(0.001));
  </code></pre>
  
  <p>Very readable!</p>
  
  <p>However, if I have a custom class whose equality depends on floating point comparison:</p>
  
  <pre><code>class Coord
  {
    Coord(double radius, double radians)
    {
      this.Radius = radius;
      this.Radians = radians;
    }
  
    double Radius { get; }
    double Radians { get; }
  
    public override bool Equals(Object obj)
    {
      Coord c = obj as Coord;
      if (obj == null || c == null) return false;
  
      return c.Radians == this.Radians &amp;&amp; c.Radius == this.Radius;
    }
  }
  </code></pre>
  
  <p>I would like to write my tests like this:</p>
  
  <pre><code>Coord reference = new Coord(1.0, 3.14);
  
  // test another Coord for near-equality to a reference Coord:
  Assert.That(testCoord, Is.EqualTo(reference).Within(0.001));
  </code></pre>
  
  <p><strong>Is it at all possible to use NUnit like this?</strong></p>