コード例 #1
0
        public static void TestFromNanoseconds(double timeMs)
        {
            var accurateMs = TimeSpan.FromTicks((long)(timeMs * TimeSpan.TicksPerMillisecond));

            Assert.AreEqual(
                TimeSpanHelper.FromNanoseconds(timeMs * 1000 * 1000),
                accurateMs);

            Assert.AreEqual(
                accurateMs.TotalNanoseconds(),
                timeMs * 1000 * 1000);
        }
コード例 #2
0
        public static void TestMultiplySuccess(int time, double scale)
        {
            // Too small for timespan resolution
            Assert.AreEqual(
                TimeSpan.FromTicks(time * 10000).Multiply(scale),
                TimeSpan.FromTicks((long)(time * 10000 * scale)));

            // Too small for timespan resolution
            Assert.AreEqual(
                TimeSpanHelper.FromNanoseconds(time * 10000).Multiply(scale),
                TimeSpanHelper.FromNanoseconds(time * 10000 * scale));

            // Too small for timespan resolution
            Assert.AreEqual(
                TimeSpanHelper.FromMicroseconds(time * 10000).Multiply(scale),
                TimeSpanHelper.FromMicroseconds(time * 10000 * scale));

            // HACK: see https://stackoverflow.com/a/5450495 for explanation
            Assert.AreEqual(
                Math.Round(TimeSpan.FromMilliseconds(time).Multiply(scale).TotalMilliseconds),
                Math.Round(TimeSpan.FromMilliseconds(time * scale).TotalMilliseconds));

            Assert.AreEqual(
                TimeSpan.FromSeconds(time).Multiply(scale),
                TimeSpan.FromSeconds(time * scale));

            Assert.AreEqual(
                TimeSpan.FromMinutes(time).Multiply(scale),
                TimeSpan.FromMinutes(time * scale));

            Assert.AreEqual(
                TimeSpan.FromHours(time).Multiply(scale),
                TimeSpan.FromHours(time * scale));

            Assert.AreEqual(
                TimeSpan.FromDays(time).Multiply(scale),
                TimeSpan.FromDays(time * scale));
        }