Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions BDD/BerlinClockFeatureSteps.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -23,6 +22,5 @@ public void ThenTheClockShouldLookLike(string theExpectedBerlinClockOutput)
{
Assert.AreEqual(berlinClock.convertTime(theTime), theExpectedBerlinClockOutput);
}

}
}
2 changes: 2 additions & 0 deletions BerlinClock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BDD\BerlinClockFeatureSteps.cs" />
<Compile Include="Classes\Enums.cs" />
<Compile Include="Classes\Minutes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BDD\BerlinClockFeatureSteps.feature.cs">
<AutoGen>True</AutoGen>
Expand Down
17 changes: 17 additions & 0 deletions Classes/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace BerlinClock.Classes
{
enum LightStatus
{
Orange = 'O',
Red = 'R',
Yellow = 'Y'
}
enum Values
{
Zero = 0,
One,
Two,
Three,
Four
}
}
38 changes: 38 additions & 0 deletions Classes/Minutes.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
57 changes: 51 additions & 6 deletions Classes/TimeConverter.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}