diff --git a/BDD/BerlinClockFeatureSteps.cs b/BDD/BerlinClockFeatureSteps.cs index 4390f3cb..6e9730dc 100644 --- a/BDD/BerlinClockFeatureSteps.cs +++ b/BDD/BerlinClockFeatureSteps.cs @@ -1,7 +1,6 @@ -using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; using TechTalk.SpecFlow; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Linq; namespace BerlinClock { @@ -23,6 +22,5 @@ public void ThenTheClockShouldLookLike(string theExpectedBerlinClockOutput) { Assert.AreEqual(berlinClock.convertTime(theTime), theExpectedBerlinClockOutput); } - } } diff --git a/BerlinClock.csproj b/BerlinClock.csproj index ac8af99d..860d9303 100644 --- a/BerlinClock.csproj +++ b/BerlinClock.csproj @@ -50,6 +50,8 @@ + + True diff --git a/Classes/Enums.cs b/Classes/Enums.cs new file mode 100644 index 00000000..7d4e19af --- /dev/null +++ b/Classes/Enums.cs @@ -0,0 +1,17 @@ +namespace BerlinClock.Classes +{ + enum LightStatus + { + Orange = 'O', + Red = 'R', + Yellow = 'Y' + } + enum Values + { + Zero = 0, + One, + Two, + Three, + Four + } +} \ No newline at end of file diff --git a/Classes/Minutes.cs b/Classes/Minutes.cs new file mode 100644 index 00000000..56245566 --- /dev/null +++ b/Classes/Minutes.cs @@ -0,0 +1,38 @@ +using System; +using System.Linq; +using System.Text; + +namespace BerlinClock.Classes +{ + internal class Minutes + { + private static readonly Int32 totalCharactersInMinutesLine1 = 11; + private static readonly Int32 fiveMinutes = 5; + private const string zeroLight = "OOOO", oneLight = "YOOO", twoLights = "YYOO", threeLights = "YYYO", fourLights = "YYYY"; + internal static StringBuilder FiveMinutesRow(Int32 totalMinutes) + { + Int32 numberOfFiveMinutes = totalMinutes / fiveMinutes; + StringBuilder fiveMinutesRow = new StringBuilder(); + for (Int32 i = 1; i <= numberOfFiveMinutes; i++) + { + fiveMinutesRow.Append(i % 3 == (Int32) Values.Zero ? (char)LightStatus.Red : (char)LightStatus.Yellow); + } + Int32 paddingEmptyCharactersCount = totalCharactersInMinutesLine1 - fiveMinutesRow.ToString().Count(); + while (paddingEmptyCharactersCount > 0) + { + fiveMinutesRow.Append((char)LightStatus.Orange); + paddingEmptyCharactersCount--; + } + fiveMinutesRow.Append(Environment.NewLine); + return fiveMinutesRow; + } + internal static StringBuilder OneMinutesRow(Int32 totalMinutes) + { + StringBuilder OneMinutesRow = new StringBuilder(); + OneMinutesRow.Append((totalMinutes % fiveMinutes == (Int32) Values.Zero) ? zeroLight : (totalMinutes % fiveMinutes == (Int32)Values.One) ? oneLight + : (totalMinutes % fiveMinutes == (Int32)Values.Two) ? twoLights : (totalMinutes % fiveMinutes == (Int32)Values.Three) ? threeLights + : (totalMinutes % fiveMinutes == (Int32)Values.Four) ? fourLights : string.Empty); + return OneMinutesRow; + } + } +} \ No newline at end of file diff --git a/Classes/TimeConverter.cs b/Classes/TimeConverter.cs index dd5bf4e0..2820704d 100644 --- a/Classes/TimeConverter.cs +++ b/Classes/TimeConverter.cs @@ -1,15 +1,60 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using BerlinClock.Classes; +using System; using System.Text; namespace BerlinClock { public class TimeConverter : ITimeConverter { - public string convertTime(string aTime) + private const char delimiter = ':'; + private Int32 totalHours; + private Int32 totalMinutes; + private Int32 totalSeconds; + private StringBuilder berlinClockBuilder; + private const Int32 fiveHours = 5; + private static readonly string zeroLight = "OOOO", oneLight = "ROOO", twoLights = "RROO", threeLights = "RRRO", fourLights = "RRRR"; + public TimeConverter() { - throw new NotImplementedException(); + berlinClockBuilder = new StringBuilder(); + } + public string convertTime(string time) + { + parseTime(time); + SecondsRow(); + FiveHoursRow(); + OneHoursRow(); + berlinClockBuilder.Append(Minutes.FiveMinutesRow(totalMinutes)); + berlinClockBuilder.Append(Minutes.OneMinutesRow(totalMinutes)); + return Convert.ToString(berlinClockBuilder); + } + + private void parseTime(string inputTime) + { + string[] splitTime = inputTime.Split(new char[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); + Int32.TryParse(splitTime[0], out totalHours); + Int32.TryParse(splitTime[1], out totalMinutes); + Int32.TryParse(splitTime[2], out totalSeconds); + } + + private void SecondsRow() + { + berlinClockBuilder.Append(totalSeconds % 2 == 0 ? (char) LightStatus.Yellow : (char) LightStatus.Orange); + berlinClockBuilder.Append(Environment.NewLine); + } + + private void FiveHoursRow() + { + berlinClockBuilder.Append((totalHours / fiveHours == (Int32) Values.Zero) ? zeroLight : (totalHours / fiveHours == (Int32) Values.One) ? oneLight + : (totalHours / fiveHours == (Int32) Values.Two) ? twoLights : (totalHours / fiveHours == (Int32) Values.Three) ? threeLights + : (totalHours / fiveHours == (Int32) Values.Four) ? fourLights : string.Empty); + berlinClockBuilder.Append(Environment.NewLine); + } + private void OneHoursRow() + { + berlinClockBuilder.Append((totalHours % fiveHours == (Int32)Values.Zero) ? zeroLight : (totalHours % fiveHours == (Int32)Values.One) ? oneLight + : (totalHours % fiveHours == (Int32)Values.Two) ? twoLights: (totalHours % fiveHours == (Int32)Values.Three) ? threeLights + : (totalHours % fiveHours == (Int32)Values.Four) ? fourLights : string.Empty); + berlinClockBuilder.Append(Environment.NewLine); } } -} +} \ No newline at end of file