Skip to content

Commit 00ad491

Browse files
paparomeoSleeplessByte
authored andcommitted
[gigasecond] Add a test to check that input is not mutated (#817)
* Add a test to check that input is not mutated. * Add hint that there is a test to prevent mutation of argument.
1 parent d5cf2b1 commit 00ad491

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

exercises/gigasecond/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ has passed.
55

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

8+
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.
9+
10+
811
## Setup
912

1013
Go through the setup instructions for Javascript to install the necessary

exercises/gigasecond/gigasecond.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@ describe('Gigasecond', () => {
3535
const expectedDate = new Date(Date.parse('2046-10-03T01:46:39Z'));
3636
expect(gs).toEqual(expectedDate);
3737
});
38+
39+
xtest('does not mutate the input', () => {
40+
const input = new Date(Date.UTC(2020, 0, 4, 20, 28, 30));
41+
gigasecond(input);
42+
expect(input).toEqual(new Date(Date.UTC(2020, 0, 4, 20, 28, 30)));
43+
});
3844
});

0 commit comments

Comments
 (0)