Given a moment, determine the moment that would be after a gigasecond has passed.
A gigasecond is 10^9 (1,000,000,000) seconds.
To run the tests, run the command dotnet test
from within the exercise directory.
Initially, only the first test will be enabled. This is to encourage you to solve the exercise one step at a time.
Once you get the first test passing, remove the Skip
property from the next test and work on getting that test passing.
Once none of the tests are skipped and they are all passing, you can submit your solution
using exercism submit Gigasecond.cs
For more detailed information about the C# track, including how to get help if you're having trouble, please visit the exercism.io C# language page.
Chapter 9 in Chris Pine's online Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=09
// This file was auto-generated based on version 2.0.0 of the canonical data.
using System;
using Xunit;
public class GigasecondTest
{
[Fact]
public void Date_only_specification_of_time()
{
Assert.Equal(new DateTime(2043, 1, 1, 1, 46, 40), Gigasecond.Add(new DateTime(2011, 4, 25)));
}
[Fact(Skip = "Remove to run test")]
public void Second_test_for_date_only_specification_of_time()
{
Assert.Equal(new DateTime(2009, 2, 19, 1, 46, 40), Gigasecond.Add(new DateTime(1977, 6, 13)));
}
[Fact(Skip = "Remove to run test")]
public void Third_test_for_date_only_specification_of_time()
{
Assert.Equal(new DateTime(1991, 3, 27, 1, 46, 40), Gigasecond.Add(new DateTime(1959, 7, 19)));
}
[Fact(Skip = "Remove to run test")]
public void Full_time_specified()
{
Assert.Equal(new DateTime(2046, 10, 2, 23, 46, 40), Gigasecond.Add(new DateTime(2015, 1, 24, 22, 0, 0)));
}
[Fact(Skip = "Remove to run test")]
public void Full_time_with_day_roll_over()
{
Assert.Equal(new DateTime(2046, 10, 3, 1, 46, 39), Gigasecond.Add(new DateTime(2015, 1, 24, 23, 59, 59)));
}
}
using System;
public static class Gigasecond
{
public static DateTime Add(DateTime moment)
{
return moment.AddSeconds(1_000_000_000);
}
}
A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.
Here are some questions to help you reflect on this solution and learn the most from it.
Level up your programming skills with 3,450 exercises across 52 languages, and insightful discussion with our volunteer team of welcoming mentors. Exercism is 100% free forever.
Sign up Learn More
Community comments