mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
algorithm: add IntToBase algo and a test for it (#1258)
This commit is contained in:
25
Maths/test/IntToBase.test.js
Normal file
25
Maths/test/IntToBase.test.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { intToBase } from '../intToBase'
|
||||
|
||||
describe('Int to Base', () => {
|
||||
test('Conversion to the binary system', () => {
|
||||
expect(intToBase(210, 2)).toEqual('11010010')
|
||||
expect(intToBase(-210, 2)).toEqual('-11010010')
|
||||
})
|
||||
test('Conversion to the system with base 5', () => {
|
||||
expect(intToBase(210, 5)).toEqual('1320')
|
||||
expect(intToBase(-210, 5)).toEqual('-1320')
|
||||
})
|
||||
test('Conversion to the octal system', () => {
|
||||
expect(intToBase(210, 8)).toEqual('322')
|
||||
expect(intToBase(-210, 8)).toEqual('-322')
|
||||
})
|
||||
test('Output is 0', () => {
|
||||
expect(intToBase(0, 8)).toEqual('0')
|
||||
expect(intToBase(0, 8)).toEqual('0')
|
||||
})
|
||||
test('Throwing an exception', () => {
|
||||
expect(() => intToBase('string', 2)).toThrow()
|
||||
expect(() => intToBase(10, 'base')).toThrow()
|
||||
expect(() => intToBase(true, false)).toThrow()
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user