@santi100a/percentage-lib
Version:
Santi's Powerful Percentage Function: Easily find percentages!
48 lines (39 loc) • 1.65 kB
text/typescript
// Generated by CodiumAI
import percentage = require('..');
describe('percentage', () => {
// Returns the correct percentage value for positive input values
it('should return the correct percentage value when given positive input values', () => {
expect(percentage(10, 50)).toBe(5);
expect(percentage(20, 75)).toBe(15);
expect(percentage(100, 20)).toBe(20);
});
// Returns 0 when n or p is 0
it('should return 0 when n is 0', () => {
expect(percentage(0, 50)).toBe(0);
expect(percentage(0, 75)).toBe(0);
expect(percentage(0, 100)).toBe(0);
});
it('should return 0 when p is 0', () => {
expect(percentage(10, 0)).toBe(0);
expect(percentage(20, 0)).toBe(0);
expect(percentage(100, 0)).toBe(0);
});
// Returns n when p is 100 and n is any value
it('should return n when p is 100 and n is any value', () => {
expect(percentage(10, 100)).toBe(10);
expect(percentage(20, 100)).toBe(20);
expect(percentage(100, 100)).toBe(100);
});
// Returns the correct negative values when n is negative
it('should return the correct negative values when n is negative', () => {
expect(percentage(-10, 50)).toBe(-5);
expect(percentage(-20, 75)).toBe(-15);
expect(percentage(-100, 20)).toBe(-20);
});
// Throws when p is negative
it('should throw when p is negative', () => {
expect(() => percentage(10, -50)).toThrow(/"percentage" must be/);
expect(() => percentage(20, -75)).toThrow(/"percentage" must be/);
expect(() => percentage(100, -20)).toThrow(/"percentage" must be/);
});
});