public void RoundTimeTest() { TimeTicksFormatService target = new TimeTicksFormatService(); // TODO: Initialize to an appropriate value Assert.AreEqual(0, Math.Round(0.0)); Assert.AreEqual(Minutes(0), target.RoundTime(Minutes(0), Minutes(1))); Assert.AreEqual(1, Math.Round(1.0)); Assert.AreEqual(Minutes(1), target.RoundTime(Minutes(1), Minutes(1))); Assert.AreEqual(1, Math.Round(0.51)); Assert.AreEqual(Minutes(1), target.RoundTime(Minutes(0.51), Minutes(1))); Assert.AreEqual(2, Math.Round(1.5)); Assert.AreEqual(Minutes(2), target.RoundTime(Minutes(1.5), Minutes(1))); Assert.AreEqual(2, Math.Round(1.6)); Assert.AreEqual(Minutes(2), target.RoundTime(Minutes(1.6), Minutes(1))); Assert.AreEqual(-1, Math.Round(-1.0)); Assert.AreEqual(Minutes(-1), target.RoundTime(Minutes(-1), Minutes(1))); Assert.AreEqual(-1, Math.Round(-0.51)); Assert.AreEqual(Minutes(-1), target.RoundTime(Minutes(-0.51), Minutes(1))); Assert.AreEqual(-2, Math.Round(-1.5)); Assert.AreEqual(Minutes(-2), target.RoundTime(Minutes(-1.5), Minutes(1))); Assert.AreEqual(-2, Math.Round(-1.6)); Assert.AreEqual(Minutes(-2), target.RoundTime(Minutes(-1.6), Minutes(1))); Assert.AreEqual(Minutes(4), target.RoundTime(Minutes(3), Minutes(2))); Assert.AreEqual(Minutes(2), target.RoundTime(Minutes(2.9), Minutes(2))); Assert.AreEqual(Minutes(4), target.RoundTime(Minutes(3.1), Minutes(2))); }
public void TicksToStringTests() { var service = new TimeTicksFormatService(); var scale1Second = TimeSpan.FromSeconds(1).Ticks; var scale10Second = TimeSpan.FromSeconds(.1).Ticks; var scale100Second = TimeSpan.FromSeconds(.01).Ticks; var scale1000Second = TimeSpan.FromSeconds(.001).Ticks; var ts = new TimeSpan(0, 12, 46, 54, 745); Assert.AreEqual("12:46:55", service.TicksToString(ts.Ticks, scale1Second)); Assert.AreEqual("12:46:54.7", service.TicksToString(ts.Ticks, scale10Second)); Assert.AreEqual("12:46:54.74", service.TicksToString(ts.Ticks, scale100Second)); Assert.AreEqual("12:46:54.745", service.TicksToString(ts.Ticks, scale1000Second)); ts = new TimeSpan(46, 12, 46, 54, 745); Assert.AreEqual("1116:46:55", service.TicksToString(ts.Ticks, scale1Second)); Assert.AreEqual("1116:46:54.7", service.TicksToString(ts.Ticks, scale10Second)); Assert.AreEqual("1116:46:54.74", service.TicksToString(ts.Ticks, scale100Second)); Assert.AreEqual("1116:46:54.745", service.TicksToString(ts.Ticks, scale1000Second)); Assert.AreEqual("12:01:55", service.TicksToString(new TimeSpan(0, 12, 01, 54, 745).Ticks, scale1Second)); }
public void ParseTets() { var service = new TimeTicksFormatService(); Assert.AreEqual(new TimeSpan(1, 1, 1).Ticks, service.ParseToTicks("1:1:1")); Assert.AreEqual(new TimeSpan(0, 40, 10).Ticks, service.ParseToTicks("00:40:10")); }
private static ITimeTicksFormatService ITimeTicksFormatService() { var service = new TimeTicksFormatService(); IoC.Resolve <IServiceBus>().Register <ITimeTicksFormatService>(service); return(service); }