Skip to content

Commit

Permalink
Update tests and more
Browse files Browse the repository at this point in the history
  • Loading branch information
mobily committed Dec 4, 2021
1 parent e19df9a commit 0a21cab
Show file tree
Hide file tree
Showing 95 changed files with 3,296 additions and 518 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@

## Features

- 🚀 built with `ReScript`, which generates highly performant JavaScript code (see the benchmarks [here](benchmarks))
- 🚀 built with `ReScript`, which generates highly performant JavaScript code (see the benchmark results [here](benchmarks))
- 👀 provide more readable code, due to the `data-first` approach
- ✨ support for `TypeScript` and `Flow`
- 🛡 write safer code with `Option` and `Result` types
- 🎯 all functions return immutable data (no side-effects)
- ✅ high tests coverage
- 🌲 tree-shakeable
- 📝 fully documented
Expand Down
28 changes: 16 additions & 12 deletions __tests__/Array/splitAt.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { A } from '../..'
import { A, O } from '../..'

describe('splitAt', () => {
it('returns None', () => {
expect(A.splitAt([], 1)).toBeNone()
expect(A.splitAt([1, 2, 3], -1)).toBeNone()
expect(A.splitAt([1, 2, 3], 4)).toBeNone()
expect(A.splitAt([], 1)).toEqual(O.None)
expect(A.splitAt([1, 2, 3], -1)).toEqual(O.None)
expect(A.splitAt([1, 2, 3], 4)).toEqual(O.None)
})

it('returns Some', () => {
expect(A.splitAt([], 0)).toBeSome([[], []])
expect(A.splitAt([1], 1)).toBeSome([[1], []])
expect(A.splitAt([1, 2], 1)).toBeSome([[1], [2]])
expect(A.splitAt([true, true, false], 2)).toBeSome([[true, true], [false]])
expect(A.splitAt([[1], [2], [3], [4]], 2)).toBeSome([
[[1], [2]],
[[3], [4]],
])
expect(A.splitAt([], 0)).toEqual(O.Some([[], []]))
expect(A.splitAt([1], 1)).toEqual(O.Some([[1], []]))
expect(A.splitAt([1, 2], 1)).toEqual(O.Some([[1], [2]]))
expect(A.splitAt([true, true, false], 2)).toEqual(
O.Some([[true, true], [false]]),
)
expect(A.splitAt([[1], [2], [3], [4]], 2)).toEqual(
O.Some([
[[1], [2]],
[[3], [4]],
]),
)
})
})
35 changes: 35 additions & 0 deletions __tests__/Bool/and.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expectType } from 'ts-expect'

import { B, pipe } from '../..'

describe('and', () => {
it('provides correct types', () => {
expectType<boolean>(B.and(true, true))
})

it('combines two boolean using AND', () => {
expect(B.and(true, true)).toEqual(true)
expect(B.and(false, false)).toEqual(false)
expect(B.and(true, false)).toEqual(false)
})

it('*', () => {
expect(B.and(true, true)).toEqual(true)
})
})

describe('and (pipe)', () => {
it('provides correct types', () => {
expectType<boolean>(pipe(true, B.and(true)))
})

it('combines two boolean using AND', () => {
expect(pipe(true, B.and(true))).toEqual(true)
expect(pipe(false, B.and(false))).toEqual(false)
expect(pipe(true, B.and(false))).toEqual(false)
})

it('*', () => {
expect(pipe(true, B.and(false))).toEqual(false)
})
})
77 changes: 77 additions & 0 deletions __tests__/Bool/ifElse.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { expectType } from 'ts-expect'

import { B, F, pipe } from '../..'

describe('eq', () => {
it('provides correct types', () => {
expectType<string>(
B.ifElse(
true,
() => 'ok',
() => 'nok',
),
)
})

it('folds a boolean value into a value of a different type', () => {
expect(
B.ifElse(
true,
() => 'ok',
() => 'nok',
),
).toEqual('ok')
expect(
B.ifElse(
false,
() => 'ok',
() => 'nok',
),
).toEqual('nok')
})

it('*', () => {
expect(B.ifElse(true, F.always('ts'), F.always('belt'))).toEqual('ts')
})
})

describe('eq (pipe)', () => {
it('provides correct types', () => {
expectType<number>(
pipe(
true,
B.ifElse(
() => 0,
() => 1,
),
),
)
})

it('folds a boolean value into a value of a different type', () => {
expect(
pipe(
true,
B.ifElse(
() => 1,
() => 0,
),
),
).toEqual(1)
expect(
pipe(
false,
B.ifElse(
() => 1,
() => 0,
),
),
).toEqual(0)
})

it('*', () => {
expect(pipe(false, B.ifElse(F.always('ts'), F.always('belt')))).toEqual(
'belt',
)
})
})
35 changes: 35 additions & 0 deletions __tests__/Bool/implies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expectType } from 'ts-expect'

import { B, pipe } from '../..'

describe('implies', () => {
it('provides correct types', () => {
expectType<boolean>(B.implies(true, true))
})

it('combines two booleans using an implication', () => {
expect(B.implies(true, true)).toEqual(true)
expect(B.implies(false, false)).toEqual(true)
expect(B.implies(true, false)).toEqual(false)
})

it('*', () => {
expect(B.implies(false, true)).toEqual(true)
})
})

