Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions __tests__/math.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Many functions are not tested, and edge cases are missing
*/

import { add, subtract, multiply, divide, factorial, isPrime, average, findMax } from '../src/utils/math';
import { add, subtract, divide, isPrime } from '../src/utils/math';

describe('Math Utilities', () => {
// Basic tests for add function
Expand All @@ -21,7 +21,7 @@ describe('Math Utilities', () => {
it('should subtract two numbers', () => {
expect(subtract(5, 3)).toBe(2);
});

// Missing: negative results, zero cases
});

Expand All @@ -35,7 +35,7 @@ describe('Math Utilities', () => {
it('should divide two numbers', () => {
expect(divide(10, 2)).toBe(5);
});

// BUG: Missing test for division by zero!
// This would catch the bug in the divide function
});
Expand All @@ -51,7 +51,7 @@ describe('Math Utilities', () => {
it('should return true for 7', () => {
expect(isPrime(7)).toBe(true);
});

// Missing: test for 1, 2, negative numbers, non-prime numbers
});

Expand All @@ -60,4 +60,4 @@ describe('Math Utilities', () => {

// No tests for findMax function!
// This function also has issues with empty arrays
});
});
36 changes: 18 additions & 18 deletions __tests__/todoApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Users can add these via workflows
*/

import { TodoApp, Todo } from '../src/bonus/todoApp';
import { TodoApp } from '../src/bonus/todoApp';

