From 8abfbfc24e9ad9e5c1d9112af576824b3e3eb5e3 Mon Sep 17 00:00:00 2001 From: Pedro Romano Date: Sat, 4 Jan 2020 20:40:22 +0000 Subject: [PATCH 1/2] Add a test to check that input is not mutated. --- exercises/gigasecond/gigasecond.spec.js | 6 ++++++ 1 file changed, 6 insertions(+) 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))); + }); }); From d12c6cda2f74c5edb03b520178d1a609223fbd16 Mon Sep 17 00:00:00 2001 From: Pedro Romano Date: Wed, 8 Jan 2020 22:01:18 +0000 Subject: [PATCH 2/2] Add hint that there is a test to prevent mutation of argument. --- exercises/gigasecond/.meta/hints.md | 1 + exercises/gigasecond/README.md | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 exercises/gigasecond/.meta/hints.md 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