describe('implies (pipe)', () => {
it('provides correct types', () => {
expectType<boolean>(pipe(true, B.implies(true)))
})

it('combines two booleans using an implication', () => {
expect(pipe(true, B.implies(true))).toEqual(true)
expect(pipe(false, B.implies(false))).toEqual(true)
expect(pipe(true, B.implies(false))).toEqual(false)
})

it('*', () => {
expect(pipe(true, B.implies(false))).toEqual(false)
})
})
33 changes: 33 additions & 0 deletions __tests__/Bool/inverse.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expectType } from 'ts-expect'

import { B, pipe } from '../..'

describe('inverse', () => {
it('provides correct types', () => {
expectType<boolean>(B.inverse(true))
})

it('negates the given boolean', () => {
expect(B.inverse(true)).toEqual(false)
expect(B.inverse(false)).toEqual(true)
})

it('*', () => {
expect(B.inverse(false)).toEqual(true)
})
})

describe('inverse (pipe)', () => {
it('provides correct types', () => {
expectType<boolean>(pipe(true, B.inverse))
})

it('negates the given boolean', () => {
expect(pipe(true, B.inverse)).toEqual(false)
expect(pipe(false, B.inverse)).toEqual(true)
})

it('*', () => {
expect(pipe(true, B.inverse)).toEqual(false)
})
})
35 changes: 35 additions & 0 deletions __tests__/Bool/nand.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expectType } from 'ts-expect'

import { B, pipe } from '../..'

describe('nand', () => {
it('provides correct types', () => {
expectType<boolean>(B.nand(true, true))
})

it('combines two booleans using NAND', () => {
expect(B.nand(true, true)).toEqual(false)
expect(B.nand(false, false)).toEqual(true)
expect(B.nand(true, false)).toEqual(true)
})

it('*', () => {
expect(B.nand(true, false)).toEqual(true)
})
})

describe('nand (pipe)', () => {
it('provides correct types', () => {
expectType<boolean>(pipe(true, B.nand(true)))
})

it('combines two booleans using NAND', () => {
expect(pipe(true, B.nand(true))).toEqual(false)
expect(pipe(false, B.nand(false))).toEqual(true)
expect(pipe(true, B.nand(false))).toEqual(true)
})

it('*', () => {
expect(pipe(false, B.nand(false))).toEqual(true)
})
})
35 changes: 35 additions & 0 deletions __tests__/Bool/nor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expectType } from 'ts-expect'

import { B, pipe } from '../..'

describe('nor', () => {
it('provides correct types', () => {
expectType<boolean>(B.nor(true, true))
})

it('combines two booleans using NOR', () => {
expect(B.nor(true, true)).toEqual(false)
expect(B.nor(false, false)).toEqual(true)
expect(B.nor(true, false)).toEqual(false)
})

it('*', () => {
expect(B.nor(true, false)).toEqual(false)
})
})

describe('nor (pipe)', () => {
it('provides correct types', () => {
expectType<boolean>(pipe(true, B.nor(true)))
})

it('combines two booleans using NOR', () => {
expect(pipe(true, B.nor(true))).toEqual(false)
expect(pipe(false, B.nor(false))).toEqual(true)
expect(pipe(true, B.nor(false))).toEqual(false)
})

it('*', () => {
expect(pipe(false, B.nor(false))).toEqual(true)
})
})
35 changes: 35 additions & 0 deletions __tests__/Bool/or.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expectType } from 'ts-expect'

import { B, pipe } from '../..'

describe('or', () => {
it('provides correct types', () => {
expectType<boolean>(B.or(true, true))
})

it('combines two booleans using OR', () => {
expect(B.or(true, true)).toEqual(true)
expect(B.or(false, false)).toEqual(false)
expect(B.or(true, false)).toEqual(true)
})

it('*', () => {
expect(B.or(true, false)).toEqual(true)
})
})

describe('or (pipe)', () => {
it('provides correct types', () => {
expectType<boolean>(pipe(true, B.or(true)))
})

it('combines two booleans using OR', () => {
expect(pipe(true, B.or(true))).toEqual(true)
expect(pipe(false, B.or(false))).toEqual(false)
expect(pipe(true, B.or(false))).toEqual(true)
})

it('*', () => {
expect(pipe(false, B.or(false))).toEqual(false)
})
})
35 changes: 35 additions & 0 deletions __tests__/Bool/xnor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expectType } from 'ts-expect'

import { B, pipe } from '../..'

describe('xnor', () => {
it('provides correct types', () => {
expectType<boolean>(B.xnor(true, true))
})

it('combines two booleans using XNOR', () => {
expect(B.xnor(true, true)).toEqual(true)
expect(B.xnor(false, false)).toEqual(true)
expect(B.xnor(true, false)).toEqual(false)
})

it('*', () => {
expect(B.xnor(true, false)).toEqual(false)
})
})

describe('xnor (pipe)', () => {
it('provides correct types', () => {
expectType<boolean>(pipe(true, B.xnor(true)))
})

it('combines two booleans using XNOR', () => {
expect(pipe(true, B.xnor(true))).toEqual(true)
expect(pipe(false, B.xnor(false))).toEqual(true)
expect(pipe(true, B.xnor(false))).toEqual(false)
})

it('*', () => {
expect(pipe(false, B.xnor(false))).toEqual(true)
})
})
Loading

0 comments on commit 0a21cab

Please sign in to comment.