Testing the Easter program—part 1
Before improving the main code, it's important to have automated tests
I’m going to experiment with the Gauss Easter program by trying to make it understandable without comments and without needing to explain it. Before that, I need to write some tests.
The problem is I will be changing the code. How will I know I haven’t broken something? By going to the web interface and trying it out? This would be tedious and wouldn’t work well. Instead, I wrote a few automated tests. All I do now is enter a command on my terminal. It runs the tests, and after two seconds it tells me they passed.
Here are the tests, which you can probably understand easily even if you don’t know this language:
test('earliest possible date', () => {
expect(getEasterDate(1598)).toEqual([3, 22]);
});
test('latest possible date', () => {
expect(getEasterDate(1666)).toEqual([4, 25]);
});
test('19 April special case where d = 29 and e = 6', () => {
expect(getEasterDate(1609)).toEqual([4, 19]);
});
test('non-special 19 April', () => {
expect(getEasterDate(1615)).toEqual([4, 19]);
});
test('18 April special case where d = 28 and e = 6 and more', () => {
expect(getEasterDate(1954)).toEqual([4, 18]);
});
test('non-special 18 April', () => {
expect(getEasterDate(1965)).toEqual([4, 18]);
});
test('correct p', () => {
expect(getEasterDate(4200)).toEqual([4, 20]);
});