예제 #1
0
        public void TimeCompareWithoutTruncationTest()
        {
            var comparer = new TimeSpanPrecisionComparer(TimeSpan.Zero);

            Assert.IsTrue(comparer.Equals(TimeSpan.FromTicks(1), TimeSpan.FromTicks(1)));
            Assert.IsFalse(comparer.Equals(TimeSpan.FromTicks(1), TimeSpan.FromTicks(2)));
        }
예제 #2
0
        public void TimeCompareTest()
        {
            var comparer = new TimeSpanPrecisionComparer(TimeSpan.FromMilliseconds(10));

            Assert.IsTrue(comparer.Equals(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)));
            Assert.IsTrue(comparer.Equals(TimeSpan.FromSeconds(2.3), TimeSpan.FromSeconds(2.3)));
            Assert.IsTrue(comparer.Equals(TimeSpan.FromSeconds(2.34), TimeSpan.FromSeconds(2.34)));

            Assert.IsFalse(comparer.Equals(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(3)));
            Assert.IsFalse(comparer.Equals(TimeSpan.FromSeconds(2.3), TimeSpan.FromSeconds(2.4)));
            Assert.IsFalse(comparer.Equals(TimeSpan.FromSeconds(2.34), TimeSpan.FromSeconds(2.35)));

            Assert.IsTrue(comparer.Equals(TimeSpan.FromSeconds(2.345), TimeSpan.FromSeconds(2.345)));
            Assert.IsTrue(comparer.Equals(TimeSpan.FromSeconds(2.345), TimeSpan.FromSeconds(2.346)));
            Assert.IsTrue(comparer.Equals(TimeSpan.FromSeconds(2.340), TimeSpan.FromSeconds(2.349)));
        }