Initial commit: Create comprehensive Git playground
- Multi-language source code (Python, JavaScript, Java, C++, Go) - Configuration files (JSON, YAML, INI) - Sample data files (CSV, JSON, logs) - Binary and media assets (PNG, SVG, PDF) - Test files and deployment scripts - Nested directory structure for testing Git features 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
53
tests/unit/test_calculator.js
Normal file
53
tests/unit/test_calculator.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const Calculator = require('../../src/calculator');
|
||||
|
||||
describe('Calculator', () => {
|
||||
let calculator;
|
||||
|
||||
beforeEach(() => {
|
||||
calculator = new Calculator();
|
||||
});
|
||||
|
||||
test('should add two numbers correctly', () => {
|
||||
expect(calculator.add(2, 3)).toBe(5);
|
||||
expect(calculator.add(-1, 1)).toBe(0);
|
||||
expect(calculator.add(0, 0)).toBe(0);
|
||||
});
|
||||
|
||||
test('should subtract two numbers correctly', () => {
|
||||
expect(calculator.subtract(5, 3)).toBe(2);
|
||||
expect(calculator.subtract(1, 1)).toBe(0);
|
||||
expect(calculator.subtract(0, 5)).toBe(-5);
|
||||
});
|
||||
|
||||
test('should multiply two numbers correctly', () => {
|
||||
expect(calculator.multiply(3, 4)).toBe(12);
|
||||
expect(calculator.multiply(-2, 3)).toBe(-6);
|
||||
expect(calculator.multiply(0, 5)).toBe(0);
|
||||
});
|
||||
|
||||
test('should divide two numbers correctly', () => {
|
||||
expect(calculator.divide(10, 2)).toBe(5);
|
||||
expect(calculator.divide(7, 2)).toBe(3.5);
|
||||
expect(calculator.divide(-6, 3)).toBe(-2);
|
||||
});
|
||||
|
||||
test('should throw error when dividing by zero', () => {
|
||||
expect(() => calculator.divide(5, 0)).toThrow('Division by zero is not allowed');
|
||||
});
|
||||
|
||||
test('should maintain calculation history', () => {
|
||||
calculator.add(2, 3);
|
||||
calculator.multiply(4, 5);
|
||||
|
||||
const history = calculator.getHistory();
|
||||
expect(history).toHaveLength(2);
|
||||
expect(history[0]).toBe('2 + 3 = 5');
|
||||
expect(history[1]).toBe('4 * 5 = 20');
|
||||
});
|
||||
|
||||
test('should clear history', () => {
|
||||
calculator.add(1, 1);
|
||||
calculator.clearHistory();
|
||||
expect(calculator.getHistory()).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user