[phobos] Split std.datetime in two?
Andrei Alexandrescu
andrei at erdani.com
Thu Feb 10 14:02:37 PST 2011
On 2/10/11 3:44 PM, Don Clugston wrote:
> (1) There has to be a maximum acceptable source file size.
> Personally I start to feel uncomfortable above 2000 lines, and get an
> uncontrollable urge to split at 5000 lines. That's just me, but I
> suggest all modules should be short. And at 35000 lines,
> std.datetime.length> short.max.
Agreed.
> (2) Actually, it seems that most of size actually comes because every
> test is written 'by hand'. If they were done as arrays [parameter1,
> parameter2, result]...
> with a loop, they'd be a lot shorter. (I crunched down the
> std.math.exp tests enormously by doing this). Looking at that module,
> I get the feeling that there's been a lot of cut-and-paste.
> It is a little disconcerting if D really cannot write unittesting code
> concisely. If it really needs to be that big, that part of the
> language needs more work; or we need more helper functions. Or both.
Agreed. People will look at Phobos for inspiration in terms of style and
idioms. If they see they're looking at more than 2x the size of the code
for adding tests, probably they'd feel intimidated.
Peeking at std.datetime's unittests, I confirm they are very repetitive
- essentially unrolled loops. I just set the bar somewhat halfway and
saw the following. I mean come on!
Andrei
assertThrown!DateTimeException(Date.fromISOString(""));
assertThrown!DateTimeException(Date.fromISOString("990704"));
assertThrown!DateTimeException(Date.fromISOString("0100704"));
assertThrown!DateTimeException(Date.fromISOString("2010070"));
assertThrown!DateTimeException(Date.fromISOString("2010070 "));
assertThrown!DateTimeException(Date.fromISOString("120100704"));
assertThrown!DateTimeException(Date.fromISOString("-0100704"));
assertThrown!DateTimeException(Date.fromISOString("+0100704"));
assertThrown!DateTimeException(Date.fromISOString("2010070a"));
assertThrown!DateTimeException(Date.fromISOString("20100a04"));
assertThrown!DateTimeException(Date.fromISOString("2010a704"));
assertThrown!DateTimeException(Date.fromISOString("99-07-04"));
assertThrown!DateTimeException(Date.fromISOString("010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-0"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-0 "));
assertThrown!DateTimeException(Date.fromISOString("12010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("-010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("+010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-0a"));
assertThrown!DateTimeException(Date.fromISOString("2010-0a-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-a7-04"));
assertThrown!DateTimeException(Date.fromISOString("2010/07/04"));
assertThrown!DateTimeException(Date.fromISOString("2010/7/04"));
assertThrown!DateTimeException(Date.fromISOString("2010/7/4"));
assertThrown!DateTimeException(Date.fromISOString("2010/07/4"));
assertThrown!DateTimeException(Date.fromISOString("2010-7-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-7-4"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-4"));
assertThrown!DateTimeException(Date.fromISOString("99Jul04"));
assertThrown!DateTimeException(Date.fromISOString("010Jul04"));
assertThrown!DateTimeException(Date.fromISOString("2010Jul0"));
assertThrown!DateTimeException(Date.fromISOString("2010Jul0
"));
assertThrown!DateTimeException(Date.fromISOString("12010Jul04"));
assertThrown!DateTimeException(Date.fromISOString("-010Jul04"));
assertThrown!DateTimeException(Date.fromISOString("+010Jul04"));
assertThrown!DateTimeException(Date.fromISOString("2010Jul0a"));
assertThrown!DateTimeException(Date.fromISOString("2010Jua04"));
assertThrown!DateTimeException(Date.fromISOString("2010aul04"));
assertThrown!DateTimeException(Date.fromISOString("99-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jul-0"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jul-0 "));
assertThrown!DateTimeException(Date.fromISOString("12010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("-010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("+010-Jul-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jul-0a"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jua-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jal-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-aul-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-07-04"));
assertThrown!DateTimeException(Date.fromISOString("2010-Jul-04"));
assertPred!"=="(Date.fromISOString("19990706"), Date(1999,
7, 6));
assertPred!"=="(Date.fromISOString("-19990706"),
Date(-1999, 7, 6));
assertPred!"=="(Date.fromISOString("+019990706"),
Date(1999, 7, 6));
assertPred!"=="(Date.fromISOString("19990706 "), Date(1999,
7, 6));
assertPred!"=="(Date.fromISOString(" 19990706"), Date(1999,
7, 6));
assertPred!"=="(Date.fromISOString(" 19990706 "),
Date(1999, 7, 6));
//Verify Examples.
assert(Date.fromISOString("20100704") == Date(2010, 7, 4));
assert(Date.fromISOString("19981225") == Date(1998, 12, 25));
assert(Date.fromISOString("00000105") == Date(0, 1, 5));
assert(Date.fromISOString("-00040105") == Date(-4, 1, 5));
assert(Date.fromISOString(" 20100704 ") == Date(2010, 7, 4));
More information about the phobos
mailing list