diff --git a/exercises/gigasecond/.meta/hints.md b/exercises/gigasecond/.meta/hints.md new file mode 100644 index 0000000000..b6a5faca65 --- /dev/null +++ b/exercises/gigasecond/.meta/hints.md @@ -0,0 +1 @@ +It is possible to return a correct value for this exercise by mutating the solution function argument. Although there are legitimate use cases for mutating function arguments, this is usually undesirable, and in the case of this exercise, clearly unexpected. For this reason, the test suite has a test that fails in case the argument has been modified after the function execution. diff --git a/exercises/gigasecond/README.md b/exercises/gigasecond/README.md index a21a67147f..057458d03e 100644 --- a/exercises/gigasecond/README.md +++ b/exercises/gigasecond/README.md @@ -5,6 +5,9 @@ has passed. A gigasecond is 10^9 (1,000,000,000) seconds. +It is possible to return a correct value for this exercise by mutating the solution function argument. Although there are legitimate use cases for mutating function arguments, this is usually undesirable, and in the case of this exercise, clearly unexpected. For this reason, the test suite has a test that fails in case the argument has been modified after the function execution. + + ## Setup Go through the setup instructions for Javascript to install the necessary diff --git a/exercises/gigasecond/gigasecond.spec.js b/exercises/gigasecond/gigasecond.spec.js index 52991b99c4..41b110b667 100644 --- a/exercises/gigasecond/gigasecond.spec.js +++ b/exercises/gigasecond/gigasecond.spec.js @@ -35,4 +35,10 @@ describe('Gigasecond', () => { const expectedDate = new Date(Date.parse('2046-10-03T01:46:39Z')); expect(gs).toEqual(expectedDate); }); + + xtest('does not mutate the input', () => { + const input = new Date(Date.UTC(2020, 0, 4, 20, 28, 30)); + gigasecond(input); + expect(input).toEqual(new Date(Date.UTC(2020, 0, 4, 20, 28, 30))); + }); });