digitalmars.D.learn - Dlang tour - Unittesting example
- Joe (5/5) Oct 01 2018 There appears to be a problem with the example at
- bauss (3/8) Oct 02 2018 I think it's more likely a problem with your OS.
- Joe (3/13) Oct 02 2018 Well then it's also a problem with run.dlang.io, since as I said
- Joe (5/20) Oct 02 2018 I forgot to mention: at the end, it reports "1/1 unittests
- Basile B. (16/37) Oct 02 2018 The problem is the NaN madness.
- ag0aep6g (4/23) Oct 02 2018 NaN simply isn't equal to itself. Has nothing to do with there being
- Joe (12/27) Oct 02 2018 OK, so changing the example from
- Steven Schveighoffer (7/29) Oct 02 2018 I will note that the granularity of the unittests is based on how many
- Jonathan M Davis (9/19) Oct 02 2018 IIRC, we use stdc for formatting floating values and not pure D code
There appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest, the resulting program crashes. It happens with ldc2 on Linux but it can also be seen if you click on "Export" and run it with dmd -unittest.
Oct 01 2018
On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:There appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest, the resulting program crashes. It happens with ldc2 on Linux but it can also be seen if you click on "Export" and run it with dmd -unittest.I think it's more likely a problem with your OS. I am unable to reproduce that with either of dmd or ldc.
Oct 02 2018
On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:Well then it's also a problem with run.dlang.io, since as I said it also happens when you run it there.There appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest, the resulting program crashes. It happens with ldc2 on Linux but it can also be seen if you click on "Export" and run it with dmd -unittest.I think it's more likely a problem with your OS. I am unable to reproduce that with either of dmd or ldc.
Oct 02 2018
On Tuesday, 2 October 2018 at 12:25:19 UTC, Joe wrote:On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:I forgot to mention: at the end, it reports "1/1 unittests FAILED". I see three tests--two in the struct and the separate one--but the assertion failure is in line 49 (the standalone) so apparently the other two are not being run (or reported).On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:Well then it's also a problem with run.dlang.io, since as I said it also happens when you run it there.There appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest, the resulting program crashes. It happens with ldc2 on Linux but it can also be seen if you click on "Export" and run it with dmd -unittest.I think it's more likely a problem with your OS. I am unable to reproduce that with either of dmd or ldc.
Oct 02 2018
On Tuesday, 2 October 2018 at 12:30:36 UTC, Joe wrote:On Tuesday, 2 October 2018 at 12:25:19 UTC, Joe 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.On Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:I forgot to mention: at the end, it reports "1/1 unittests FAILED". I see three tests--two in the struct and the separate one--but the assertion failure is in line 49 (the standalone) so apparently the other two are not being run (or reported).On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:Well then it's also a problem with run.dlang.io, since as I said it also happens when you run it there.There appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest, the resulting program crashes. It happens with ldc2 on Linux but it can also be seen if you click on "Export" and run it with dmd -unittest.I think it's more likely a problem with your OS. I am unable to reproduce that with either of dmd or ldc.
Oct 02 2018
On 10/02/2018 03:24 PM, 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.NaN simply isn't equal to itself. Has nothing to do with there being multiple NaNs. `d == d`, `double.nan == double.nan`, `double.init == double.init` are all false, too.
Oct 02 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().
Oct 02 2018
On 10/2/18 8:30 AM, Joe wrote:On Tuesday, 2 October 2018 at 12:25:19 UTC, Joe wrote:I will note that the granularity of the unittests is based on how many *modules* were tested. There is only one unittest function in each ModuleInfo (as provided by the compiler to the runtime), so that's the number that's being reported. So in this case, it's not missing unittests, it's running all given unit tests. -SteveOn Tuesday, 2 October 2018 at 09:59:28 UTC, bauss wrote:I forgot to mention: at the end, it reports "1/1 unittests FAILED". I see three tests--two in the struct and the separate one--but the assertion failure is in line 49 (the standalone) so apparently the other two are not being run (or reported).On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:Well then it's also a problem with run.dlang.io, since as I said it also happens when you run it there.There appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest, the resulting program crashes. It happens with ldc2 on Linux but it can also be seen if you click on "Export" and run it with dmd -unittest.I think it's more likely a problem with your OS. I am unable to reproduce that with either of dmd or ldc.
Oct 02 2018
On Tuesday, October 2, 2018 3:59:28 AM MDT bauss via Digitalmars-d-learn wrote:On Tuesday, 2 October 2018 at 04:13:01 UTC, Joe wrote:IIRC, we use stdc for formatting floating values and not pure D code (because correctly converting floating point values to strings is really, really complicated to implement). So, the result is going to depend on the system that it's run on. It fails on my system (64-bit FreeBSD). Honestly, this is basically the same thing as comparing floating point values with ==. You shouldn't do it. So, I'd argue that it's just plain a bad example. - Jonathan M DavisThere appears to be a problem with the example at https://tour.dlang.org/tour/en/gems/unittesting If compiled with -unittest, the resulting program crashes. It happens with ldc2 on Linux but it can also be seen if you click on "Export" and run it with dmd -unittest.I think it's more likely a problem with your OS. I am unable to reproduce that with either of dmd or ldc.
Oct 02 2018