mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-18 01:05:42 +08:00

* chore: Switch to Node 20 + Vitest * chore: migrate to vitest mock functions * chore: code style (switch to prettier) * test: re-enable long-running test Seems the switch to Node 20 and Vitest has vastly improved the code's and / or the test's runtime! see #1193 * chore: code style * chore: fix failing tests * Updated Documentation in README.md * Update contribution guidelines to state usage of Prettier * fix: set prettier printWidth back to 80 * chore: apply updated code style automatically * fix: set prettier line endings to lf again * chore: apply updated code style automatically --------- Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
import { FindMinIterator } from '../FindMinIterator'
|
|
|
|
describe('FindMinIterator', () => {
|
|
test('given empty array then min is undefined', () => {
|
|
expect(FindMinIterator([])).toBeUndefined()
|
|
})
|
|
|
|
test('given single value array then min is found', () => {
|
|
expect(FindMinIterator([1])).toBe(1)
|
|
expect(FindMinIterator([-1])).toBe(-1)
|
|
expect(FindMinIterator([0])).toBe(0)
|
|
})
|
|
|
|
test('given array then min is found', () => {
|
|
expect(FindMinIterator([1, 2])).toBe(1)
|
|
expect(FindMinIterator([-1, 10])).toBe(-1)
|
|
expect(FindMinIterator([0, 100])).toBe(0)
|
|
expect(FindMinIterator([100, 0])).toBe(0)
|
|
expect(
|
|
FindMinIterator([100, 50, 20, 0, -100, 0, 2, 30, 45, 99, 104, 23])
|
|
).toBe(-100)
|
|
})
|
|
|
|
test('given empty generator then min is undefined', () => {
|
|
const src = function* () {} // eslint-disable-line
|
|
expect(FindMinIterator(src())).toBeUndefined()
|
|
})
|
|
|
|
test('given generator then min is found', () => {
|
|
const src = function* () {
|
|
// eslint-disable-line
|
|
yield 1
|
|
yield -1
|
|
yield 0
|
|
}
|
|
expect(FindMinIterator(src())).toBe(-1)
|
|
})
|
|
|
|
test('given string generator then min string length is found', () => {
|
|
const src = function* () {
|
|
// eslint-disable-line
|
|
yield 'abc'
|
|
yield 'de'
|
|
yield 'qwerty'
|
|
}
|
|
expect(FindMinIterator(src(), (_x) => _x.length)).toBe(2)
|
|
})
|
|
|
|
test('given array of objects then min accessor is found', () => {
|
|
const array = [
|
|
{ name: 'Item #1', price: 1.0 },
|
|
{ name: 'Item #2', price: 0.0 },
|
|
{ name: 'Item #3', price: -1.0 }
|
|
]
|
|
expect(FindMinIterator(array, (_x) => _x.price)).toBe(-1)
|
|
expect(FindMinIterator(array, (_x) => _x.name)).toBe('Item #1')
|
|
})
|
|
})
|