Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Dec 27, 2023
1 parent 34e8f4d commit 5947eed
Show file tree
Hide file tree
Showing 10 changed files with 1,576 additions and 1,576 deletions.
756 changes: 378 additions & 378 deletions src/__tests__/builtins.test.ts

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions src/__tests__/custom.test.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import { describe, it, expect } from 'vitest';
import { compact, compactObject, flatmap } from '../custom';
import { repeat } from '../itertools';
import { describe, it, expect } from "vitest";
import { compact, compactObject, flatmap } from "../custom";
import { repeat } from "../itertools";

describe('compact', () => {
it('compact w/ empty list', () => {
expect(compact([])).toEqual([]);
});
describe("compact", () => {
it("compact w/ empty list", () => {
expect(compact([])).toEqual([]);
});

it('icompact removes nullish values', () => {
expect(compact('abc')).toEqual(['a', 'b', 'c']);
expect(compact(['x', undefined])).toEqual(['x']);
expect(compact([0, null, undefined, NaN, Infinity])).toEqual([0, NaN, Infinity]);
});
it("icompact removes nullish values", () => {
expect(compact("abc")).toEqual(["a", "b", "c"]);
expect(compact(["x", undefined])).toEqual(["x"]);
expect(compact([0, null, undefined, NaN, Infinity])).toEqual([0, NaN, Infinity]);
});
});

describe('compactObject', () => {
it('compactObject w/ empty object', () => {
expect(compactObject({})).toEqual({});
});
describe("compactObject", () => {
it("compactObject w/ empty object", () => {
expect(compactObject({})).toEqual({});
});

it('compactObject removes nullish values', () => {
expect(compactObject({ a: 1, b: 'foo', c: 0, d: null })).toEqual({ a: 1, b: 'foo', c: 0 });
expect(compactObject({ a: undefined, b: false, c: 0, d: null })).toEqual({ b: false, c: 0 });
});
it("compactObject removes nullish values", () => {
expect(compactObject({ a: 1, b: "foo", c: 0, d: null })).toEqual({ a: 1, b: "foo", c: 0 });
expect(compactObject({ a: undefined, b: false, c: 0, d: null })).toEqual({ b: false, c: 0 });
});
});

describe('flatmap', () => {
it('flatmap w/ empty list', () => {
expect(Array.from(flatmap([], (x) => [x]))).toEqual([]);
});
describe("flatmap", () => {
it("flatmap w/ empty list", () => {
expect(Array.from(flatmap([], (x) => [x]))).toEqual([]);
});

it('flatmap works', () => {
const dupeEvens = (x: number) => (x % 2 === 0 ? [x, x] : [x]);
const triple = <T>(x: T) => [x, x, x];
const nothin = () => [];
expect(Array.from(flatmap([1, 2, 3, 4, 5], dupeEvens))).toEqual([1, 2, 2, 3, 4, 4, 5]);
expect(Array.from(flatmap(['hi', 'ha'], triple))).toEqual(['hi', 'hi', 'hi', 'ha', 'ha', 'ha']);
expect(Array.from(flatmap(['hi', 'ha'], nothin))).toEqual([]);
});
it("flatmap works", () => {
const dupeEvens = (x: number) => (x % 2 === 0 ? [x, x] : [x]);
const triple = <T>(x: T) => [x, x, x];
const nothin = () => [];
expect(Array.from(flatmap([1, 2, 3, 4, 5], dupeEvens))).toEqual([1, 2, 2, 3, 4, 4, 5]);
expect(Array.from(flatmap(["hi", "ha"], triple))).toEqual(["hi", "hi", "hi", "ha", "ha", "ha"]);
expect(Array.from(flatmap(["hi", "ha"], nothin))).toEqual([]);
});

it('flatmap example', () => {
const repeatN = (n: number) => repeat(n, n);
expect(Array.from(flatmap([0, 1, 2, 3, 4], repeatN))).toEqual([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]);
});
it("flatmap example", () => {
const repeatN = (n: number) => repeat(n, n);
expect(Array.from(flatmap([0, 1, 2, 3, 4], repeatN))).toEqual([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]);
});
});
Loading

0 comments on commit 5947eed

Please sign in to comment.