Avatar of freddie2025

freddie2025's solution

to Gigasecond in the C# Track

Published at Apr 09 2019 · 0 comments
Instructions
Test suite
Solution

Note:

This exercise has changed since this solution was written.

Given a moment, determine the moment that would be after a gigasecond has passed.

A gigasecond is 10^9 (1,000,000,000) seconds.

Running the tests

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

Further information

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.

Source

Chapter 9 in Chris Pine's online Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=09

GigasecondTest.cs

// 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)
    {
        int gigaSecond = 1000000000;
        return moment.AddSeconds(gigaSecond);
    }
}

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

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.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?