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
134 changes: 134 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.svclog
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml
*.azurePubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
packages/
## TODO: If the tool you use requires repositories.config, also uncomment the next line
!packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
![Ss]tyle[Cc]op.targets
~$*
*~
*.dbmdl
*.[Pp]ublish.xml

*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

# =========================
# Windows detritus
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

_NCrunch*
/.vs
20 changes: 11 additions & 9 deletions BDD/BerlinClockFeatureSteps.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
using System;
using TechTalk.SpecFlow;
using BerlinClock.Classes;
using BerlinClock.Classes.BusinessLogic;
using BerlinClock.Classes.Input;
using BerlinClock.Classes.Output;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using TechTalk.SpecFlow;

namespace BerlinClock
{
[Binding]
public class TheBerlinClockSteps
{
private ITimeConverter berlinClock = new TimeConverter();
private String theTime;
private readonly ITimeConverter _berlinClock = new TimeConverter(new TimeParser(), new MatrixConverter(), new MatrixPrinter());
private string _theTime;



[When(@"the time is ""(.*)""")]
public void WhenTheTimeIs(string time)
{
theTime = time;
_theTime = time;
}

[Then(@"the clock should look like")]
public void ThenTheClockShouldLookLike(string theExpectedBerlinClockOutput)
{
Assert.AreEqual(berlinClock.convertTime(theTime), theExpectedBerlinClockOutput);
Assert.AreEqual(theExpectedBerlinClockOutput, _berlinClock.ConvertTime(_theTime));
}

}
Expand Down
11 changes: 11 additions & 0 deletions BerlinClock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BDD\BerlinClockFeatureSteps.cs" />
<Compile Include="Classes\BusinessLogic\IMatrixConverter.cs" />
<Compile Include="Classes\BusinessLogic\LampMatrix.cs" />
<Compile Include="Classes\BusinessLogic\Lamps\Lamp.cs" />
<Compile Include="Classes\BusinessLogic\Lamps\RedLamp.cs" />
<Compile Include="Classes\BusinessLogic\Lamps\YellowLamp.cs" />
<Compile Include="Classes\BusinessLogic\MatrixConverter.cs" />
<Compile Include="Classes\Input\ITimeParser.cs" />
<Compile Include="Classes\Input\TimeParser.cs" />
<Compile Include="Classes\Output\IMatrixPrinter.cs" />
<Compile Include="Classes\Output\MatrixPrinter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BDD\BerlinClockFeatureSteps.feature.cs">
<AutoGen>True</AutoGen>
Expand All @@ -70,6 +80,7 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
9 changes: 9 additions & 0 deletions Classes/BusinessLogic/IMatrixConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace BerlinClock.Classes.BusinessLogic
{
public interface IMatrixConverter
{
LampMatrix FromTimeSpan(TimeSpan time);
}
}
61 changes: 61 additions & 0 deletions Classes/BusinessLogic/LampMatrix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BerlinClock.Classes.BusinessLogic.Lamps;

namespace BerlinClock.Classes.BusinessLogic
{
public class LampMatrix
{
/// <summary>
/// Lamp that is on the top of the clock
/// that blinks on/off every two seconds.
/// </summary>
public Lamp OddSecondsLamp => Rows[0][0];

public IEnumerable<Lamp[]> TimeIndicatorLampRows => Rows.Skip(1);

public Lamp[][] Rows { get; } =
{
new Lamp[]
{
new YellowLamp(TimeSpan.Zero),
},
new Lamp[]
{
new RedLamp(TimeSpan.FromHours(5)),
new RedLamp(TimeSpan.FromHours(5)),
new RedLamp(TimeSpan.FromHours(5)),
new RedLamp(TimeSpan.FromHours(5)),
},
new Lamp[]
{
new RedLamp(TimeSpan.FromHours(1)),
new RedLamp(TimeSpan.FromHours(1)),
new RedLamp(TimeSpan.FromHours(1)),
new RedLamp(TimeSpan.FromHours(1)),
},
new Lamp[]
{
new YellowLamp(TimeSpan.FromMinutes(5)),
new YellowLamp(TimeSpan.FromMinutes(5)),
new RedLamp(TimeSpan.FromMinutes(5)),
new YellowLamp(TimeSpan.FromMinutes(5)),
new YellowLamp(TimeSpan.FromMinutes(5)),
new RedLamp(TimeSpan.FromMinutes(5)),
new YellowLamp(TimeSpan.FromMinutes(5)),
new YellowLamp(TimeSpan.FromMinutes(5)),
new RedLamp(TimeSpan.FromMinutes(5)),
new YellowLamp(TimeSpan.FromMinutes(5)),
new YellowLamp(TimeSpan.FromMinutes(5)),
},
new Lamp[]
{
new YellowLamp(TimeSpan.FromMinutes(1)),
new YellowLamp(TimeSpan.FromMinutes(1)),
new YellowLamp(TimeSpan.FromMinutes(1)),
new YellowLamp(TimeSpan.FromMinutes(1))
},
};
}
}
35 changes: 35 additions & 0 deletions Classes/BusinessLogic/Lamps/Lamp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace BerlinClock.Classes.BusinessLogic.Lamps
{
public abstract class Lamp
{
public const string DisabledLampSign = "O";

/// <summary>
/// Time duration of the Lamp
/// </summary>
public TimeSpan Time { get; }

/// <summary>
/// Color of turned ON lamp
/// </summary>
public string Color { get; }

/// <summary>
/// Is lamp turned ON
/// </summary>
public bool Enabled { get; set; } = false;

/// <summary>
/// Effective Lamp Sign
/// </summary>
public string LampSign => Enabled ? Color : DisabledLampSign;

protected Lamp(TimeSpan time, string color)
{
Time = time;
Color = color;
}
}
}
11 changes: 11 additions & 0 deletions Classes/BusinessLogic/Lamps/RedLamp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace BerlinClock.Classes.BusinessLogic.Lamps
{
public class RedLamp : Lamp
{
public RedLamp(TimeSpan time) : base(time, "R")
{
}
}
}
11 changes: 11 additions & 0 deletions Classes/BusinessLogic/Lamps/YellowLamp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace BerlinClock.Classes.BusinessLogic.Lamps
{
public class YellowLamp : Lamp
{
public YellowLamp(TimeSpan time) : base(time, "Y")
{
}
}
}
39 changes: 39 additions & 0 deletions Classes/BusinessLogic/MatrixConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using BerlinClock.Classes.BusinessLogic.Lamps;
using System;

namespace BerlinClock.Classes.BusinessLogic
{
public class MatrixConverter : IMatrixConverter
{
public LampMatrix FromTimeSpan(TimeSpan time)
{
var matrix = new LampMatrix();
matrix.OddSecondsLamp.Enabled = IsBlinking(time);

foreach (var rowLamps in matrix.TimeIndicatorLampRows)
{
foreach (var lamp in rowLamps)
{
if (ShouldEnableLamp(time, lamp))
{
time = EnableLamp(time, lamp);
}
}
}

return matrix;
}

private static TimeSpan EnableLamp(TimeSpan time, Lamp lamp)
{
time -= lamp.Time;
lamp.Enabled = true;

return time;
}

private static bool ShouldEnableLamp(TimeSpan time, Lamp lamp) => time - lamp.Time >= TimeSpan.Zero;

private static bool IsBlinking(TimeSpan time) => time.Seconds % 2 == 0;
}
}
11 changes: 3 additions & 8 deletions Classes/ITimeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BerlinClock
namespace BerlinClock.Classes
{
public interface ITimeConverter
{
String convertTime(String aTime);
string ConvertTime(string aTime);
}
}
}
Loading