Dlang tour - Unittesting example
    Joe 
    jma at freedomcircle.com
       
    Tue Oct  2 17:04:19 UTC 2018
    
    
  
On Tuesday, 2 October 2018 at 13:24:09 UTC, Basile B. wrote:
> The problem is the NaN madness.
> Since several values are NaN there's this strange stuff:
>
> void main()
> {
>     import std.stdio;
>     import std.math : isNaN;
>     double d;
>
>     writeln(d.init);    // nan
>     writeln(d);         // nan
>     writeln(d.nan);     // nan
>
>     assert(d.isNaN);
>     assert(d == d.nan);  // fails
>     assert(d == d.init); // fails
> }
>
> the last assert is just crazy.
OK, so changing the example from
     // .init a special built-in property that
     // returns the initial value of type.
     assert(vec.x == double.init);
to
     import std.math : isNaN;
     assert(vec.x.isNaN);
doesn't cause the crash. Although I'm a bit puzzled still, I 
thought (coming from Python) that when you ran the unittest 
version it would report which tests passed and which failed, not 
run through main().
    
    
More information about the Digitalmars-d-learn
mailing list