/** * Calculate the age in years of a person. * * @param {Person} p A Person object implementing a birth Date parameter. * @return {number} The age in years of p. */ function calculate_age(p) { let thisYear = new Date().getFullYear(); let personYear = p.birth.getFullYear(); let age = thisYear - personYear; return age; } var bertignac = { name: "Louis Bertignac", birth: new Date(1954, 01, 23) } test("Standard usage", function() { equal(calculate_age(bertignac), 63); equal(calculate_age({birth: new Date(1954, 01, 23)}), 63); }); test("Wrong type parameter", function() { throws(function() {calculate_age(1872)}, "Parameter should be an object", "Exception thrown if parameter is a number"); throws(function() {calculate_age("Something")}, "Parameter should be an object", "Exception thrown if parameter is a string"); });