Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andrii Makhota solution #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Binary file added .vs/BerlinClock/v16/.suo
Binary file not shown.
Empty file.
Binary file added .vs/BerlinClock/v16/Server/sqlite3/storage.ide
Binary file not shown.
Binary file not shown.
Binary file added .vs/BerlinClock/v16/TestStore/0/testlog.manifest
Binary file not shown.
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\HourMinutesBerlinTime.cs" />
<Compile Include="Classes\TimeStringParser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BDD\BerlinClockFeatureSteps.feature.cs">
<AutoGen>True</AutoGen>
Expand Down
55 changes: 55 additions & 0 deletions Classes/HourMinutesBerlinTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BerlinClock
{
/*
* Class for storing hours and minutes
* with support of 24:00 value
*/
class HourMinutesBerlinTime
{
private int hour = 0;
private int min = 0;

public HourMinutesBerlinTime(int aH, int aM) {
Hour = aH;
Minute = aM;
}

public int Hour {
get { return hour; }
set {
// value must be between 0 and 23 or it can be 24 if minutes value is 0
if ((value >= 0) && (value <= 23) || (value == 24) && (min == 0))
{
hour = value;
}
else {
throw new ArgumentOutOfRangeException("Hour", "Hour value must be between 0 and 23 or it can be 24 and minutes must been 0");
}
}
}
public int Minute{
get { return min; }
set {
// value must be between 0 and 59
// BUT it can be only 0 if hours value is 24
if (((value >= 0) && (value <= 59) && (hour < 24))||((hour == 24)&&(value == 0)))
{
min = value;
}
else if ((hour == 24)&&(value != 0)) {
throw new ArgumentOutOfRangeException("Minute", "If hour = 24 then minutes can be only 0");
}
else
{
throw new ArgumentOutOfRangeException("Minute", "Minute value must be between 0 and 59");
}
}
}
}
}
80 changes: 79 additions & 1 deletion Classes/TimeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,87 @@ namespace BerlinClock
{
public class TimeConverter : ITimeConverter
{
private int hours5x; // 5x hours indicator value
private int hours1x; // single hour indicator value
private int minutes5x;// 5x minute indicator value
private int minutes1x;// single minute indicator value
private bool isAM; // is now before or after midday

public string convertTime(string aTime)
{
throw new NotImplementedException();
TimeStringParser parser = new TimeStringParser();
HourMinutesBerlinTime dt = parser.GetTime(aTime);
if ((dt.Hour < 12)||
(dt.Hour == 24) // 24 is ante meridiem
) {
isAM = true;
}
else{
isAM = false;
}
hours5x = (int)Math.Floor(dt.Hour / 5.0);
hours1x = dt.Hour - hours5x * 5;

minutes5x = (int)Math.Floor(dt.Minute / 5.0);
minutes1x = dt.Minute - minutes5x * 5;
return GetTimeRepresentationString();
}
private String GetTimeRepresentationString() {
/*
* function form output string for BerlinClock
*/
String strRetValue = "";
if (isAM) {
strRetValue += "Y";
}
else
{
strRetValue += "O";
}
int i;
strRetValue += System.Environment.NewLine;
for (i = 0; i < hours5x; i ++)
{
strRetValue += "R";
}
for (; i < 4; i++)
{
strRetValue += "O";
}
strRetValue += System.Environment.NewLine;
for (i = 0; i < hours1x; i++)
{
strRetValue += "R";
}
for (; i < 4; i++)
{
strRetValue += "O";
}
strRetValue += System.Environment.NewLine;
for (i = 0; i < minutes5x; i++)
{
if ((i == 2) || (i == 5) || (i == 8))// check for quarter of hour
{
strRetValue += "R";
}
else {
strRetValue += "Y";
}
}
for (; i < 11; i++)
{
strRetValue += "O";
}
strRetValue += System.Environment.NewLine;
for (i = 0; i < minutes1x; i++)
{
strRetValue += "Y";
}
for (; i < 4; i++)
{
strRetValue += "O";
}
return strRetValue;
}
}
}
34 changes: 34 additions & 0 deletions Classes/TimeStringParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BerlinClock
{
class TimeStringParser
{
/*
* Class for parsing time input string
*/
public HourMinutesBerlinTime GetTime(string aTime) {
try
{
// trying to use standart parser
DateTime dt = DateTime.ParseExact(aTime, "HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture);
return new HourMinutesBerlinTime(dt.Hour, dt.Minute);
}
catch (FormatException exc) {
// check if string 24:00 - it is forbidden for DateTime from .Net
// but valid for BerlinClock
if (aTime.Equals("24:00:00")||aTime.Equals("24:00"))
{
return new HourMinutesBerlinTime(24, 0);
}
else {
throw exc;
}
}
}
}
}
Binary file added bin/Debug/BerlinClock.dll
Binary file not shown.
12 changes: 12 additions & 0 deletions bin/Debug/BerlinClock.dll.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<specFlow>
<unitTestProvider name="MsTest" />
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --></specFlow>
</configuration>
Binary file added bin/Debug/BerlinClock.pdb
Binary file not shown.
Binary file not shown.
Binary file added bin/Debug/TechTalk.SpecFlow.dll
Binary file not shown.
Empty file.
9 changes: 9 additions & 0 deletions obj/Debug/BerlinClock.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
D:\My Documents\GitHub\DotNetBerlinClock1\bin\Debug\BerlinClock.dll.config
D:\My Documents\GitHub\DotNetBerlinClock1\bin\Debug\BerlinClock.dll
D:\My Documents\GitHub\DotNetBerlinClock1\bin\Debug\BerlinClock.pdb
D:\My Documents\GitHub\DotNetBerlinClock1\bin\Debug\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
D:\My Documents\GitHub\DotNetBerlinClock1\bin\Debug\TechTalk.SpecFlow.dll
D:\My Documents\GitHub\DotNetBerlinClock1\obj\Debug\BerlinClock.csprojAssemblyReference.cache
D:\My Documents\GitHub\DotNetBerlinClock1\obj\Debug\BerlinClock.csproj.CopyComplete
D:\My Documents\GitHub\DotNetBerlinClock1\obj\Debug\BerlinClock.dll
D:\My Documents\GitHub\DotNetBerlinClock1\obj\Debug\BerlinClock.pdb
Binary file not shown.
Binary file added obj/Debug/BerlinClock.dll
Binary file not shown.
Binary file added obj/Debug/BerlinClock.pdb
Binary file not shown.
Binary file not shown.
Binary file added packages/SpecFlow.1.9.0/.signature.p7s
Binary file not shown.
31 changes: 31 additions & 0 deletions packages/SpecFlow.1.9.0/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
SpecFlow Licence (New BSD License)

Copyright (c) 2009, TechTalk

Disclaimer:
* The initial codebase of Specflow was written by TechTalk employees.
No 3rd party code was included.
* No code of customer projects was used to create this project.
* TechTalk had the full rights to publish the initial codebase.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the SpecFlow project nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL TECHTALK OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Binary file added packages/SpecFlow.1.9.0/SpecFlow.1.9.0.nupkg
Binary file not shown.
Loading