diff --git a/apps/frontend/src/utils/general.test.ts b/apps/frontend/src/utils/general.test.ts new file mode 100644 index 00000000..2595d4d3 --- /dev/null +++ b/apps/frontend/src/utils/general.test.ts @@ -0,0 +1,21 @@ +import { expect, test } from 'vitest'; +import { ftpPercentFromWatt, wattFromFtpPercent } from './general'; + +test('Watt values passed through ftpPercentFromWatt and wattFromFtpPercent ends up with the entered Watt value', () => { + let failures = []; + for (let ftp = 200; ftp <= 500; ftp += 1) { + for (let watt = 0; watt <= 1000; watt += 1) { + const ftpPct = ftpPercentFromWatt(watt, ftp); + const wattFromFtpPct = wattFromFtpPercent(ftpPct, ftp); + if (wattFromFtpPct !== watt) { + failures.push({ + watt, + exactWattFromFtpPct: (ftpPct * ftp) / 100, + ftpPct, + ftp, + }); + } + } + } + expect(failures.length).toBe(0); +}); diff --git a/apps/frontend/src/utils/general.ts b/apps/frontend/src/utils/general.ts index 5323cada..b1ebddad 100644 --- a/apps/frontend/src/utils/general.ts +++ b/apps/frontend/src/utils/general.ts @@ -50,23 +50,6 @@ export const ftpPercentFromWatt = (watt: number, ftp: number) => export const wattFromFtpPercent = (ftpPercent: number, ftp: number) => Math.round((ftpPercent * ftp) / 100); -let failures = []; -for (let ftp = 1; ftp <= 500; ftp += 1) { - for (let watt = 0; watt <= 1000; watt += 1) { - const ftpPct = Math.floor(1000 * (watt / ftp)) / 10; - const wattFromFtpPct = Math.round((ftpPct * ftp) / 100); - if (wattFromFtpPct !== watt) { - failures.push({ - watt, - exactWattFromFtpPct: (ftpPct * ftp) / 100, - ftpPct, - ftp, - }); - } - } -} -console.log('watt', failures); - export const editable = (data: T): Editable => ({ touched: false, data }); export const touched = (data: T): Editable => ({ touched: true, data }); export const addEditableError = (editable: Editable, error: string) => ({