import { add, subtract, multiply, divide, isEven, capitalize } from '../utils';
describe('Math utilities', () => {
describe('add', () => {
it('should add two positive numbers', () => {
expect(add(2, 3)).toBe(5);
});
it('should add negative numbers', () => {
expect(add(-2, -3)).toBe(-5);
});
});
describe('subtract', () => {
it('should subtract two numbers', () => {
expect(subtract(5, 3)).toBe(2);
});
});
describe('multiply', () => {
it('should multiply two numbers', () => {
expect(multiply(3, 4)).toBe(12);
});
it('should handle multiplication by zero', () => {
expect(multiply(5, 0)).toBe(0);
});
});
describe('divide', () => {
it('should divide two numbers', () => {
expect(divide(10, 2)).toBe(5);
});
it('should throw error for division by zero', () => {
expect(() => divide(10, 0)).toThrow('Division by zero');
});
});
});
describe('Utility functions', () => {
describe('isEven', () => {
it('should return true for even numbers', () => {
expect(isEven(4)).toBe(true);
expect(isEven(0)).toBe(true);
});
it('should return false for odd numbers', () => {
expect(isEven(3)).toBe(false);
expect(isEven(-1)).toBe(false);
});
});
describe('capitalize', () => {
it('should capitalize first letter', () => {
expect(capitalize('hello')).toBe('Hello');
});
it('should handle empty string', () => {
expect(capitalize('')).toBe('');
});
it('should handle mixed case', () => {
expect(capitalize('hELLO')).toBe('Hello');
});
});
});