Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-----I need mocha testing for this code ---------- ------------USING JAVASCRIPT--------------- class UnitMap { constructor(from, to, multiplier) { this.from = from; this.to = to; this.multiplier =

-----I need mocha testing for this code ----------

------------USING JAVASCRIPT---------------

class UnitMap { constructor(from, to, multiplier) { this.from = from; this.to = to; this.multiplier = multiplier; } } class UnitConverter { constructor() { this.unitMaps = [ new UnitMap('g', 'ounce', 28.3495231), new UnitMap('g', 'pound', 453.59237), new UnitMap('m', 'inch', 0.0254), new UnitMap('m', 'foot', 0.3048) ]; } round(value, decimals) { return Number(Math.round(value+'e'+decimals)+'e-'+decimals); } kgToOunce(val) { const multiplier = this.unitMaps.find(u => u.to == 'ounce').multiplier; const convertedVal = (val * 1000) / multiplier; return this.round(convertedVal, 4); } kgToPound(val) { const multiplier = this.unitMaps.find(u => u.to == 'pound').multiplier; const convertedVal = (val * 1000) / multiplier; return this.round(convertedVal, 4); } meterToInch(val) { const multiplier = this.unitMaps.find(u => u.to == 'inch').multiplier; const convertedVal = val / multiplier; return this.round(convertedVal, 4); } meterToFoot(val) { const multiplier = this.unitMaps.find(u => u.to == 'foot').multiplier; const convertedVal = val / multiplier; return this.round(convertedVal, 4); } } module.exports = new UnitConverter(); const unitConverter = new UnitConverter(); /* console.log( '1 Kg is', unitConverter.kgToOunce(1), 'ounce' ); console.log( '2 Kg is', unitConverter.kgToPound(2), 'poud'); console.log( '1 m is', unitConverter.meterToInch(1), 'inch' ); console.log( '2 m is', unitConverter.meterToFoot(2), 'foot'); */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

Students also viewed these Databases questions

Question

Calculate the account balance for each of the following:

Answered: 1 week ago