[Swift-devel] assertEqual

Mihael Hategan hategan at mcs.anl.gov
Wed Apr 8 13:08:18 CDT 2015


I went with an optional. It keeps backwards compatibility and makes it
clear what that number is.

Mihael

On Wed, 2015-04-08 at 11:48 -0500, Tim Armstrong wrote:
> Reviving this thread...  Probably the options are to either add an overload:
> 
> assertEqual(float v1, float v2, float tolerance, string msg)
> 
> or something like
> 
> assertAlmostEqual(float v1, float v2, float tolerance, string msg)
> assertApproxEqual(float v1, float v2, float tolerance, string msg)
> assertApprox(float v1, float v2, float tolerance, string msg)
> 
> I don't think there's much of a reason to break compatibility in Swift/T
> with the (float, float, string) form, so I think we should keep that in.
> 
> - Tim
> 
> On 6 April 2015 at 12:14, Mihael Hategan <hategan at mcs.anl.gov> wrote:
> 
> > On Mon, 2015-04-06 at 09:38 -0500, Tim Armstrong wrote:
> > > Right, the tests for those things in the Swift test suite are like:
> > >
> > > assert(abs(sin(PI/2) - 1.0) < 1e-15, "sin");
> > >
> > > Which is a little less convenient.
> > >
> > > I think if we want almost equal semantics we could have assertAlmostEqual
> > > with a tolerance parameter
> >
> > That's a choice.
> >
> > I personally think that approximate equality in numerics is such a
> > widespread issue, that there wouldn't be much confusion.
> >
> > Mihael
> >
> > >
> > > -Tim
> > >
> > > On 5 April 2015 at 21:17, Mihael Hategan <hategan at mcs.anl.gov> wrote:
> > >
> > > > Hi,
> > > >
> > > > I found it useful to have a tolerance parameter for assertEqual(float,
> > > > float).
> > > >
> > > > Checks like assertEqual(tan(x), sin(x) / cos(x)) are otherwise not
> > going
> > > > to work very well.
> > > >
> > > > Mihael
> > > >
> > > > _______________________________________________
> > > > Swift-devel mailing list
> > > > Swift-devel at ci.uchicago.edu
> > > > https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel
> > > >
> >
> >
> >





More information about the Swift-devel mailing list