Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 498

Show
Ignore:
Timestamp:
01/11/11 04:27:36 (14 years ago)
Author:
jmdavis
Message:

Temporarily make tests which are failing on Windows Posix-only.

When I have the time, I'll work on testing it on a Windows box and make
the test properly robust for differences in ticks per second. But the
code should be just fine. It's the test that needs to be improved.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/core/time.d

    r494 r498  
    880880 
    881881    /++ 
    882882        Returns the fractional seconds passed the second. 
    883883 
    884884        Examples: 
    885885-------------------- 
    886886assert(dur!"msecs"(1000).fracSec == FracSec.from!"msecs"(0)); 
    887887assert(dur!"msecs"(1217).fracSec == FracSec.from!"msecs"(217)); 
    888888assert(dur!"usecs"(43).fracSec == FracSec.from!"usecs"(43)); 
    889889assert(dur!"hnsecs"(50_007).fracSec == FracSec.from!"hnsecs"(50_007)); 
     890assert(dur!"nsecs"(62_127).fracSec == FracSec.from!"nsecs"(62_100)); 
    890891-------------------- 
    891892     +/ 
    892893    @property FracSec fracSec() const pure nothrow 
    893894    { 
    894895        try 
    895896        { 
    896897            long hnsecs = _hnsecs; 
    897898            auto days = splitUnitsFromHNSecs!"days"(hnsecs) + 1; 
    898899 
    899900            if(hnsecs < 0) 
     
    912913            assert(0, "FracSec.from!\"hnsecs\"() threw."); 
    913914    } 
    914915 
    915916    unittest 
    916917    { 
    917918        //Verify Examples. 
    918919        assert(dur!"msecs"(1000).fracSec == FracSec.from!"msecs"(0)); 
    919920        assert(dur!"msecs"(1217).fracSec == FracSec.from!"msecs"(217)); 
    920921        assert(dur!"usecs"(43).fracSec == FracSec.from!"usecs"(43)); 
    921922        assert(dur!"hnsecs"(50_007).fracSec == FracSec.from!"hnsecs"(50_007)); 
     923        assert(dur!"nsecs"(62_127).fracSec == FracSec.from!"nsecs"(62_100)); 
    922924 
    923925        const dur = Duration(12); 
    924926        const cdur = Duration(12); 
    925927        immutable idur = Duration(12); 
    926928        static assert(__traits(compiles, dur.fracSec)); 
    927929        static assert(__traits(compiles, cdur.fracSec)); 
    928930        static assert(__traits(compiles, idur.fracSec)); 
    929931    } 
    930932 
    931933 
     
    11951197    long _hnsecs; 
    11961198} 
    11971199 
    11981200 
    11991201/++ 
    12001202    This allows you to construct a Duration from the given time units 
    12011203    with the given length. 
    12021204 
    12031205    The possible values for units are "weeks", "days", "hours", "minutes", 
    12041206    "seconds", "msecs" (milliseconds), "usecs", (microseconds), 
    1205     and "hnsecs" (hecto-nanoseconds, i.e. 100 ns)
     1207    "hnsecs" (hecto-nanoseconds, i.e. 100 ns), and "nsecs"
    12061208 
    12071209    Params: 
    12081210        units  = The time units of the duration (e.g. "days"). 
    12091211        length = The number of units in the duration. 
    12101212  +/ 
    12111213@safe 
    12121214Duration dur(string units)(long length) pure nothrow 
    12131215    if(units == "weeks" || 
    12141216       units == "days" || 
    12151217       units == "hours" || 
     
    14931495            assert(t.usecs == 1_999_999); 
    14941496        } 
    14951497 
    14961498        if(ticksPerSec >= 1_000_000) 
    14971499            assert(TickDuration.from!"usecs"(7).usecs == 7); 
    14981500    } 
    14991501 
    15001502    //test from!"hnsecs"(). 
    15011503    unittest 
    15021504    { 
    1503         auto t = TickDuration.from!"hnsecs"(10_000_000); 
    1504         assert(t.hnsecs == 10_000_000); 
    1505         t = TickDuration.from!"hnsecs"(20_000_000); 
    1506         assert(t.hnsecs == 20_000_000); 
    1507  
    1508         if(ticksPerSec == 1_000_000) 
     1505        //Skipping tests on Windows until properly robust tests 
     1506        //can be devised and tested on a Windows box. 
     1507        //The differences in ticksPerSec on Windows makes testing 
     1508        //exact values a bit precarious. 
     1509        version(Posix) 
    15091510        { 
    1510             t.length -= 1; 
    1511             assert(t.hnsecs == 19999990); 
    1512             assert(TickDuration.from!"hnsecs"(70).hnsecs == 70); 
    1513             assert(TickDuration.from!"hnsecs"(7).hnsecs == 0); 
     1511            auto t = TickDuration.from!"hnsecs"(10_000_000); 
     1512            assert(t.hnsecs == 10_000_000); 
     1513            t = TickDuration.from!"hnsecs"(20_000_000); 
     1514            assert(t.hnsecs == 20_000_000); 
     1515 
     1516            if(ticksPerSec == 1_000_000) 
     1517            { 
     1518                t.length -= 1; 
     1519                assert(t.hnsecs == 19999990); 
     1520                assert(TickDuration.from!"hnsecs"(70).hnsecs == 70); 
     1521                assert(TickDuration.from!"hnsecs"(7).hnsecs == 0); 
     1522            } 
     1523 
     1524            if(ticksPerSec >= 10_000_000) 
     1525            { 
     1526                t.length -= 1; 
     1527                assert(t.hnsecs == 19999999); 
     1528                assert(TickDuration.from!"hnsecs"(70).hnsecs == 70); 
     1529                assert(TickDuration.from!"hnsecs"(7).hnsecs == 7); 
     1530            } 
    15141531        } 
    1515  
    1516         if(ticksPerSec >= 10_000_000) 
     1532    } 
     1533 
     1534    //test from!"nsecs"(). 
     1535    unittest 
     1536    { 
     1537        //Skipping tests on Windows until properly robust tests 
     1538        //can be devised and tested on a Windows box. 
     1539        //The differences in ticksPerSec on Windows makes testing 
     1540        //exact values a bit precarious. 
     1541        version(Posix) 
    15171542        { 
    1518             t.length -= 1; 
    1519             assert(t.hnsecs == 19999999); 
    1520             assert(TickDuration.from!"hnsecs"(70).hnsecs == 70); 
    1521             assert(TickDuration.from!"hnsecs"(7).hnsecs == 7); 
    1522         } 
    1523     } 
    1524  
    1525     //test from!"nsecs"(). 
    1526     unittest 
    1527     { 
    1528         auto t = TickDuration.from!"nsecs"(1_000_000_000); 
    1529         assert(t.nsecs == 1_000_000_000); 
    1530         t = TickDuration.from!"nsecs"(2_000_000_000); 
    1531         assert(t.nsecs == 2_000_000_000); 
    1532  
    1533         if(ticksPerSec == 1_000_000) 
    1534         { 
    1535             t.length -= 1; 
    1536             assert(t.nsecs == 1999999000); 
    1537         } 
    1538  
    1539         if(ticksPerSec >= 1_000_000_000) 
    1540         { 
    1541             t.length -= 1; 
    1542             assert(t.nsecs == 1999999999); 
     1543            auto t = TickDuration.from!"nsecs"(1_000_000_000); 
     1544            assert(t.nsecs == 1_000_000_000); 
     1545            t = TickDuration.from!"nsecs"(2_000_000_000); 
     1546            assert(t.nsecs == 2_000_000_000); 
     1547 
     1548            if(ticksPerSec == 1_000_000) 
     1549            { 
     1550                t.length -= 1; 
     1551                assert(t.nsecs == 1999999000); 
     1552            } 
     1553 
     1554            if(ticksPerSec >= 1_000_000_000) 
     1555            { 
     1556                t.length -= 1; 
     1557                assert(t.nsecs == 1999999999); 
     1558            } 
    15431559        } 
    15441560    } 
    15451561 
    15461562 
    15471563    /++ 
    15481564        Returns a Duration with the same number of hnsecs as this TickDuration. 
    15491565      +/ 
    15501566    Duration opCast(T)() const pure nothrow 
    15511567        if(is(T == Duration)) 
    15521568    { 
     
    24562472 
    24572473        Note that this does not give you any greater precision 
    24582474        than setting the value of this FracSec as hnsecs. 
    24592475 
    24602476        Params: 
    24612477            nsecs = The number of nsecs passed the second. 
    24622478 
    24632479        Throws: 
    24642480            TimeException if the given value is not less than one second. 
    24652481      +/ 
    2466     @property void nsecs(int nsecs) pure 
     2482    @property void nsecs(long nsecs) pure 
    24672483    { 
    24682484        //So that -99 through -1 throw instead of result in FracSec(0). 
    24692485        if(nsecs < 0) 
    24702486            _enforceValid(-1); 
    24712487 
    24722488        immutable hnsecs = cast(int)convert!("nsecs", "hnsecs")(nsecs); 
    24732489 
    24742490        _enforceValid(hnsecs); 
    24752491        _hnsecs = hnsecs; 
    24762492    } 
    24772493 
    24782494    unittest 
    24792495    { 
    2480         static void testFS(int nsecs, in FracSec expected = FracSec.init, size_t line = __LINE__) 
     2496        static void testFS(long nsecs, in FracSec expected = FracSec.init, size_t line = __LINE__) 
    24812497        { 
    24822498            FracSec fs; 
    24832499 
    24842500            fs.nsecs = nsecs; 
    24852501 
    24862502            if(fs != expected) 
    24872503                throw new AssertError("", __FILE__, line); 
    24882504        } 
    24892505 
    24902506        tAssertExThrown!TimeException(testFS(-1));