Skip to content

Instantly share code, notes, and snippets.

@VisualBean
Created October 6, 2020 11:05
Show Gist options
  • Save VisualBean/cd3b5bb55e0f0bfbd30f9cc4e7ac86df to your computer and use it in GitHub Desktop.
Save VisualBean/cd3b5bb55e0f0bfbd30f9cc4e7ac86df to your computer and use it in GitHub Desktop.
public class Time
{
private int seconds;
private Time(int seconds)
{
this.seconds = seconds;
}
public static Time Hours(int n)
{
return new Time(n * 60 * 60);
}
public static Time Minutes(int n)
{
return new Time(n * 60);
}
public static Time Seconds(int n)
{
return new Time(n);
}
public int InMiliseconds()
{
return seconds * 1000;
}
public int InSeconds()
{
return seconds;
}
public int InMinutes()
{
return seconds / 60;
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void Test()
{
Assert.IsTrue(Time.Hours(1).InMiliseconds() == Time.Minutes(60).InMiliseconds(), "1 hour should be the same as 60 minutes");
Assert.IsTrue(Time.Minutes(60).InMiliseconds() == Time.Seconds(3600).InMiliseconds(), "60 minutes should be the same as 3600 seconds");
Assert.IsTrue(Time.Seconds(60).InSeconds() == 60, "60 seconds should be 60 seconds");
Assert.IsTrue(Time.Minutes(1).InSeconds() == 60, "1 minute should be 60 seconds");
Assert.IsTrue(Time.Hours(1).InMiliseconds() == 3_600_000, "1 hour should be 3.600.000 miliseconds");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment