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);
|
||||
});
|
||||
});
|
||||
101
tests/unit/test_utils.py
Normal file
101
tests/unit/test_utils.py
Normal file
@@ -0,0 +1,101 @@
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add src directory to path for imports
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'src'))
|
||||
|
||||
from utils import generate_random_string, hash_string, flatten_dict, chunk_list, DataProcessor
|
||||
|
||||
class TestUtils:
|
||||
|
||||
def test_generate_random_string(self):
|
||||
# Test default length
|
||||
result = generate_random_string()
|
||||
assert len(result) == 10
|
||||
assert result.isalnum()
|
||||
|
||||
# Test custom length
|
||||
result = generate_random_string(5)
|
||||
assert len(result) == 5
|
||||
|
||||
# Test uniqueness
|
||||
result1 = generate_random_string(20)
|
||||
result2 = generate_random_string(20)
|
||||
assert result1 != result2
|
||||
|
||||
def test_hash_string(self):
|
||||
# Test SHA256 (default)
|
||||
result = hash_string("hello")
|
||||
assert len(result) == 64 # SHA256 produces 64 character hex string
|
||||
|
||||
# Test MD5
|
||||
result = hash_string("hello", "md5")
|
||||
assert len(result) == 32 # MD5 produces 32 character hex string
|
||||
|
||||
# Test consistency
|
||||
result1 = hash_string("test")
|
||||
result2 = hash_string("test")
|
||||
assert result1 == result2
|
||||
|
||||
def test_flatten_dict(self):
|
||||
nested = {
|
||||
"a": 1,
|
||||
"b": {
|
||||
"c": 2,
|
||||
"d": {
|
||||
"e": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expected = {
|
||||
"a": 1,
|
||||
"b.c": 2,
|
||||
"b.d.e": 3
|
||||
}
|
||||
|
||||
result = flatten_dict(nested)
|
||||
assert result == expected
|
||||
|
||||
# Test custom separator
|
||||
result = flatten_dict(nested, sep="_")
|
||||
assert "b_c" in result
|
||||
assert "b_d_e" in result
|
||||
|
||||
def test_chunk_list(self):
|
||||
data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
|
||||
result = chunk_list(data, 3)
|
||||
expected = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
||||
assert result == expected
|
||||
|
||||
# Test uneven chunks
|
||||
result = chunk_list(data, 4)
|
||||
expected = [[1, 2, 3, 4], [5, 6, 7, 8], [9]]
|
||||
assert result == expected
|
||||
|
||||
# Test empty list
|
||||
result = chunk_list([], 3)
|
||||
assert result == []
|
||||
|
||||
class TestDataProcessor:
|
||||
|
||||
def test_process_numbers(self):
|
||||
processor = DataProcessor()
|
||||
numbers = [1.0, 2.0, 3.0, 4.0, 5.0]
|
||||
|
||||
result = processor.process_numbers(numbers)
|
||||
|
||||
assert result['count'] == 5
|
||||
assert result['sum'] == 15.0
|
||||
assert result['average'] == 3.0
|
||||
assert result['min'] == 1.0
|
||||
assert result['max'] == 5.0
|
||||
assert processor.processed_count == 1
|
||||
|
||||
def test_process_numbers_empty_list(self):
|
||||
processor = DataProcessor()
|
||||
result = processor.process_numbers([])
|
||||
assert result == {}
|
||||
assert processor.processed_count == 0
|
||||
Reference in New Issue
Block a user