Skip to content

Commit

Permalink
test: Extract watt/ftp test to an actual test
Browse files Browse the repository at this point in the history
  • Loading branch information
sivertschou committed Jan 11, 2025
1 parent 41c3dae commit e47c2d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
21 changes: 21 additions & 0 deletions apps/frontend/src/utils/general.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
17 changes: 0 additions & 17 deletions apps/frontend/src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T>(data: T): Editable<T> => ({ touched: false, data });
export const touched = <T>(data: T): Editable<T> => ({ touched: true, data });
export const addEditableError = <T>(editable: Editable<T>, error: string) => ({
Expand Down

0 comments on commit e47c2d2

Please sign in to comment.