algorithm: Liouville function (#1100)

This commit is contained in:
Akshay Dubey
2022-09-15 12:20:58 +05:30
committed by GitHub
parent e7ee09a07d
commit d1152144aa
2 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
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]
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])
})
}
it('should throw error when supplied negative numbers', () => {
expect(() => { liouvilleFunction(-1) }).toThrow(Error)
})
it('should throw error when supplied zero', () => {
expect(() => { liouvilleFunction(0) }).toThrow(Error)
})
})