-
Notifications
You must be signed in to change notification settings - Fork 0
/
allPairs.test.ts
38 lines (30 loc) · 1007 Bytes
/
allPairs.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { describe, expect, it } from "vitest"
import { allPairsEach, allPairsMap, allPairsMapFilter } from "../allPairs"
describe("allPairsEach", () => {
it("should execute the callback function for each pair of elements", () => {
const items = [1, 2, 3, 4]
const result: number[] = []
allPairsEach(items, (a, b) => {
result.push(a + b)
})
expect(result).toEqual([3, 4, 5, 5, 6, 7])
})
})
describe("allPairsMap", () => {
it("should apply the callback function to each pair of elements and return an array of results", () => {
const items = [1, 2, 3, 4]
const result = allPairsMap(items, (a, b) => a + b)
expect(result).toEqual([3, 4, 5, 5, 6, 7])
})
})
describe("allPairsMapFilter", () => {
it("should apply the callback function to each pair of elements and return an array of filtered results", () => {
const items = [1, 2, 3, 4]
const result = allPairsMapFilter(items, (a, b) => {
if (a + b > 5) {
return a + b
}
})
expect(result).toEqual([6, 7])
})
})