describe('TodoApp', () => {
let app: TodoApp;
Expand All @@ -16,7 +16,7 @@ describe('TodoApp', () => {
describe('addTodo', () => {
it('should add a new todo with default priority', () => {
const todo = app.addTodo('Test todo');

expect(todo.title).toBe('Test todo');
expect(todo.completed).toBe(false);
expect(todo.priority).toBe('medium');
Expand All @@ -25,7 +25,7 @@ describe('TodoApp', () => {

it('should add a todo with custom priority', () => {
const todo = app.addTodo('Urgent task', 'Fix critical bug', 'high');

expect(todo.priority).toBe('high');
expect(todo.description).toBe('Fix critical bug');
});
Expand All @@ -36,7 +36,7 @@ describe('TodoApp', () => {
app.addTodo('Todo 1');
app.addTodo('Todo 2');
app.addTodo('Todo 3');

const todos = app.getAllTodos();
expect(todos).toHaveLength(3);
});
Expand All @@ -50,7 +50,7 @@ describe('TodoApp', () => {
it('should return todo by ID', () => {
const todo1 = app.addTodo('First');
const todo2 = app.addTodo('Second');

expect(app.getTodoById(1)).toEqual(todo1);
expect(app.getTodoById(2)).toEqual(todo2);
});
Expand All @@ -63,9 +63,9 @@ describe('TodoApp', () => {
describe('completeTodo', () => {
it('should mark todo as completed', () => {
const todo = app.addTodo('Complete me');

const result = app.completeTodo(todo.id);

expect(result).toBe(true);
expect(app.getTodoById(todo.id)?.completed).toBe(true);
});
Expand All @@ -78,9 +78,9 @@ describe('TodoApp', () => {
describe('deleteTodo', () => {
it('should delete a todo', () => {
const todo = app.addTodo('Delete me');

const result = app.deleteTodo(todo.id);

expect(result).toBe(true);
expect(app.getTodoById(todo.id)).toBeUndefined();
expect(app.getAllTodos()).toHaveLength(0);
Expand All @@ -96,11 +96,11 @@ describe('TodoApp', () => {
const todo1 = app.addTodo('Incomplete 1');
const todo2 = app.addTodo('Complete me');
const todo3 = app.addTodo('Incomplete 2');

app.completeTodo(todo2.id);

const incomplete = app.getIncompleteTodos();

expect(incomplete).toHaveLength(2);
expect(incomplete.map(t => t.id)).toEqual([todo1.id, todo3.id]);
});
Expand All @@ -109,21 +109,21 @@ describe('TodoApp', () => {
describe('getCompletedTodos', () => {
it('should return only completed todos', () => {
const todo1 = app.addTodo('Todo 1');
const todo2 = app.addTodo('Todo 2');
app.addTodo('Todo 2');
const todo3 = app.addTodo('Todo 3');

app.completeTodo(todo1.id);
app.completeTodo(todo3.id);

const completed = app.getCompletedTodos();

expect(completed).toHaveLength(2);
expect(completed.map(t => t.id)).toEqual([todo1.id, todo3.id]);
});
});

// TODO: Tests for features to be implemented via workflows

describe.skip('markAllAsCompleted', () => {
it('should mark all todos as completed', () => {
// This test will be added when the feature is implemented
Expand All @@ -147,4 +147,4 @@ describe('TodoApp', () => {
// This test will be added when the feature is implemented
});
});
});
});
2 changes: 1 addition & 1 deletion __tests__/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ describe('Users API', () => {
expect(formatUserName(user)).toBe('JOHN DOE');
});
});
});
});
14 changes: 4 additions & 10 deletions api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,13 @@ export function isAdmin(userId: number): boolean {
return user.role === 'admin';
}

// Unused import that should be cleaned up (for Workflow #2)
import * as fs from 'fs';

// Console.log that should be removed (for Workflow #2)
console.log('Users API loaded');

/**
* Format user display name
* Missing proper formatting and has inconsistent spacing
*/
export function formatUserName(user: User): string {
// Inconsistent indentation (for ESLint to catch)
const displayName=user.name.toUpperCase(); // Missing spaces around =
return displayName
// Inconsistent indentation (for ESLint to catch)
const displayName = user.name.toUpperCase(); // Missing spaces around =
return displayName;
// Missing semicolon above (for Prettier to fix)
}
}
8 changes: 4 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* This file demonstrates how the various modules work together
*/

import { getUserById, getUserEmail, isAdmin } from './api/users';
import { add, subtract, multiply, divide } from './src/utils/math';
import { getUserById, getUserEmail } from './api/users';
import { add, multiply, divide } from './src/utils/math';
import { createLogger } from './src/helpers/logger';
import { TodoApp } from './src/bonus/todoApp';

Expand All @@ -16,7 +16,7 @@ logger.info('Testing Users API...');
try {
const user = getUserById(1);
logger.info(`Found user: ${user.name}`);

// This will cause an error with non-existent user
const email = getUserEmail(999);
logger.info(`User email: ${email}`);
Expand Down Expand Up @@ -48,4 +48,4 @@ const incomplete = todoApp.getIncompleteTodos();
logger.info(`${incomplete.length} todos remaining`);

// Export for testing
export { todoApp, logger };
export { todoApp, logger };
16 changes: 10 additions & 6 deletions src/bonus/todoApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export class TodoApp {
/**
* Add a new todo item
*/
addTodo(title: string, description?: string, priority: 'low' | 'medium' | 'high' = 'medium'): Todo {
addTodo(
title: string,
description?: string,
priority: 'low' | 'medium' | 'high' = 'medium'
): Todo {
const todo: Todo = {
id: this.nextId++,
title,
Expand All @@ -29,7 +33,7 @@ export class TodoApp {
createdAt: new Date(),
priority
};

this.todos.push(todo);
return todo;
}
Expand Down Expand Up @@ -88,13 +92,13 @@ export class TodoApp {

// FEATURE REQUEST: Add a method to mark all todos as completed
// This is intentionally missing for users to implement via workflows

// FEATURE REQUEST: Add a method to get todos by priority
// This is intentionally missing for users to implement via workflows

// FEATURE REQUEST: Add a method to update todo details
// This is intentionally missing for users to implement via workflows

// FEATURE REQUEST: Add a method to clear all completed todos
// This is intentionally missing for users to implement via workflows
}
Expand All @@ -106,4 +110,4 @@ app.addTodo('Fix bug in users.ts', 'TypeError when user not found', 'high');
app.addTodo('Add unit tests', 'Cover all math functions', 'medium');
app.addTodo('Update dependencies', 'Security vulnerabilities', 'high');
app.addTodo('Add documentation', 'JSDoc comments needed', 'low');
*/
*/
22 changes: 11 additions & 11 deletions src/helpers/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ export function createLogger(prefix?: string, level?: LogLevel): Logger {
// Missing JSDoc comment
export function parseLogLevel(level: string): LogLevel {
switch (level.toUpperCase()) {
case 'DEBUG':
return LogLevel.DEBUG;
case 'INFO':
return LogLevel.INFO;
case 'WARN':
return LogLevel.WARN;
case 'ERROR':
return LogLevel.ERROR;
default:
return LogLevel.INFO;
case 'DEBUG':
return LogLevel.DEBUG;
case 'INFO':
return LogLevel.INFO;
case 'WARN':
return LogLevel.WARN;
case 'ERROR':
return LogLevel.ERROR;
default:
return LogLevel.INFO;
}
}

Expand All @@ -99,4 +99,4 @@ export function formatError(error: Error): string {
return `${error.name}: ${error.message}\n${error.stack}`;
}

export { Logger, LogLevel };
export { Logger, LogLevel };
6 changes: 3 additions & 3 deletions src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export function factorial(n: number): number {
export function isPrime(n: number): boolean {
// Edge case: numbers less than 2 are not prime
if (n < 2) return false;

// Check for divisibility up to square root of n
for (let i = 2; i <= Math.sqrt(n); i++) {
if (n % i === 0) {
return false;
}
}

return true;
}

Expand All @@ -97,4 +97,4 @@ export function average(numbers: number[]): number {
export function findMax(numbers: number[]): number {
// BUG: What happens with empty array?
return Math.max(...numbers);
}
}
Loading
Loading