public void Test() { Assert.That(() => TestDuration.HoursString(TimeSpan.FromHours(1)), Is.EqualTo("1")); Assert.That(() => TestDuration.MinutesString(TimeSpan.FromMinutes(1)), Is.EqualTo("1")); Assert.That(() => TestDuration.SecondsString(TimeSpan.FromSeconds(1)), Is.EqualTo("1")); Assert.That(() => TestDuration.MillisString(TimeSpan.FromMilliseconds(1)), Is.EqualTo("1")); Assert.That(() => TestDuration.MicrosString(TimeSpan.FromTicks(10)), Is.EqualTo("1")); // 1 tick = 100 nanoseconds Assert.That(() => TestDuration.NanosString(TimeSpan.FromTicks(1)), Is.EqualTo("100")); // 1 tick = 100 nanoseconds Assert.That(() => TestDuration.Hours(1).Hours, Is.EqualTo(1)); Assert.That(() => TestDuration.Minutes(1).Minutes, Is.EqualTo(1)); Assert.That(() => TestDuration.Seconds(1).Seconds, Is.EqualTo(1)); Assert.That(() => TestDuration.Millis(1).Milliseconds, Is.EqualTo(1)); Assert.That(() => TestDuration.Micros(1).Ticks, Is.EqualTo(10)); // 1 tick = 100 nanoseconds Assert.That(() => TestDuration.Nanos(100).Ticks, Is.EqualTo(1)); // 1 tick = 100 nanoseconds Assert.That(() => TestDuration.Hoursf(1.5).TotalMinutes, Is.EqualTo(90)); Assert.That(() => TestDuration.Minutesf(1.5).TotalSeconds, Is.EqualTo(90)); Assert.That(() => TestDuration.Secondsf(1.5).TotalMilliseconds, Is.EqualTo(1500)); Assert.That(() => TestDuration.Millisf(1.5).Ticks, Is.EqualTo(1500 * 10)); Assert.That(() => TestDuration.Microsf(1.5).Ticks, Is.EqualTo(15)); // 1 tick = 100 nanoseconds Assert.That(() => TestDuration.Nanosf(100.5).Ticks, Is.EqualTo(1)); // 1 tick = 100 nanoseconds Assert.That(() => TestDuration.Box(1)?.Seconds, Is.EqualTo(1)); Assert.That(() => TestDuration.Box(-1), Is.Null); Assert.That(() => TestDuration.Unbox(TimeSpan.FromSeconds(1)), Is.EqualTo(1)); Assert.That(() => TestDuration.Unbox(null), Is.EqualTo(-1)); }
private void testDuration() { var hours = TestDuration.Hours(2); var minutes = TestDuration.Minutes(2); var seconds = TestDuration.Seconds(2); var millis = TestDuration.Millis(2); var micros = TestDuration.Micros(2); var nanos = TestDuration.Nanos(200); //minimal time-unit is 100 ns var hoursf = TestDuration.Hoursf(2.5); var minutesf = TestDuration.Minutesf(2.5); var secondsf = TestDuration.Secondsf(2.5); var milisf = TestDuration.Millisf(2.5); var microsf = TestDuration.Microsf(2.5); var nanosf = TestDuration.Nanosf(200.0); //minimal time-unit is 100 ns var box = TestDuration.Box(5); var unbox = TestDuration.Unbox(box); bool r = hours.Hours == 2 && minutes.Minutes == 2 && seconds.Seconds == 2 && millis.Milliseconds == 2 && micros.TotalMilliseconds == 2E-3 && nanos.TotalMilliseconds == 2E-4 && hoursf.TotalHours == 2.5 && minutesf.TotalMinutes == 2.5 && secondsf.TotalSeconds == 2.5 && milisf.TotalMilliseconds == 2.5 && microsf.TotalMilliseconds == 2.5E-3 && nanosf.TotalMilliseconds == 2E-4 && TestDuration.HoursString(hours) == "2" && TestDuration.MinutesString(minutes) == "2" && TestDuration.SecondsString(seconds) == "2" && TestDuration.MillisString(millis) == "2" && TestDuration.MicrosString(micros) == "2" && TestDuration.NanosString(nanos) == "200"; append("testDuration", r); }