From c3eb4f73729be50357de937556d7326e22ddaa1d Mon Sep 17 00:00:00 2001 From: swp Date: Sat, 4 Apr 2026 02:02:14 +0100 Subject: [PATCH] test: add validation functions for autonomous pipeline testing Created test files to verify full pipeline flow: - add.ts - Basic math functions (add, subtract, multiply, divide) - add.test.ts - Comprehensive test suite with Bun test framework These files will be used to test: - @sdet-engineer: Test writing (TDD) - @lead-developer: Implementation - @code-skeptic: Code review - @security-auditor: Security check - E2E pipeline flow --- src/validation/add.test.ts | 53 ++++++++++++++++++++++++++++++++++++++ src/validation/add.ts | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/validation/add.test.ts create mode 100644 src/validation/add.ts diff --git a/src/validation/add.test.ts b/src/validation/add.test.ts new file mode 100644 index 0000000..026c62a --- /dev/null +++ b/src/validation/add.test.ts @@ -0,0 +1,53 @@ +// Test file for validation functions +import { describe, it, expect } from 'bun:test' +import { add, subtract, multiply, divide } from './add' + +describe('Validation Functions', () => { + describe('add', () => { + it('should add two positive numbers', () => { + expect(add(2, 3)).toBe(5) + }) + + it('should add negative numbers', () => { + expect(add(-1, -2)).toBe(-3) + }) + + it('should add zero', () => { + expect(add(5, 0)).toBe(5) + }) + + it('should handle floating point', () => { + expect(add(0.1, 0.2)).toBeCloseTo(0.3) + }) + }) + + describe('subtract', () => { + it('should subtract two numbers', () => { + expect(subtract(5, 3)).toBe(2) + }) + + it('should handle negative result', () => { + expect(subtract(3, 5)).toBe(-2) + }) + }) + + describe('multiply', () => { + it('should multiply two numbers', () => { + expect(multiply(4, 3)).toBe(12) + }) + + it('should multiply by zero', () => { + expect(multiply(5, 0)).toBe(0) + }) + }) + + describe('divide', () => { + it('should divide two numbers', () => { + expect(divide(10, 2)).toBe(5) + }) + + it('should throw on division by zero', () => { + expect(() => divide(5, 0)).toThrow('Division by zero') + }) + }) +}) diff --git a/src/validation/add.ts b/src/validation/add.ts new file mode 100644 index 0000000..4988be2 --- /dev/null +++ b/src/validation/add.ts @@ -0,0 +1,46 @@ +// Test file for autonomous pipeline testing +// This should pass through: requirement-refiner → sdet-engineer → lead-developer → code-skeptic + +/** + * Adds two numbers + * @param a - First number + * @param b - Second number + * @returns Sum of a and b + */ +export function add(a: number, b: number): number { + return a + b +} + +/** + * Subtracts second number from first + * @param a - First number + * @param b - Second number + * @returns Difference of a and b + */ +export function subtract(a: number, b: number): number { + return a - b +} + +/** + * Multiplies two numbers + * @param a - First number + * @param b - Second number + * @returns Product of a and b + */ +export function multiply(a: number, b: number): number { + return a * b +} + +/** + * Divides first number by second + * @param a - Dividend + * @param b - Divisor + * @returns Quotient of a and b + * @throws Error if b is zero + */ +export function divide(a: number, b: number): number { + if (b === 0) { + throw new Error('Division by zero') + } + return a / b +}