import { describe, it, expect } from 'vitest';
import { add, subtract, multiply, divide, factorial } from './math';
describe('Math Functions', () => {
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);
});
it('should add zero', () => {
expect(add(5, 0)).toBe(5);
});
});
describe('subtract', () => {
it('should subtract two numbers', () => {
expect(subtract(5, 3)).toBe(2);
});
it('should handle negative results', () => {
expect(subtract(3, 5)).toBe(-2);
});
});
describe('multiply', () => {
it('should multiply two numbers', () => {
expect(multiply(3, 4)).toBe(12);
});
it('should handle zero multiplication', () => {
expect(multiply(5, 0)).toBe(0);
});
});
describe('divide', () => {
it('should divide two numbers', () => {
expect(divide(10, 2)).toBe(5);
});
it('should throw error on division by zero', () => {
expect(() => divide(10, 0)).toThrow('Division by zero');
});
});
describe('factorial', () => {
it('should calculate factorial of positive number', () => {
expect(factorial(5)).toBe(120);
});
it('should return 1 for factorial of 0', () => {
expect(factorial(0)).toBe(1);
});
it('should return 1 for factorial of 1', () => {
expect(factorial(1)).toBe(1);
});
it('should throw error for negative numbers', () => {
expect(() => factorial(-1)).toThrow('Factorial of negative number');
});
});
});