diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..138e2ab0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vs/BerlinClock/v16 +bin/Debug +obj/Debug +packages +BerlinClock.v12.suo diff --git a/App.config b/App.config index 0f9d2230..4f07eab6 100644 --- a/App.config +++ b/App.config @@ -1,12 +1,12 @@ - - - -
- - - - - - - + + + +
+ + + + + + + \ No newline at end of file diff --git a/BDD/BerlinClockFeatureSteps.cs b/BDD/BerlinClockFeatureSteps.cs index 4390f3cb..c01fb651 100644 --- a/BDD/BerlinClockFeatureSteps.cs +++ b/BDD/BerlinClockFeatureSteps.cs @@ -1,28 +1,28 @@ -using System; -using TechTalk.SpecFlow; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Linq; - -namespace BerlinClock -{ - [Binding] - public class TheBerlinClockSteps - { - private ITimeConverter berlinClock = new TimeConverter(); - private String theTime; - - - [When(@"the time is ""(.*)""")] - public void WhenTheTimeIs(string time) - { - theTime = time; - } - - [Then(@"the clock should look like")] - public void ThenTheClockShouldLookLike(string theExpectedBerlinClockOutput) - { - Assert.AreEqual(berlinClock.convertTime(theTime), theExpectedBerlinClockOutput); - } - - } -} +using System; +using TechTalk.SpecFlow; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Linq; +using BerlinClock.Interfaces; + +namespace BerlinClock +{ + [Binding] + public class TheBerlinClockSteps + { + private ITimeConverter berlinClock = new TimeConverter(); + private String theTime; + + [When(@"the time is ""(.*)""")] + public void WhenTheTimeIs(string time) + { + theTime = time; + } + + [Then(@"the clock should look like")] + public void ThenTheClockShouldLookLike(string theExpectedBerlinClockOutput) + { + Assert.AreEqual(berlinClock.convertTime(theTime), theExpectedBerlinClockOutput); + } + + } +} diff --git a/BDD/BerlinClockFeatureSteps.feature b/BDD/BerlinClockFeatureSteps.feature index 67669587..8d17a18e 100644 --- a/BDD/BerlinClockFeatureSteps.feature +++ b/BDD/BerlinClockFeatureSteps.feature @@ -1,51 +1,51 @@ - -Feature: The Berlin Clock - As a clock enthusiast - I want to tell the time using the Berlin Clock - So that I can increase the number of ways that I can read the time - - -Scenario: Midnight 00:00 -When the time is "00:00:00" -Then the clock should look like -""" -Y -OOOO -OOOO -OOOOOOOOOOO -OOOO -""" - - -Scenario: Middle of the afternoon -When the time is "13:17:01" -Then the clock should look like -""" -O -RROO -RRRO -YYROOOOOOOO -YYOO -""" - -Scenario: Just before midnight -When the time is "23:59:59" -Then the clock should look like -""" -O -RRRR -RRRO -YYRYYRYYRYY -YYYY -""" - -Scenario: Midnight 24:00 -When the time is "24:00:00" -Then the clock should look like -""" -Y -RRRR -RRRR -OOOOOOOOOOO -OOOO -""" + +Feature: The Berlin Clock + As a clock enthusiast + I want to tell the time using the Berlin Clock + So that I can increase the number of ways that I can read the time + + +Scenario: Midnight 00:00 +When the time is "00:00:00" +Then the clock should look like +""" +Y +OOOO +OOOO +OOOOOOOOOOO +OOOO +""" + + +Scenario: Middle of the afternoon +When the time is "13:17:01" +Then the clock should look like +""" +O +RROO +RRRO +YYROOOOOOOO +YYOO +""" + +Scenario: Just before midnight +When the time is "23:59:59" +Then the clock should look like +""" +O +RRRR +RRRO +YYRYYRYYRYY +YYYY +""" + +Scenario: Midnight 24:00 +When the time is "24:00:00" +Then the clock should look like +""" +Y +RRRR +RRRR +OOOOOOOOOOO +OOOO +""" diff --git a/BDD/BerlinClockFeatureSteps.feature.cs b/BDD/BerlinClockFeatureSteps.feature.cs index 643d6539..dee22e43 100644 --- a/BDD/BerlinClockFeatureSteps.feature.cs +++ b/BDD/BerlinClockFeatureSteps.feature.cs @@ -1,142 +1,142 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by SpecFlow (http://www.specflow.org/). -// SpecFlow Version:1.9.0.77 -// SpecFlow Generator Version:1.9.0.0 -// Runtime Version:4.0.30319.34209 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -#region Designer generated code -#pragma warning disable -namespace BerlinClock.BDD -{ - using TechTalk.SpecFlow; - - - [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.9.0.77")] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()] - public partial class TheBerlinClockFeature - { - - private static TechTalk.SpecFlow.ITestRunner testRunner; - -#line 1 "BerlinClockFeatureSteps.feature" -#line hidden - - [Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute()] - public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext) - { - testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); - TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "The Berlin Clock", "As a clock enthusiast\r\n I want to tell the time using the Berlin Clock\r\n So tha" + - "t I can increase the number of ways that I can read the time", ProgrammingLanguage.CSharp, ((string[])(null))); - testRunner.OnFeatureStart(featureInfo); - } - - [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()] - public static void FeatureTearDown() - { - testRunner.OnFeatureEnd(); - testRunner = null; - } - - [Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()] - public virtual void TestInitialize() - { - if (((TechTalk.SpecFlow.FeatureContext.Current != null) - && (TechTalk.SpecFlow.FeatureContext.Current.FeatureInfo.Title != "The Berlin Clock"))) - { - BerlinClock.BDD.TheBerlinClockFeature.FeatureSetup(null); - } - } - - [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()] - public virtual void ScenarioTearDown() - { - testRunner.OnScenarioEnd(); - } - - public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) - { - testRunner.OnScenarioStart(scenarioInfo); - } - - public virtual void ScenarioCleanup() - { - testRunner.CollectScenarioErrors(); - } - - [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] - [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Midnight 00:00")] - [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "The Berlin Clock")] - public virtual void Midnight0000() - { - TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Midnight 00:00", ((string[])(null))); -#line 8 -this.ScenarioSetup(scenarioInfo); -#line 9 -testRunner.When("the time is \"00:00:00\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); -#line hidden -#line 10 -testRunner.Then("the clock should look like", "Y\r\nOOOO\r\nOOOO\r\nOOOOOOOOOOO\r\nOOOO", ((TechTalk.SpecFlow.Table)(null)), "Then "); -#line hidden - this.ScenarioCleanup(); - } - - [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] - [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Middle of the afternoon")] - [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "The Berlin Clock")] - public virtual void MiddleOfTheAfternoon() - { - TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Middle of the afternoon", ((string[])(null))); -#line 20 -this.ScenarioSetup(scenarioInfo); -#line 21 -testRunner.When("the time is \"13:17:01\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); -#line hidden -#line 22 -testRunner.Then("the clock should look like", "O\r\nRROO\r\nRRRO\r\nYYROOOOOOOO\r\nYYOO", ((TechTalk.SpecFlow.Table)(null)), "Then "); -#line hidden - this.ScenarioCleanup(); - } - - [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] - [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Just before midnight")] - [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "The Berlin Clock")] - public virtual void JustBeforeMidnight() - { - TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Just before midnight", ((string[])(null))); -#line 31 -this.ScenarioSetup(scenarioInfo); -#line 32 -testRunner.When("the time is \"23:59:59\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); -#line hidden -#line 33 -testRunner.Then("the clock should look like", "O\r\nRRRR\r\nRRRO\r\nYYRYYRYYRYY\r\nYYYY", ((TechTalk.SpecFlow.Table)(null)), "Then "); -#line hidden - this.ScenarioCleanup(); - } - - [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] - [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Midnight 24:00")] - [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "The Berlin Clock")] - public virtual void Midnight2400() - { - TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Midnight 24:00", ((string[])(null))); -#line 42 -this.ScenarioSetup(scenarioInfo); -#line 43 -testRunner.When("the time is \"24:00:00\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); -#line hidden -#line 44 -testRunner.Then("the clock should look like", "Y\r\nRRRR\r\nRRRR\r\nOOOOOOOOOOO\r\nOOOO", ((TechTalk.SpecFlow.Table)(null)), "Then "); -#line hidden - this.ScenarioCleanup(); - } - } -} -#pragma warning restore -#endregion +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:1.9.0.77 +// SpecFlow Generator Version:1.9.0.0 +// Runtime Version:4.0.30319.34209 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace BerlinClock.BDD +{ + using TechTalk.SpecFlow; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.9.0.77")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()] + public partial class TheBerlinClockFeature + { + + private static TechTalk.SpecFlow.ITestRunner testRunner; + +#line 1 "BerlinClockFeatureSteps.feature" +#line hidden + + [Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute()] + public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext) + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "The Berlin Clock", "As a clock enthusiast\r\n I want to tell the time using the Berlin Clock\r\n So tha" + + "t I can increase the number of ways that I can read the time", ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()] + public static void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()] + public virtual void TestInitialize() + { + if (((TechTalk.SpecFlow.FeatureContext.Current != null) + && (TechTalk.SpecFlow.FeatureContext.Current.FeatureInfo.Title != "The Berlin Clock"))) + { + BerlinClock.BDD.TheBerlinClockFeature.FeatureSetup(null); + } + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()] + public virtual void ScenarioTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioStart(scenarioInfo); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Midnight 00:00")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "The Berlin Clock")] + public virtual void Midnight0000() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Midnight 00:00", ((string[])(null))); +#line 8 +this.ScenarioSetup(scenarioInfo); +#line 9 +testRunner.When("the time is \"00:00:00\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 10 +testRunner.Then("the clock should look like", "Y\r\nOOOO\r\nOOOO\r\nOOOOOOOOOOO\r\nOOOO", ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Middle of the afternoon")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "The Berlin Clock")] + public virtual void MiddleOfTheAfternoon() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Middle of the afternoon", ((string[])(null))); +#line 20 +this.ScenarioSetup(scenarioInfo); +#line 21 +testRunner.When("the time is \"13:17:01\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 22 +testRunner.Then("the clock should look like", "O\r\nRROO\r\nRRRO\r\nYYROOOOOOOO\r\nYYOO", ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Just before midnight")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "The Berlin Clock")] + public virtual void JustBeforeMidnight() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Just before midnight", ((string[])(null))); +#line 31 +this.ScenarioSetup(scenarioInfo); +#line 32 +testRunner.When("the time is \"23:59:59\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 33 +testRunner.Then("the clock should look like", "O\r\nRRRR\r\nRRRO\r\nYYRYYRYYRYY\r\nYYYY", ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Midnight 24:00")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "The Berlin Clock")] + public virtual void Midnight2400() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Midnight 24:00", ((string[])(null))); +#line 42 +this.ScenarioSetup(scenarioInfo); +#line 43 +testRunner.When("the time is \"24:00:00\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 44 +testRunner.Then("the clock should look like", "Y\r\nRRRR\r\nRRRR\r\nOOOOOOOOOOO\r\nOOOO", ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/BerlinClock.csproj b/BerlinClock.csproj index ac8af99d..6a80b188 100644 --- a/BerlinClock.csproj +++ b/BerlinClock.csproj @@ -1,81 +1,85 @@ - - - - - Debug - AnyCPU - {0451204D-BF86-43E1-B560-FC9AC830B9A9} - Library - Properties - BerlinClock - BerlinClock - v4.5 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - packages\SpecFlow.1.9.0\lib\net35\TechTalk.SpecFlow.dll - True - - - - - - - True - True - BerlinClockFeatureSteps.feature - - - - - - - - - SpecFlowSingleFileGenerator - BerlinClockFeatureSteps.feature.cs - - - - - - - + + + + + Debug + AnyCPU + {0451204D-BF86-43E1-B560-FC9AC830B9A9} + Library + Properties + BerlinClock + BerlinClock + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + packages\SpecFlow.1.9.0\lib\net35\TechTalk.SpecFlow.dll + True + + + + + + + + + + + True + True + BerlinClockFeatureSteps.feature + + + + + + + + + SpecFlowSingleFileGenerator + BerlinClockFeatureSteps.feature.cs + + + + + + + \ No newline at end of file diff --git a/BerlinClock.sln b/BerlinClock.sln index 082911a2..636b4306 100644 --- a/BerlinClock.sln +++ b/BerlinClock.sln @@ -1,22 +1,25 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BerlinClock", "BerlinClock.csproj", "{0451204D-BF86-43E1-B560-FC9AC830B9A9}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0451204D-BF86-43E1-B560-FC9AC830B9A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0451204D-BF86-43E1-B560-FC9AC830B9A9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0451204D-BF86-43E1-B560-FC9AC830B9A9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0451204D-BF86-43E1-B560-FC9AC830B9A9}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BerlinClock", "BerlinClock.csproj", "{0451204D-BF86-43E1-B560-FC9AC830B9A9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0451204D-BF86-43E1-B560-FC9AC830B9A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0451204D-BF86-43E1-B560-FC9AC830B9A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0451204D-BF86-43E1-B560-FC9AC830B9A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0451204D-BF86-43E1-B560-FC9AC830B9A9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DE05EE45-B0EC-4DC3-9009-A5D82ABD1BA3} + EndGlobalSection +EndGlobal diff --git a/Classes/HourServices.cs b/Classes/HourServices.cs new file mode 100644 index 00000000..882ba758 --- /dev/null +++ b/Classes/HourServices.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BerlinClock.Classes +{ + /// + /// responsabilities of hour in clock + /// + public static class HourServices + { + /// + /// Simple validation of hour range returning a bool + /// + /// + /// + public static bool IsValid(int hour) + { + bool valid = false; + + if ((hour >= 0) && (hour < 25)) + { + valid = true; + } + + return valid; + } + } +} diff --git a/Classes/ITimeConverter.cs b/Classes/Interfaces/ITimeConverter.cs similarity index 80% rename from Classes/ITimeConverter.cs rename to Classes/Interfaces/ITimeConverter.cs index 1d9e4c27..b0ed5373 100644 --- a/Classes/ITimeConverter.cs +++ b/Classes/Interfaces/ITimeConverter.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace BerlinClock -{ - public interface ITimeConverter - { - String convertTime(String aTime); - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BerlinClock.Interfaces +{ + public interface ITimeConverter + { + String convertTime(String aTime); + } +} diff --git a/Classes/SecondServices.cs b/Classes/SecondServices.cs new file mode 100644 index 00000000..ad85af2e --- /dev/null +++ b/Classes/SecondServices.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BerlinClock.Classes +{ + /// + /// Responsabilities of abstract time + /// + public static class SecondServices + { + /// + /// Simple validation of second/minute range returning a bool + /// + /// + /// + public static bool IsValid(int second) + { + bool valid = false; + + if ((second >= 0) && (second < 60)) + { + valid = true; + } + + return valid; + } + } +} diff --git a/Classes/TimeConverter.cs b/Classes/TimeConverter.cs index dd5bf4e0..0b355104 100644 --- a/Classes/TimeConverter.cs +++ b/Classes/TimeConverter.cs @@ -1,15 +1,64 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace BerlinClock -{ - public class TimeConverter : ITimeConverter - { - public string convertTime(string aTime) - { - throw new NotImplementedException(); - } - } -} +using BerlinClock.Classes; +using BerlinClock.Interfaces; +using BerlinClock.Model; +using System; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace BerlinClock +{ + public class TimeConverter : ITimeConverter + { + public string convertTime(string aTime) + { + if (!string.IsNullOrEmpty(ValidateInput(aTime))) + { + return "Problem with input! pattern example 00:00:00"; + } + + BerlinUhr oClock = new BerlinUhr(aTime); + + return oClock.BuildUpBerlinClock(); + } + + /// + /// method to validate input before procede to Clock + /// + /// + /// + private string ValidateInput(string aTime) + { + StringBuilder valid = new StringBuilder("Invalid Input:"); + bool validReturn = true; + int expectedLength = 8; + var numberSeparators = Regex.Matches(aTime, ":").Count; + + try + { + if (aTime.Length != expectedLength) + { + validReturn = false; + valid.AppendLine(string.Format("different string length than expected: Expected = {0}, Length{1}", expectedLength, aTime.Length)); + } + else if (numberSeparators != 2) + { + validReturn = false; + valid.AppendLine(string.Format("separator are different of two, input: {0}", aTime)); + } + } + catch (Exception e) + { + validReturn = false; + valid.AppendLine("Exception Problem !"); + } + + if (validReturn) + { + return ""; + } + + return valid.ToString(); + } + } +} diff --git a/Model/BerlinUhr.cs b/Model/BerlinUhr.cs new file mode 100644 index 00000000..64a7bef0 --- /dev/null +++ b/Model/BerlinUhr.cs @@ -0,0 +1,187 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BerlinClock.Model +{ + /// + /// Represents a clock in berlin with clock inheritance + /// + public class BerlinUhr : Clock + { + public BerlinUhr(string aTime = "00:00:00") + { + StringToClock(aTime); + } + + /// + /// Represents top of clock the first lamp yellow, blinks every two seconds + /// + public string YellowLed + { + get { return FirstSecondRow(Second); } + } + + /// + /// the top of clock represents the hours in the top row with 4 red lamps in every 5 hour + /// + public string FiveHourRow + { + get { return FirstHourRow(Hour); } + } + + /// + /// the top of clock represents the hours in the lower of row with 4 red lamps in every 1 hour + /// + public string OneHourRow + { + get { return SecondHourRow(Hour); } + } + + /// + /// the bottom of clock represents the minutes containing 11 lamps in yellow with each 5 minutes. + /// the 3rd, 6th and 9th lamp are red and indicate the first quarter, half and last quarter of an hour + /// + public string FiveMinuteRow + { + get { return FirstMinuteRow(Minute); } + } + + /// + /// In the last row with 4 lamps every lamp represents 1 minute in yellow + /// + public string OneMinuteRow + { + get { return SecondMinuteRow(Minute); } + } + + /// + /// method to return time formatted in correct order in string representating leds and colors + /// + /// + public string BuildUpBerlinClock() + { + StringBuilder stringBerlinTimeString = new StringBuilder(); + + stringBerlinTimeString.AppendLine(YellowLed); + stringBerlinTimeString.AppendLine(FiveHourRow); + stringBerlinTimeString.AppendLine(OneHourRow); + stringBerlinTimeString.AppendLine(FiveMinuteRow); + stringBerlinTimeString.Append(OneMinuteRow); + + return stringBerlinTimeString.ToString(); + } + + #region Private Methods + + /// + /// return Yellow Lamp status in second + /// + /// + /// + private string FirstSecondRow(int second) + { + string ledOn = "O"; + + if (YellowOn(second)) + { + ledOn = "Y"; + } + + return ledOn; + } + + /// + /// algorithm to return number of lamps + /// + /// + /// + private string FirstHourRow(int hour) + { + double rowLamp = hour / 5; + return HourRow(rowLamp); + } + + /// + /// algorithm to return number of lamps + /// + /// + /// + private string SecondHourRow(int hour) + { + double minute = hour % 10; + return HourRow(minute, 4, "R"); + } + + /// + /// algorithm to return number of lamps + /// + /// + /// + private string FirstMinuteRow(int minute) + { + double rowLamp = minute / 5; + return HourRow(rowLamp, 11, "Y"); + } + + /// + /// algorithm to return number of lamps + /// + /// + /// + private string SecondMinuteRow(int minute) + { + double rowLamp1 = minute / 5; + double timelamp = rowLamp1 * 5; + double rowLamp = Math.Abs(timelamp - minute); + return HourRow(rowLamp, 4, "Y"); + } + + /// + /// Yellow lamp algorithm + /// + /// + /// + private bool YellowOn(int second) + { + return (second % 2) == 0; + } + + /// + /// clock algorithm to return switched led + /// + /// number of lamps + /// return of lamps + /// color of lightned lamp + /// + private string HourRow(double value, int led = 4, string ledColor = "R") + { + StringBuilder stringRow = new StringBuilder(); + + for (int i = 1; i <= led; i++) + { + string ledOn = "O"; + bool ledQuarter = (i % 3 == 0); + + if (value >= i) + { + if (ledQuarter && ledColor != "R" && led > 4) + { + ledOn = "R"; + } + else + { + ledOn = ledColor; + } + } + + stringRow.Append(ledOn); + } + + return stringRow.ToString(); + } + #endregion + } +} diff --git a/Model/Clock.cs b/Model/Clock.cs new file mode 100644 index 00000000..87e87cf7 --- /dev/null +++ b/Model/Clock.cs @@ -0,0 +1,99 @@ +using BerlinClock.Classes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BerlinClock.Model +{ + /// + /// class with integer properties Hour, Minute and Second + /// + public class Clock + { + private int _hour; + private int _minute; + private int _second; + + /// + /// Represent hour from 0 to 24 + /// + public int Hour + { + get + { + return _hour; + } + set + { + if ((value >= 0) && (value < 25)) + { + _hour = value; + } + } + } + + /// + /// Represent minute from 0 to 59 + /// + public int Minute + { + get + { + return _minute; + } + set + { + if ((value >= 0) && (value < 60)) + { + _minute = value; + } + } + } + + /// + /// Represent second from 0 to 59 + /// + public int Second + { + get + { + return _second; + } + set + { + if ((value >= 0) && (value < 60)) + { + _second = value; + } + } + } + + public bool IsValid() + { + return HourServices.IsValid(Hour) && SecondServices.IsValid(Minute) && SecondServices.IsValid(Second); + } + + /// + /// convert time 00:00:00 in string to model object Clock{Hour, Minute, Second} + /// + /// + public void StringToClock(string aTime) + { + var separator = ':'; + + List listNumber = new List(); + foreach (var interString in aTime.Split(separator)) + { + int number; + if (Int32.TryParse(interString, out number)) + listNumber.Add(number); + } + + Hour = listNumber[0]; + Minute = listNumber[1]; + Second = listNumber[2]; + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 749ff5ef..ccd74f8a 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("BerlinClock")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("TEST COMPANY")] -[assembly: AssemblyProduct("BerlinClock")] -[assembly: AssemblyCopyright("Copyright © TEST COMPANY 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("556c4a6c-4bcd-4244-93ba-0d609facaf49")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("BerlinClock")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("TEST COMPANY")] +[assembly: AssemblyProduct("BerlinClock")] +[assembly: AssemblyCopyright("Copyright © TEST COMPANY 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("556c4a6c-4bcd-4244-93ba-0d609facaf49")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Readme.md b/Readme.md index 2fc6f6bb..bc2d8d2f 100644 --- a/Readme.md +++ b/Readme.md @@ -1,34 +1,34 @@ -# The Berlin Clock - -The Berlin Uhr (Clock) is a rather strange way to show the time. On the top of the clock there is a yellow lamp that -blinks on/off every two seconds. The time is calculated by adding rectangular lamps. - -The top two rows of lamps are red. These indicate the hours of a day. In the top row there are 4 red lamps. Every lamp -represents 5 hours. In the lower row of red lamps every lamp represents 1 hour. So if two lamps of the first row and -three of the second row are switched on that indicates 5+5+3=13h or 1 pm. - -The two rows of lamps at the bottom count the minutes. The first of these rows has 11 lamps, the second 4. In the -first row every lamp represents 5 minutes. In this first row the 3rd, 6th and 9th lamp are red and indicate the first -quarter, half and last quarter of an hour. The other lamps are yellow. In the last row with 4 lamps every lamp -represents 1 minute. - -One can be seen [here](http://uniqueclocks.co.uk/media/berlin~clock.jpg~1.gif) - -## The brief - -We have created a number of acceptance tests for the Berlin Clock and your challenge is to get them passing. - -## Some hints -ensure that your machine has visual studio (we used 2013), and the following 2 extensions: 1) Nuget 2) 'specflow for visual studio 2013' (or appropriate). These can be installed under menu tools, Extensions and updates. - -The exercise contains an un-implemented Specflow BDD test (see http://www.specflow.org/getting-started/). The use of BDD in this instance is to provide you with our definition of done for the task. - -Please ensure that you are familiar with our values in the instructions project. They are important to us. - -* simple, elegant code that reads like a narrative -* thinking about the code more than the writing of the code (we spend a lot of time thinking/debating about what we are writing) -* transparency and feedback to support continuous learning -* excellent testing that acts as documentation for the code -* challenging boundaries where necessary - - +# The Berlin Clock + +The Berlin Uhr (Clock) is a rather strange way to show the time. On the top of the clock there is a yellow lamp that +blinks on/off every two seconds. The time is calculated by adding rectangular lamps. + +The top two rows of lamps are red. These indicate the hours of a day. In the top row there are 4 red lamps. Every lamp +represents 5 hours. In the lower row of red lamps every lamp represents 1 hour. So if two lamps of the first row and +three of the second row are switched on that indicates 5+5+3=13h or 1 pm. + +The two rows of lamps at the bottom count the minutes. The first of these rows has 11 lamps, the second 4. In the +first row every lamp represents 5 minutes. In this first row the 3rd, 6th and 9th lamp are red and indicate the first +quarter, half and last quarter of an hour. The other lamps are yellow. In the last row with 4 lamps every lamp +represents 1 minute. + +One can be seen [here](http://uniqueclocks.co.uk/media/berlin~clock.jpg~1.gif) + +## The brief + +We have created a number of acceptance tests for the Berlin Clock and your challenge is to get them passing. + +## Some hints +ensure that your machine has visual studio (we used 2013), and the following 2 extensions: 1) Nuget 2) 'specflow for visual studio 2013' (or appropriate). These can be installed under menu tools, Extensions and updates. + +The exercise contains an un-implemented Specflow BDD test (see http://www.specflow.org/getting-started/). The use of BDD in this instance is to provide you with our definition of done for the task. + +Please ensure that you are familiar with our values in the instructions project. They are important to us. + +* simple, elegant code that reads like a narrative +* thinking about the code more than the writing of the code (we spend a lot of time thinking/debating about what we are writing) +* transparency and feedback to support continuous learning +* excellent testing that acts as documentation for the code +* challenging boundaries where necessary + + diff --git a/packages.config b/packages.config index c6658054..080f8954 100644 --- a/packages.config +++ b/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file