SIGN IN SIGN UP

Algorithms and Data Structures implemented in JavaScript for beginners, following best practices.

34084 0 0 JavaScript
2022-09-15 12:20:58 +05:30
import { liouvilleFunction } from '../LiouvilleFunction'
const expectedValuesArray = [
1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, -1, -1, -1, 1, 1,
-1, 1, 1, 1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1, -1, -1, -1, -1,
-1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1,
-1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1,
-1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1
]
2022-09-15 12:20:58 +05:30
describe('Testing liouville function', () => {
for (let i = 1; i <= 100; i++) {
it(
'Testing for number = ' + i + ', should return ' + expectedValuesArray[i],
() => {
expect(liouvilleFunction(i)).toBe(expectedValuesArray[i - 1])
}
)
2022-09-15 12:20:58 +05:30
}
it('should throw error when supplied negative numbers', () => {
expect(() => {
liouvilleFunction(-1)
}).toThrow(Error)
2022-09-15 12:20:58 +05:30
})
it('should throw error when supplied zero', () => {
expect(() => {
liouvilleFunction(0)
}).toThrow(Error)
2022-09-15 12:20:58 +05:30
})
})