Skip to content

Commit 9616425

Browse files
committed
Adding new modules and test files.
1 parent 17d4100 commit 9616425

7 files changed

Lines changed: 67 additions & 2 deletions

File tree

src/arrayUtils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function findMax(numbers: number[]): number | null {
2+
if (numbers.length === 0) return null;
3+
return Math.max(...numbers);
4+
}
5+
6+
export function deduplicate<T>(arr: T[]): T[] {
7+
return [...new Set(arr)];
8+
}

src/math.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function multiply(a: number, b: number): number {
2+
return a * b;
3+
}
4+
5+
export function isEven(n: number): boolean {
6+
return n % 2 === 0;
7+
}

src/stringUtils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function reverseString(str: string): string {
2+
return str.split('').reverse().join('');
3+
}
4+
5+
export function capitalizeFirst(str: string): string {
6+
if (!str) return '';
7+
return str[0].toUpperCase() + str.slice(1);
8+
}

tests/arrayUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { findMax, deduplicate } from '../src/arrayUtils';
2+
3+
describe('arrayUtils.ts', () => {
4+
test('finds max in array', () => {
5+
expect(findMax([1, 2, 3, 9, 5])).toBe(9);
6+
expect(findMax([])).toBeNull();
7+
});
8+
9+
test('removes duplicate values from array', () => {
10+
expect(deduplicate([1, 2, 2, 3, 3, 3])).toEqual([1, 2, 3]);
11+
});
12+
});

tests/index.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { add } from '../src/index';
22

3-
test('adds 2 + 2 to equal 4', () => {
4-
expect(add(2, 2)).toBe(4);
3+
describe('index.ts', () => {
4+
test('adds positive numbers correctly', () => {
5+
expect(add(3, 7)).toBe(10);
6+
});
7+
8+
test('adds negative numbers correctly', () => {
9+
expect(add(-5, -6)).toBe(-11);
10+
});
511
});

tests/math.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { multiply, isEven } from '../src/math';
2+
3+
describe('math.ts', () => {
4+
test('multiplies numbers correctly', () => {
5+
expect(multiply(4, 5)).toBe(20);
6+
});
7+
8+
test('detects even numbers', () => {
9+
expect(isEven(4)).toBe(true);
10+
expect(isEven(5)).toBe(false);
11+
});
12+
});

tests/stringUtils.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { reverseString, capitalizeFirst } from '../src/stringUtils';
2+
3+
describe('stringUtils.ts', () => {
4+
test('reverses a string', () => {
5+
expect(reverseString('hello')).toBe('olleh');
6+
});
7+
8+
test('capitalizes first letter', () => {
9+
expect(capitalizeFirst('world')).toBe('World');
10+
expect(capitalizeFirst('')).toBe('');
11+
});
12+
});

0 commit comments

Comments
 (0)