From 67b77e27db4e747f87ae51f3a29f2ef13e06abc5 Mon Sep 17 00:00:00 2001 From: Luis Mauro Martinez Baez Date: Thu, 26 Oct 2017 17:36:56 -0500 Subject: [PATCH 1/3] Changes tests in order to be useful --- lib/convertInchesToCentimeters.js | 2 +- test/convertInchesToCentimeters.test.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/convertInchesToCentimeters.js b/lib/convertInchesToCentimeters.js index c449060f..73b04bab 100644 --- a/lib/convertInchesToCentimeters.js +++ b/lib/convertInchesToCentimeters.js @@ -5,7 +5,7 @@ */ function convertInchesToCentimeters(inches){ //Code goes here - throw new Error("Invalid Argument"); + throw new Error("Invalid Type"); } module.exports = convertInchesToCentimeters; diff --git a/test/convertInchesToCentimeters.test.js b/test/convertInchesToCentimeters.test.js index 562abbdf..b703daf0 100644 --- a/test/convertInchesToCentimeters.test.js +++ b/test/convertInchesToCentimeters.test.js @@ -1,15 +1,18 @@ const { convertInchesToCentimeters } = require("../lib"); describe("convertInchesToCentimeters", () => { - it("Should return converted inches to centimeters", () => { - expect(() => convertInchesToCentimeters(5).toBe(12.7000254000508)); - expect(() => convertInchesToCentimeters(7).toBe(17.78003556007112)); - // add more cases + test("5 inches is 12.7000254000508 cm", () => { + expect(convertInchesToCentimeters(5)).toBe(12.7000254000508); }); - it("Should check if parameter is valid", () => { - expect(() => convertInchesToCentimeters({})).toThrow("Invalid Argument"); - expect(() => convertInchesToCentimeters([1,2])).toThrow("Invalid Argument"); - // add more cases + test("7 inches is 17.78003556007112 cm", () => { + expect(convertInchesToCentimeters(7)).toBe(12.78003556007112); + }); + + test("Throw error on invalid type", () => { + expect(() => convertInchesToCentimeters("a inch")).toThrow("Invalid Type"); + expect(() => convertInchesToCentimeters(null)).toThrow("Invalid Type"); + expect(() => convertInchesToCentimeters(undefined)).toThrow("Invalid Type"); + expect(() => convertInchesToCentimeters({})).toThrow("Invalid Type"); }); }); From 7408d3ef6cd39c0e2f836bad9b7f61a188d65530 Mon Sep 17 00:00:00 2001 From: Luis Mauro Martinez Baez Date: Thu, 26 Oct 2017 17:52:51 -0500 Subject: [PATCH 2/3] Fix convertInchesToCentimeters --- lib/convertInchesToCentimeters.js | 9 ++++++--- test/convertInchesToCentimeters.test.js | 12 ++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/convertInchesToCentimeters.js b/lib/convertInchesToCentimeters.js index 73b04bab..4ba027be 100644 --- a/lib/convertInchesToCentimeters.js +++ b/lib/convertInchesToCentimeters.js @@ -1,11 +1,14 @@ /** -* Convert inches to centimeters +* Convert inches to centimeters where 1 inch equals 2.54 cm * @param {number} inches * @return returned value in centimeters */ function convertInchesToCentimeters(inches){ - //Code goes here - throw new Error("Invalid Type"); + if (typeof inches === "number" && inches === inches === isFinite(inches)) { + return inches * 2.54; + } else { + throw("Invalid Type"); + } } module.exports = convertInchesToCentimeters; diff --git a/test/convertInchesToCentimeters.test.js b/test/convertInchesToCentimeters.test.js index b703daf0..7aaa3553 100644 --- a/test/convertInchesToCentimeters.test.js +++ b/test/convertInchesToCentimeters.test.js @@ -1,12 +1,16 @@ const { convertInchesToCentimeters } = require("../lib"); describe("convertInchesToCentimeters", () => { - test("5 inches is 12.7000254000508 cm", () => { - expect(convertInchesToCentimeters(5)).toBe(12.7000254000508); + test("5 inches is 12.70 cm", () => { + expect(convertInchesToCentimeters(5)).toBe(12.7); }); - test("7 inches is 17.78003556007112 cm", () => { - expect(convertInchesToCentimeters(7)).toBe(12.78003556007112); + test("7 inches is 17.78 cm", () => { + expect(convertInchesToCentimeters(7)).toBe(17.78); + }); + + test("12 inches is 30.48 cm", () => { + expect(convertInchesToCentimeters(12)).toBe(30.48); }); test("Throw error on invalid type", () => { From 5ecf52d5e7676495df29df5a20c123da701cf641 Mon Sep 17 00:00:00 2001 From: Luis Mauro Martinez Baez Date: Thu, 26 Oct 2017 18:12:46 -0500 Subject: [PATCH 3/3] Adds convertCentimetersToInches issue --- lib/convertCentimetersToInches.js | 11 +++++++++++ test/convertCentimetersToInches.test.js | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 lib/convertCentimetersToInches.js create mode 100644 test/convertCentimetersToInches.test.js diff --git a/lib/convertCentimetersToInches.js b/lib/convertCentimetersToInches.js new file mode 100644 index 00000000..84aaeb6f --- /dev/null +++ b/lib/convertCentimetersToInches.js @@ -0,0 +1,11 @@ +/** + * Convert centimeters to inches where 1 cm equals 0.393701 inches + * @param {number} cm + * @return returned value in inches + */ +function convertCentimetersToInches(cm){ + // Your code goes here + throw("Invalid Type"); +} + +module.exports = convertCentimetersToInches; diff --git a/test/convertCentimetersToInches.test.js b/test/convertCentimetersToInches.test.js new file mode 100644 index 00000000..0d387b06 --- /dev/null +++ b/test/convertCentimetersToInches.test.js @@ -0,0 +1,18 @@ +const { convertCentimetersToInches } = require("../lib"); + +describe("convertCentimetersToInches", () => { + test("12 cm is 4.72 inches", () => { + expect(convertCentimetersToInches(12)).toBe(4.72); + }); + + test("30 cm is 11.81 inches", () => { + expect(convertCentimetersToInches(30)).toBe(11.81); + }); + + test("Throw error on invalid type", () => { + expect(() => convertCentimetersToInches("a cm")).toThrow("Invalid Type"); + expect(() => convertCentimetersToInches(null)).toThrow("Invalid Type"); + expect(() => convertCentimetersToInches(undefined)).toThrow("Invalid Type"); + expect(() => convertCentimetersToInches({})).toThrow("Invalid Type"); + }); +});