Time tests.

A while ago I said I'd circulate a couple of tests I'd written for timing. I struggled for a while on how to express these in a format suitable for the test suite. In the end I just decided to post the source (this is in C#).
Note that the semantic constraint on seconds and frames are not applied in the Parse function, thus some of these are not actually legal time expressions:

       /// <summary>
        /// Test the time parser. Not comprehensive at this point
        /// </summary>
        /// <returns></returns>
        public static bool UnitTests()
        {
            // reference is a 60 second timespan.
            // Parse applies a default tickrate and framerate of 30 unless
            // otherwise specified.
            TimeSpan reference = new TimeSpan(0, 1, 00);
            bool pass = true;

            pass &= Parse("60s").Ticks == reference.Ticks;
            pass &= Parse("1m").Ticks == reference.Ticks;
            pass &= Parse("60000ms").Ticks == reference.Ticks;
            pass &= Parse("1800f").Ticks == reference.Ticks;
            pass &= Parse("600f",10).Ticks == reference.Ticks;
            pass &= Parse("30t",0,0.5).Ticks == reference.Ticks;
            pass &= Parse("00:01:00").Ticks == reference.Ticks;
            pass &= Parse("00:00:60:00").Ticks == reference.Ticks;
            pass &= Parse("00:00:59:25",25).Ticks == reference.Ticks;

            reference = new TimeSpan(1, 0, 0);
            pass &= Parse("3600s", 0, 0.5).Ticks == reference.Ticks;
            pass &= Parse("01:00:00").Ticks == reference.Ticks;
            pass &= Parse("00:59:60:00").Ticks == reference.Ticks;
            pass &= Parse("00:59:59:25", 25).Ticks == reference.Ticks;

            return pass;
        }

Sean Hayes
Media Accessibility Strategist
Accessibility Business Unit
Microsoft

Office:  +44 118 909 5867,
Mobile: +44 7875 091385

Received on Wednesday, 29 October 2008 12:52:54 UTC