Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Oct 17, 2022
1 parent 3837839 commit fed2a64
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
6 changes: 5 additions & 1 deletion test/Monoid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ describe("Monoid", () => {

it("reverse", () => {
const M = monoid.reverse(string.Monoid)
U.deepStrictEqual(pipe("a", M.combineMany(["b"])), "ba")
U.deepStrictEqual(pipe("a", M.combine("b")), "ba")
U.deepStrictEqual(pipe("a", M.combine(M.empty)), "a")
U.deepStrictEqual(pipe(M.empty, M.combine("a")), "a")
U.deepStrictEqual(pipe("a", M.combineMany([])), "a")
U.deepStrictEqual(pipe("a", M.combineMany(["b", "c", "d"])), "dcba")
U.deepStrictEqual(pipe("a", M.combineMany([M.empty])), "a")
U.deepStrictEqual(pipe(M.empty, M.combineMany(["a"])), "a")
})
Expand Down
5 changes: 0 additions & 5 deletions test/Ordering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import * as _ from "@fp-ts/core/Ordering"
import { deepStrictEqual } from "./util"

describe("Ordering", () => {
it("combineMany", () => {
deepStrictEqual(pipe(0, _.Monoid.combineMany([1, -1])), 1)
deepStrictEqual(pipe(1, _.Monoid.combineMany([-1, -1])), 1)
})

it("match", () => {
const f = _.match(
() => "lt",
Expand Down
23 changes: 23 additions & 0 deletions test/Semigroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe("Semigroup", () => {
describe("min", () => {
it("should return the minimum", () => {
const S = _.min(number.Sortable)
U.deepStrictEqual(pipe(1, S.combineMany([])), 1)
U.deepStrictEqual(pipe(1, S.combineMany([3, 2])), 1)
})

Expand All @@ -40,12 +41,14 @@ describe("Semigroup", () => {
const S = _.min(pipe(number.Sortable, sortable.contramap((_: Item) => _.a)))
const item: Item = { a: 1 }
U.strictEqual(pipe({ a: 2 }, S.combineMany([{ a: 1 }, item])), item)
U.strictEqual(pipe(item, S.combineMany([])), item)
})
})

describe("max", () => {
it("should return the maximum", () => {
const S = _.max(number.Sortable)
U.deepStrictEqual(pipe(1, S.combineMany([])), 1)
U.deepStrictEqual(pipe(1, S.combineMany([3, 2])), 3)
})

Expand All @@ -54,6 +57,7 @@ describe("Semigroup", () => {
const S = _.max(pipe(number.Sortable, sortable.contramap((_: Item) => _.a)))
const item: Item = { a: 2 }
U.strictEqual(pipe({ a: 1 }, S.combineMany([{ a: 2 }, item])), item)
U.strictEqual(pipe(item, S.combineMany([])), item)
})
})

Expand All @@ -66,6 +70,21 @@ describe("Semigroup", () => {
name: "ab",
age: 30
})
U.deepStrictEqual(pipe({ name: "a", age: 10 }, S.combineMany([])), {
name: "a",
age: 10
})
U.deepStrictEqual(pipe({ name: "a", age: 10 }, S.combineMany([{ name: "b", age: 20 }])), {
name: "ab",
age: 30
})
U.deepStrictEqual(
pipe({ name: "a", age: 10 }, S.combineMany([{ name: "b", age: 20 }, { name: "c", age: 30 }])),
{
name: "abc",
age: 60
}
)
})

it("tuple", () => {
Expand All @@ -74,11 +93,15 @@ describe("Semigroup", () => {
number.SemigroupSum
)
U.deepStrictEqual(pipe(["a", 10], S.combine(["b", 20])), ["ab", 30])
U.deepStrictEqual(pipe(["a", 10], S.combineMany([])), ["a", 10])
U.deepStrictEqual(pipe(["a", 10], S.combineMany([["b", 20]])), ["ab", 30])
U.deepStrictEqual(pipe(["a", 10], S.combineMany([["b", 20], ["c", 30]])), ["abc", 60])
})

it("first", () => {
const S = _.first<number>()
U.deepStrictEqual(pipe(1, S.combine(2)), 1)
U.deepStrictEqual(pipe(1, S.combineMany([])), 1)
U.deepStrictEqual(pipe(1, S.combineMany([2, 3, 4, 5, 6])), 1)
})

Expand Down
3 changes: 3 additions & 0 deletions test/Semigroupal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ describe("Semigroupal", () => {

it("zipManyComposition", () => {
const zipMany = _.zipManyComposition(O.Semigroupal, O.Semigroupal)
U.deepStrictEqual(pipe(O.none, zipMany([])), O.none)
U.deepStrictEqual(pipe(O.some(O.none), zipMany([])), O.some(O.none))
U.deepStrictEqual(pipe(O.some(O.some(1)), zipMany([])), O.some(O.some([1] as const)))
U.deepStrictEqual(pipe(O.none, zipMany([O.none])), O.none)
U.deepStrictEqual(pipe(O.some(O.none), zipMany([O.none])), O.none)
U.deepStrictEqual(pipe(O.some(O.none), zipMany([O.some(O.none)])), O.some(O.none))
Expand Down
6 changes: 6 additions & 0 deletions test/Sortable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ describe("Sortable", () => {
[2, "c"],
[1, "c"]
])
U.deepStrictEqual(sort(pipe(sortBySnd, S.combineMany([sortByFst])))(tuples), [
[2, "a"],
[1, "b"],
[1, "c"],
[2, "c"]
])
})

it("getMonoid", () => {
Expand Down

0 comments on commit fed2a64

Please sign in to comment.