Files
Bubberstation/tgui/packages/common/fp.test.ts
SkyratBot c98d76bca5 [MIRROR] Tgui: More common components in ts (#27674)
* Tgui: More common components in ts (#83098)

## About The Pull Request
Converts more of common into typescript, with some tests
## Why It's Good For The Game
Typescript,,,,

* Tgui: More common components in ts

---------

Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com>
2024-05-15 00:57:58 +02:00

24 lines
651 B
TypeScript

import { flow } from './fp';
describe('flow', () => {
it('composes multiple functions into one', () => {
const add2 = (x) => x + 2;
const multiplyBy3 = (x) => x * 3;
const subtract5 = (x) => x - 5;
const composedFunction = flow(add2, multiplyBy3, subtract5);
expect(composedFunction(4)).toBe(13); // ((4 + 2) * 3) - 5 = 13
});
it('handles arrays of functions', () => {
const add2 = (x) => x + 2;
const multiplyBy3 = (x) => x * 3;
const subtract5 = (x) => x - 5;
const composedFunction = flow([add2, multiplyBy3], subtract5);
expect(composedFunction(4)).toBe(13); // ((4 + 2) * 3) - 5 = 13
});
});