Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Goldman committed Jan 24, 2024
1 parent 68975a6 commit f701e58
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions test/unit/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { chunks, deepEqual } from '../../src/logic/utils'

describe('utils', function () {
describe('deepEqual', function () {
it('should return true for equal objects', () => {
const obj1 = {
a: 1,
b: {
c: 2,
d: [3, 4]
}
}

const obj2 = {
a: 1,
b: {
c: 2,
d: [3, 4]
}
}

expect(deepEqual(obj1, obj2)).toBe(true)
})

it('should return false for different objects', () => {
expect(
deepEqual(
{
a: 1,
b: {
c: 2,
d: [3, 4]
}
},
{
a: 1,
b: {
c: 2,
d: [3, 5] // Different value here
}
}
)
).toBe(false)

expect(
deepEqual(
{
a: 1
},
{
a: 1,
b: {}
}
)
).toBe(false)
})

it('should handle simple values', () => {
expect(deepEqual(42, 42)).toBe(true)
expect(deepEqual(42, '42')).toBe(false)
})

it('should handle null and undefined', () => {
expect(deepEqual(null, null)).toBe(true)
expect(deepEqual(undefined, undefined)).toBe(true)
expect(deepEqual(null, undefined)).toBe(false)
})

// tests for deepEqual
// it('returns an empty array for an empty request', async () => {
//
// })
})

describe('chunks', function () {
const names: string[] = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']

it('returns an empty array for an empty request', async () => {
expect(chunks([], 1)).toEqual([])
expect(chunks([], 10)).toEqual([])
})

it('returns elements in chunks of the requested size', async () => {
expect(chunks(names, 1)).toEqual([['a'], ['b'], ['c'], ['d'], ['e'], ['f'], ['g'], ['h'], ['i']])
expect(chunks(names, 2)).toEqual([['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h'], ['i']])
expect(chunks(names, 3)).toEqual([
['a', 'b', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i']
])
expect(chunks(names, 4)).toEqual([['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h'], ['i']])
expect(chunks(names, 5)).toEqual([
['a', 'b', 'c', 'd', 'e'],
['f', 'g', 'h', 'i']
])
expect(chunks(names, 6)).toEqual([
['a', 'b', 'c', 'd', 'e', 'f'],
['g', 'h', 'i']
])
expect(chunks(names, 7)).toEqual([
['a', 'b', 'c', 'd', 'e', 'f', 'g'],
['h', 'i']
])
expect(chunks(names, 8)).toEqual([['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], ['i']])
expect(chunks(names, 9)).toEqual([['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']])
expect(chunks(names, 10)).toEqual([['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']])
})
})
})

0 comments on commit f701e58

Please sign in to comment.