-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,576 additions
and
1,576 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
}); | ||
}); |
Oops, something went wrong.