Skip to content

Commit

Permalink
refactor: test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenHoangSon96 committed Dec 18, 2024
1 parent 63afeda commit 06e741b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/util/TypeCasting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getMappedValue(field: Field, value: any): any {

const metaType = field.metadata.get('iox::column::type')

if (!metaType || (!metaType && field.typeId === ArrowType.Timestamp)) {
if (!metaType || field.typeId === ArrowType.Timestamp ) {
return value
}

Expand Down
73 changes: 41 additions & 32 deletions packages/client/test/unit/util/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,49 @@ import {expect} from 'chai'
import {isUnsignedNumber} from '../../../src/util/common'

describe('Test functions in common', () => {
it('should check if value is a valid number', () => {
expect(isNumber(1)).equal(true)
expect(isNumber(-1)).equal(true)
expect(isNumber(-1.2)).equal(true)
expect(isNumber('-1.2')).equal(true)
expect(isNumber('2')).equal(true)

expect(isNumber('a')).equal(false)
expect(isNumber('true')).equal(false)
expect(isNumber('')).equal(false)
expect(isNumber(' ')).equal(false)
expect(isNumber('32a')).equal(false)
expect(isNumber('32 ')).equal(false)
expect(isNumber(null)).equal(false)
expect(isNumber(undefined)).equal(false)
expect(isNumber(NaN)).equal(false)
const pairs: Array<{value: any; expect: boolean}> = [
{value: 1, expect: true},
{value: -1, expect: true},
{value: -1.2, expect: true},
{value: '-1.2', expect: true},
{value: '2', expect: true},
{value: 'a', expect: false},
{value: 'true', expect: false},
{value: '', expect: false},
{value: ' ', expect: false},
{value: '32a', expect: false},
{value: '32 ', expect: false},
{value: null, expect: false},
{value: undefined, expect: false},
{value: NaN, expect: false},
]
pairs.forEach((pair) => {
it(`check if ${pair.value} is a valid number`, () => {
expect(isNumber(pair.value)).to.equal(pair.expect)
})
})

it('should check if value is a valid unsigned number', () => {
expect(isUnsignedNumber(1)).equal(true)
expect(isUnsignedNumber(1.2)).equal(true)
expect(isUnsignedNumber('1.2')).equal(true)
expect(isUnsignedNumber('2')).equal(true)
const pairs1: Array<{value: any; expect: boolean}> = [
{value: 1, expect: true},
{value: 1.2, expect: true},
{value: '1.2', expect: true},
{value: '2', expect: true},
{value: -2.3, expect: false},
{value: '-2.3', expect: false},
{value: 'a', expect: false},
{value: 'true', expect: false},
{value: '', expect: false},
{value: ' ', expect: false},
{value: '32a', expect: false},
{value: '32 ', expect: false},
{value: null, expect: false},
{value: undefined, expect: false},
{value: NaN, expect: false},
]

expect(isUnsignedNumber(-2.3)).equal(false)
expect(isUnsignedNumber('-2.3')).equal(false)
expect(isUnsignedNumber('a')).equal(false)
expect(isUnsignedNumber('true')).equal(false)
expect(isUnsignedNumber('')).equal(false)
expect(isUnsignedNumber(' ')).equal(false)
expect(isUnsignedNumber('32a')).equal(false)
expect(isUnsignedNumber('32 ')).equal(false)
expect(isUnsignedNumber(null)).equal(false)
expect(isUnsignedNumber(undefined)).equal(false)
expect(isUnsignedNumber(NaN)).equal(false)
pairs1.forEach((pair) => {
it(`check if ${pair.value} is a valid unsigned number`, () => {
expect(isUnsignedNumber(pair.value)).to.equal(pair.expect)
})
})
})

0 comments on commit 06e741b

Please sign in to comment.