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
This commit is contained in:
swp
2026-04-04 02:02:14 +01:00
parent 657407d5ef
commit c3eb4f7372
2 changed files with 99 additions and 0 deletions

View File

@@ -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')
})
})
})

46
src/validation/add.ts Normal file
View File

@@ -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
}