From 49f6875db51057160861a2489648d459698db6c9 Mon Sep 17 00:00:00 2001 From: "Nicholas Carrigan (he/him)" Date: Wed, 25 Nov 2020 14:22:44 -0800 Subject: [PATCH] fix(learn): ES6 Getters + Setters tests (#40238) * Strengthen tests Signed-off-by: nhcarrigan * Improve verbiage Signed-off-by: nhcarrigan * Add second check to setter test Signed-off-by: nhcarrigan --- ...tters-and-setters-to-control-access-to-an-object.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object.md index 54611ea876..3ee55a99cb 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object.md @@ -40,7 +40,7 @@ Getters and setters are important because they hide internal implementation deta ## Instructions
Use the class keyword to create a Thermostat class. The constructor accepts a Fahrenheit temperature. -Now create a getter and a setter in the class, to obtain the temperature in Celsius. +In the class, create a getter to obtain the temperature in Celsius and a setter to set the temperature in Celsius. Remember that C = 5/9 * (F - 32) and F = C * 9.0 / 5 + 32, where F is the value of temperature in Fahrenheit, and C is the value of the same temperature in Celsius. Note: When you implement this, you will track the temperature inside the class in one scale, either Fahrenheit or Celsius. This is the power of a getter and a setter. You are creating an API for another user, who can get the correct result regardless of which one you track. @@ -57,13 +57,15 @@ tests: - text: class keyword should be used. testString: assert(code.match(/class/g)); - text: Thermostat should be able to be instantiated. - testString: assert((() => {const t = new Thermostat(32);return typeof t === 'object' && t.temperature === 0;})()); + testString: assert((() => {const t = new Thermostat(122);return typeof t === 'object'})()); + - text: When instantiated with a Fahrenheit value, Thermostat should set the correct temperature. + testString: assert((() => {const t = new Thermostat(122);return t.temperature === 50})()); - text: A getter should be defined. testString: assert((() => {const desc = Object.getOwnPropertyDescriptor(Thermostat.prototype, 'temperature');return !!desc && typeof desc.get === 'function';})()); - text: A setter should be defined. testString: assert((() => {const desc = Object.getOwnPropertyDescriptor(Thermostat.prototype, 'temperature');return !!desc && typeof desc.set === 'function';})()); - - text: Calling the setter should set the temperature. - testString: assert((() => {const t = new Thermostat(32); t.temperature = 26;return t.temperature !== 0;})()); + - text: Calling the setter with a Celsius value should set the temperature. + testString: assert((() => {const t = new Thermostat(32); t.temperature = 26; const u = new Thermostat(32); u.temperature = 50; return t.temperature === 26 && u.temperature === 50;})()); ```