|
1 |
| -import { absVal } from '../Abs' |
| 1 | +import { abs } from '../Abs' |
| 2 | + |
| 3 | +describe('Testing abs function', () => { |
| 4 | + it('Testing for invalid types', () => { |
| 5 | + expect(() => abs('234a')).toThrow() |
| 6 | + expect(() => abs({})).toThrow() |
| 7 | + expect(() => abs([12, -32, -60])).toThrow() |
| 8 | + }) |
| 9 | + |
| 10 | + it('Testing for number of string type', () => { |
| 11 | + expect(abs('-345')).toBe(345) |
| 12 | + expect(abs('-345.455645')).toBe(345.455645) |
| 13 | + }) |
| 14 | + |
| 15 | + it('Testing for a boolean type', () => { |
| 16 | + expect(abs(true)).toBe(1) |
| 17 | + expect(abs(false)).toBe(0) |
| 18 | + }) |
2 | 19 |
|
3 |
| -describe('absVal', () => { |
4 | 20 | it('should return an absolute value of a negative number', () => {
|
5 |
| - const absOfNegativeNumber = absVal(-34) |
| 21 | + const absOfNegativeNumber = abs(-34) |
6 | 22 | expect(absOfNegativeNumber).toBe(34)
|
7 | 23 | })
|
8 | 24 |
|
9 | 25 | it('should return an absolute value of a positive number', () => {
|
10 |
| - const absOfPositiveNumber = absVal(50) |
| 26 | + const absOfPositiveNumber = abs(50) |
11 | 27 | expect(absOfPositiveNumber).toBe(50)
|
12 | 28 | })
|
13 | 29 |
|
14 | 30 | it('should return an absolute value of a zero number', () => {
|
15 |
| - const absOfPositiveNumber = absVal(0) |
| 31 | + const absOfPositiveNumber = abs(0) |
16 | 32 | expect(absOfPositiveNumber).toBe(0)
|
17 | 33 | })
|
| 34 | + |
| 35 | + it('should return an absolute value of any floating number', () => { |
| 36 | + const absOfPositiveNumber = abs(-20.2034) |
| 37 | + expect(absOfPositiveNumber).toBe(20.2034) |
| 38 | + }) |
18 | 39 | })
|
0 commit comments