CC-301h · Module 1

Edge Case Discovery

3 min read

Claude is exceptionally good at discovering edge cases because it has seen millions of functions and knows the edge cases that commonly break them. The prompt "What edge cases should I test for this function?" produces a surprisingly thorough list. For a string processing function, Claude identifies: empty string, whitespace-only string, Unicode characters, strings longer than expected, null/undefined. For a numeric function: zero, negative numbers, floating-point precision, Number.MAX_SAFE_INTEGER, NaN, Infinity.

The technique scales to complex business logic. "This function calculates shipping costs based on weight, destination, and membership tier. What edge cases should I consider?" Claude generates: zero weight, fractional weight, destination outside service area, unknown membership tier, free shipping threshold exactly met, multiple items with combined weight exceeding limits, international destinations with customs. These are the cases that real users encounter and that developers often forget to test.

// Prompt: "Write edge case tests for this discount calculator"
// Claude generates cases you might not consider:

test('zero quantity returns zero discount', () => {
  expect(calculateDiscount(0, 'premium')).toBe(0);
});

test('negative quantity throws', () => {
  expect(() => calculateDiscount(-1, 'premium')).toThrow();
});

test('unknown tier falls back to base rate', () => {
  expect(calculateDiscount(10, 'nonexistent' as any)).toBe(0);
});

test('discount never exceeds item price', () => {
  expect(calculateDiscount(1, 'premium')).toBeLessThanOrEqual(100);
});