forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntToBase.test.js
25 lines (24 loc) · 848 Bytes
/
IntToBase.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()
})
})