From 04c3603254b6afb434d1a42e84b097402ea2e553 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Fri, 23 Feb 2024 12:47:24 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Formats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/components/Controls.svelte | 2 +- app/src/lib/utilities/math-utilities.ts | 10 ++-- app/test/specs/byteformat.spec.ts | 38 +++++++------- app/test/specs/throttler.spec.ts | 66 ++++++++++++------------- app/test/specs/toUint8.spec.ts | 32 ++++++------ 5 files changed, 74 insertions(+), 74 deletions(-) diff --git a/app/src/components/Controls.svelte b/app/src/components/Controls.svelte index bffbdc3..52ce9f5 100644 --- a/app/src/components/Controls.svelte +++ b/app/src/components/Controls.svelte @@ -71,7 +71,7 @@ data[2] = toUint8($input.left.y, -1, 1); data[3] = toUint8($input.right.x, -1, 1); data[4] = toUint8($input.right.y, -1, 1); - data[5] = toUint8($input.height, 0, 100);; + data[5] = toUint8($input.height, 0, 100); data[6] = toUint8($input.speed, 0, 100); outControllerData.set(data); diff --git a/app/src/lib/utilities/math-utilities.ts b/app/src/lib/utilities/math-utilities.ts index 6a67dc9..50404aa 100644 --- a/app/src/lib/utilities/math-utilities.ts +++ b/app/src/lib/utilities/math-utilities.ts @@ -1,5 +1,5 @@ -export const toUint8 = (number:number, min:number, max:number) => { - number = Math.max(min, Math.min(max, number)); - let scaled = ((number - min) / (max - min)) * 255; - return Math.round(scaled) & 0xFF; - } \ No newline at end of file +export const toUint8 = (number: number, min: number, max: number) => { + number = Math.max(min, Math.min(max, number)); + let scaled = ((number - min) / (max - min)) * 255; + return Math.round(scaled) & 0xff; +}; diff --git a/app/test/specs/byteformat.spec.ts b/app/test/specs/byteformat.spec.ts index 10898cf..f8d5df9 100644 --- a/app/test/specs/byteformat.spec.ts +++ b/app/test/specs/byteformat.spec.ts @@ -2,27 +2,27 @@ import { describe, it, expect } from 'vitest'; import { humanFileSize } from '../../src/lib/utilities'; describe('humanFileSize', () => { - it('returns "0B" for 0 bytes', () => { - expect(humanFileSize(0)).toBe('0B'); - }); + it('returns "0B" for 0 bytes', () => { + expect(humanFileSize(0)).toBe('0B'); + }); - it('returns the size in bytes correctly', () => { - expect(humanFileSize(500)).toBe('500B'); - }); + it('returns the size in bytes correctly', () => { + expect(humanFileSize(500)).toBe('500B'); + }); - it('returns the size in kB correctly', () => { - expect(humanFileSize(1024)).toBe('1kB'); - }); + it('returns the size in kB correctly', () => { + expect(humanFileSize(1024)).toBe('1kB'); + }); - it('returns the size in MB correctly', () => { - expect(humanFileSize(1048576)).toBe('1MB'); // 1024 * 1024 - }); + it('returns the size in MB correctly', () => { + expect(humanFileSize(1048576)).toBe('1MB'); // 1024 * 1024 + }); - it('returns the size in GB correctly', () => { - expect(humanFileSize(1073741824)).toBe('1GB'); // 1024 * 1024 * 1024 - }); + it('returns the size in GB correctly', () => { + expect(humanFileSize(1073741824)).toBe('1GB'); // 1024 * 1024 * 1024 + }); - it('rounds to 2 decimal places correctly', () => { - expect(humanFileSize(1536)).toBe('1.5kB'); // 1024 + 512 - }); -}); \ No newline at end of file + it('rounds to 2 decimal places correctly', () => { + expect(humanFileSize(1536)).toBe('1.5kB'); // 1024 + 512 + }); +}); diff --git a/app/test/specs/throttler.spec.ts b/app/test/specs/throttler.spec.ts index ec89eac..f416362 100644 --- a/app/test/specs/throttler.spec.ts +++ b/app/test/specs/throttler.spec.ts @@ -2,45 +2,45 @@ import { throttler } from '../../src/lib/utilities'; import { describe, it, expect, beforeEach, afterEach, test, vitest } from 'vitest'; describe('throttler', () => { - let throttleInstance: throttler; - let callback + let throttleInstance: throttler; + let callback; - beforeEach(() => { - vitest.useFakeTimers(); - throttleInstance = new throttler(); - callback = vitest.fn(); - }); + beforeEach(() => { + vitest.useFakeTimers(); + throttleInstance = new throttler(); + callback = vitest.fn(); + }); - afterEach(() => { - vitest.useRealTimers(); - }); + afterEach(() => { + vitest.useRealTimers(); + }); - it('should call the callback function after the specified time', () => { - throttleInstance.throttle(callback, 1000); - expect(callback).not.toHaveBeenCalled(); + it('should call the callback function after the specified time', () => { + throttleInstance.throttle(callback, 1000); + expect(callback).not.toHaveBeenCalled(); - vitest.advanceTimersByTime(1000); - expect(callback).toHaveBeenCalledTimes(1); - }); + vitest.advanceTimersByTime(1000); + expect(callback).toHaveBeenCalledTimes(1); + }); - it('should not call the callback function if throttle is called again within the timeout period', () => { - throttleInstance.throttle(callback, 1000); - throttleInstance.throttle(callback, 1000); + it('should not call the callback function if throttle is called again within the timeout period', () => { + throttleInstance.throttle(callback, 1000); + throttleInstance.throttle(callback, 1000); - vitest.advanceTimersByTime(500); - expect(callback).not.toHaveBeenCalled(); + vitest.advanceTimersByTime(500); + expect(callback).not.toHaveBeenCalled(); - vitest.advanceTimersByTime(500); - expect(callback).toHaveBeenCalledTimes(1); - }); + vitest.advanceTimersByTime(500); + expect(callback).toHaveBeenCalledTimes(1); + }); - it('should allow the callback to be called again after the timeout period', () => { - throttleInstance.throttle(callback, 1000); - vitest.advanceTimersByTime(1000); - expect(callback).toHaveBeenCalledTimes(1); + it('should allow the callback to be called again after the timeout period', () => { + throttleInstance.throttle(callback, 1000); + vitest.advanceTimersByTime(1000); + expect(callback).toHaveBeenCalledTimes(1); - throttleInstance.throttle(callback, 1000); - vitest.advanceTimersByTime(1000); - expect(callback).toHaveBeenCalledTimes(2); - }); -}); \ No newline at end of file + throttleInstance.throttle(callback, 1000); + vitest.advanceTimersByTime(1000); + expect(callback).toHaveBeenCalledTimes(2); + }); +}); diff --git a/app/test/specs/toUint8.spec.ts b/app/test/specs/toUint8.spec.ts index 04565a3..a4f70f1 100644 --- a/app/test/specs/toUint8.spec.ts +++ b/app/test/specs/toUint8.spec.ts @@ -2,23 +2,23 @@ import { describe, it, expect } from 'vitest'; import { toUint8 } from '../../src/lib/utilities'; describe('toUint8', () => { - it('min interval value should get 0', () => { - expect(toUint8(-1, -1, 1)).toBe(0); - }); + it('min interval value should get 0', () => { + expect(toUint8(-1, -1, 1)).toBe(0); + }); - it('middle interval value should get 128', () => { - expect(toUint8(0, -1, 1)).toBe(128); - }); + it('middle interval value should get 128', () => { + expect(toUint8(0, -1, 1)).toBe(128); + }); - it('max interval value should get 255', () => { - expect(toUint8(1, -1, 1)).toBe(255); - }); + it('max interval value should get 255', () => { + expect(toUint8(1, -1, 1)).toBe(255); + }); - it('min value should be clamped', () => { - expect(toUint8(-2, -1, 1)).toBe(0); - }); + it('min value should be clamped', () => { + expect(toUint8(-2, -1, 1)).toBe(0); + }); - it('max value should be clamped', () => { - expect(toUint8(2, -1, 1)).toBe(255); - }); -}); \ No newline at end of file + it('max value should be clamped', () => { + expect(toUint8(2, -1, 1)).toBe(255); + }); +});