public string convertTime(string aTime) { TimeSpan time = this.inputConverterService.Convert(aTime); BerlinClockTimeRepresentation timeRepresentation = this.berlinClockService.RepresentTime(time); return(this.visualisationService.TextVisualisation(timeRepresentation)); }
public void TwentyFourHoursAsSetHoursInputTurnOnAllDiodesOnFirstAndSecondRow() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); timeRepresentation.SetHours(24); Assert.IsTrue(timeRepresentation.FirstRow.All(x => x.IsOn)); Assert.IsTrue(timeRepresentation.SecondRow.All(x => x.IsOn)); Assert.IsTrue(timeRepresentation.ThirdRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ForthRow.All(x => !x.IsOn)); }
public void FiftyNineMinutesAsSetMinutesTurnsOnAllDiodesOfThirdAndFourthRow() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); timeRepresentation.SetMinutes(59); Assert.IsTrue(timeRepresentation.FirstRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.SecondRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ThirdRow.All(x => x.IsOn)); Assert.IsTrue(timeRepresentation.ForthRow.All(x => x.IsOn)); }
public void WhenInputExeed24HoursExpectArgumentException() { this.berlinClockFactoryMock = new Mock <IBerlineClockFactory>(); berlinClockService = new BerlineClockService(this.berlinClockFactoryMock.Object); BerlinClockTimeRepresentation timeRepresentationFactoryProduct = new BerlinClockTimeRepresentation(); this.berlinClockFactoryMock.Setup(x => x.BuildNew()).Returns(timeRepresentationFactoryProduct); Assert.Throws(typeof(ArgumentException), () => berlinClockService.RepresentTime(new TimeSpan(24, 0, 1))); }
public void ZeroMinutesAsSetMinutesTurnsOnNoDiodesInAnyRow() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); timeRepresentation.SetMinutes(0); Assert.IsTrue(timeRepresentation.FirstRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.SecondRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ThirdRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ForthRow.All(x => !x.IsOn)); }
public void ZeroAsSetSecondsTurnsOnOnlyTopDiode() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); timeRepresentation.SetSeconds(0); Assert.IsTrue(timeRepresentation.FirstRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.SecondRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ThirdRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ForthRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.TopDiode.IsOn); }
public void FiftyNineAsSetSecondsTurnsOnNoneOfDiodes() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); timeRepresentation.SetSeconds(59); Assert.IsTrue(timeRepresentation.FirstRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.SecondRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ThirdRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ForthRow.All(x => !x.IsOn)); Assert.IsFalse(timeRepresentation.TopDiode.IsOn); }
public void ZeroHoursAsSetHoursInputTurnOnNoDiodes() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); timeRepresentation.SetHours(0); Assert.IsTrue(timeRepresentation.FirstRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.SecondRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ThirdRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ForthRow.All(x => !x.IsOn)); Assert.IsTrue(!timeRepresentation.TopDiode.IsOn); }
public string TextVisualisation(BerlinClockTimeRepresentation berlinClock) { StringBuilder returnFormat = new StringBuilder(); returnFormat.AppendLine(ColorStringRepresentation(berlinClock.TopDiode.Color, berlinClock.TopDiode.IsOn)); returnFormat.AppendLine(string.Concat(DiodesLine(berlinClock.FirstRow))); returnFormat.AppendLine(string.Concat(DiodesLine(berlinClock.SecondRow))); returnFormat.AppendLine(string.Concat(DiodesLine(berlinClock.ThirdRow))); returnFormat.AppendLine(string.Concat(DiodesLine(berlinClock.ForthRow))); string resultString = returnFormat.ToString().TrimEnd(); return(resultString); }
public void Input190001ReturnsLastDiodeOfSecondRowOn() { this.berlinClockFactoryMock = new Mock <IBerlineClockFactory>(); berlinClockService = new BerlineClockService(this.berlinClockFactoryMock.Object); BerlinClockTimeRepresentation timeRepresentationFactoryProduct = new BerlinClockTimeRepresentation(); this.berlinClockFactoryMock.Setup(x => x.BuildNew()).Returns(timeRepresentationFactoryProduct); BerlinClockTimeRepresentation timeRepresentationResult = berlinClockService.RepresentTime(new TimeSpan(19, 00, 01)); Assert.IsFalse(timeRepresentationResult.TopDiode.IsOn); Assert.IsTrue(timeRepresentationResult.SecondRow.Last().IsOn); }
public void DefaultConstructorCreatesDiodesInCorrectNumberAndType() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); Assert.AreEqual(4, timeRepresentation.FirstRow.Length); Assert.IsTrue(timeRepresentation.FirstRow.All(x => x is FiveHourDiode)); Assert.AreEqual(4, timeRepresentation.SecondRow.Length); Assert.IsTrue(timeRepresentation.SecondRow.All(x => x is OneHourDiode)); Assert.AreEqual(11, timeRepresentation.ThirdRow.Length); Assert.IsTrue(timeRepresentation.ThirdRow.All(x => x is FiveMinuteDiode)); Assert.AreEqual(4, timeRepresentation.ForthRow.Length); Assert.IsTrue(timeRepresentation.ForthRow.All(x => x is OneMinuteDiode)); Assert.AreEqual(typeof(OneSecDiode), timeRepresentation.TopDiode.GetType()); }
public void ResetClockSetStateOfAllDiodesToOff() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); foreach (var diode in timeRepresentation.FirstRow.Union(timeRepresentation.SecondRow).Union(timeRepresentation.ThirdRow).Union(timeRepresentation.ForthRow)) { diode.ChangeState(); } timeRepresentation.TopDiode.ChangeState(); timeRepresentation.ResetClock(); Assert.IsTrue(timeRepresentation.FirstRow.Union(timeRepresentation.SecondRow).Union(timeRepresentation.ThirdRow).Union(timeRepresentation.ForthRow).All(x => !x.IsOn)); Assert.IsFalse(timeRepresentation.TopDiode.IsOn); }
public void InputZeroReturnsOnlyTopDiodeOn() { this.berlinClockFactoryMock = new Mock <IBerlineClockFactory>(); berlinClockService = new BerlineClockService(this.berlinClockFactoryMock.Object); BerlinClockTimeRepresentation timeRepresentationFactoryProduct = new BerlinClockTimeRepresentation(); this.berlinClockFactoryMock.Setup(x => x.BuildNew()).Returns(timeRepresentationFactoryProduct); BerlinClockTimeRepresentation timeRepresentationResult = berlinClockService.RepresentTime(TimeSpan.Zero); Assert.IsTrue(timeRepresentationResult.TopDiode.IsOn); Assert.IsTrue(timeRepresentationResult.FirstRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentationResult.SecondRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentationResult.ThirdRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentationResult.ForthRow.All(x => !x.IsOn)); }
public void InputTwentyFourHoursZeroMinutesZeroSecondsTurnsOnDiodesOnFirstAndSecondRowsAndTopDiodeOnly() { this.berlinClockFactoryMock = new Mock <IBerlineClockFactory>(); berlinClockService = new BerlineClockService(this.berlinClockFactoryMock.Object); BerlinClockTimeRepresentation timeRepresentationFactoryProduct = new BerlinClockTimeRepresentation(); this.berlinClockFactoryMock.Setup(x => x.BuildNew()).Returns(timeRepresentationFactoryProduct); //24:00:00 is represented by 1 full day in timespan representation BerlinClockTimeRepresentation timeRepresentationResult = berlinClockService.RepresentTime(new TimeSpan(1, 0, 0, 0)); Assert.IsTrue(timeRepresentationResult.TopDiode.IsOn); Assert.IsTrue(timeRepresentationResult.FirstRow.All(x => x.IsOn)); Assert.IsTrue(timeRepresentationResult.SecondRow.All(x => x.IsOn)); Assert.IsTrue(timeRepresentationResult.ThirdRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentationResult.ForthRow.All(x => !x.IsOn)); }
public void DefaultConstructorCreatedDiodesHaveCorrectColors() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); Assert.IsTrue(timeRepresentation.FirstRow.All(x => x.Color == DiodeColor.Red)); Assert.IsTrue(timeRepresentation.SecondRow.All(x => x.Color == DiodeColor.Red)); Assert.IsTrue(timeRepresentation.ForthRow.All(x => x.Color == DiodeColor.Yellow)); Assert.IsTrue(timeRepresentation.TopDiode.Color == DiodeColor.Yellow); for (int i = 0; i < 11; i++) { if (i == 2 || i == 5 || i == 8) { Assert.IsTrue(timeRepresentation.ThirdRow[i].Color == DiodeColor.Red, "3rd, 6th and 9th FiveMinuteDiodes should be red"); } else { Assert.IsTrue(timeRepresentation.ThirdRow[i].Color == DiodeColor.Yellow, "All except 3rd, 6th and 9th FiveMinuteDiodes should be yellow"); } } }
public void FiveHoursAsSetHoursInputTurnOnOneDiodeOnFirstRow() { BerlinClockTimeRepresentation timeRepresentation = new BerlinClockTimeRepresentation(); timeRepresentation.SetHours(5); for (int i = 0; i < 4; i++) { if (i == 0) { Assert.IsTrue(timeRepresentation.FirstRow[i].IsOn); } else { Assert.IsFalse(timeRepresentation.FirstRow[i].IsOn); } } Assert.IsTrue(timeRepresentation.SecondRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ThirdRow.All(x => !x.IsOn)); Assert.IsTrue(timeRepresentation.ForthRow.All(x => !x.IsOn)); }
public void InputLastSecondOfDayReturnsAllDiodeOnExecptTopAndLastOfSecondRow() { this.berlinClockFactoryMock = new Mock <IBerlineClockFactory>(); berlinClockService = new BerlineClockService(this.berlinClockFactoryMock.Object); BerlinClockTimeRepresentation timeRepresentationFactoryProduct = new BerlinClockTimeRepresentation(); this.berlinClockFactoryMock.Setup(x => x.BuildNew()).Returns(timeRepresentationFactoryProduct); BerlinClockTimeRepresentation timeRepresentationResult = berlinClockService.RepresentTime(new TimeSpan(23, 59, 59)); Assert.IsFalse(timeRepresentationResult.TopDiode.IsOn); Assert.IsTrue(timeRepresentationResult.SecondRow[0].IsOn); Assert.IsTrue(timeRepresentationResult.SecondRow[1].IsOn); Assert.IsTrue(timeRepresentationResult.SecondRow[2].IsOn); Assert.IsFalse(timeRepresentationResult.SecondRow[3].IsOn); Assert.IsTrue(timeRepresentationResult.FirstRow.All(x => x.IsOn)); Assert.IsTrue(timeRepresentationResult.ThirdRow.All(x => x.IsOn)); Assert.IsTrue(timeRepresentationResult.ForthRow.All(x => x.IsOn)); }
public BerlinClockTimeRepresentation RepresentTime(TimeSpan timeInput) { if (timeInput.TotalHours > 24.0) { throw new ArgumentException(string.Format("Hours cannot exeed 24. Got {0}", timeInput)); } BerlinClockTimeRepresentation timeRepresentation = berlinClockFactory.BuildNew(); timeRepresentation.ResetClock(); if (timeInput == OneFullDay) { timeRepresentation.SetHours(24); } else { timeRepresentation.SetHours(timeInput.Hours); } timeRepresentation.SetMinutes(timeInput.Minutes); timeRepresentation.SetSeconds(timeInput.Seconds); return(timeRepresentation); }