mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-03-19 16:36:55 +01:00
utils.digits: Make it return a string in fixed-point notation
This commit is contained in:
parent
7b80ac883a
commit
922f1ae43f
@ -75,7 +75,7 @@ export const hex2rgb = (color) => {
|
||||
};
|
||||
|
||||
export const digits = (number, digits) => {
|
||||
return Math.floor(number*Math.pow(10, digits))/Math.pow(10, digits);
|
||||
return (Math.floor(number*Math.pow(10, digits))/Math.pow(10, digits)).toFixed(digits);
|
||||
};
|
||||
|
||||
export const normalize = (ll) => {
|
||||
|
@ -1,6 +1,18 @@
|
||||
import * as utils from './utils.js';
|
||||
|
||||
describe('utils', () => {
|
||||
describe('digits', () => {
|
||||
describe.each([
|
||||
[1, 0, '1'],
|
||||
[1, 1, '1.0'],
|
||||
[3.1415, 3, '3.141'],
|
||||
])('when given value=%f and digits=%f', (value, digits, expected_value) => {
|
||||
test(`returns ${expected_value}`, () => {
|
||||
expect(utils.digits(value, digits)).toEqual(expected_value);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('hex2rgb', () => {
|
||||
describe.each([
|
||||
['#ff0000', 255, 0, 0],
|
||||
@ -21,9 +33,8 @@ describe('utils', () => {
|
||||
expect(wrapper).toThrow('isn\'t a supported hex color');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('normalize', () => {
|
||||
describe('normalize', () => {
|
||||
describe.each([
|
||||
[0, 0, 0, 0],
|
||||
[61, 48, 61, 48],
|
||||
@ -43,4 +54,5 @@ describe('normalize', () => {
|
||||
expect(utils.normalize(input)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user