UNPKG

claude-flow-novice

Version:

Claude Flow Novice - Advanced orchestration platform for multi-agent AI workflows with CFN Loop architecture Includes CodeSearch (hybrid SQLite + pgvector), mem0/memgraph specialists, and all CFN skills.

36 lines 8.81 kB
{ "conversationId": "py-v3-test-1765383241-1765383246751", "metadata": { "agentId": "py-v3-test-1765383241", "feature": "Statistics calculator that computes mean, median, and mode from list of numbers", "filePath": "/tmp/cerebras-test-py-v3/stats.py", "contextFiles": [], "completedAt": "2025-12-10T16:14:08.072Z" }, "conversation": [ { "role": "system", "content": "You are a TDD expert. Follow Red-Green-Refactor strictly. Use Given/When/Then test structure. Generate ONLY code - no markdown code blocks, no explanations, just raw code." }, { "role": "user", "content": "# TDD Red Phase: Write Failing Tests\n\n## Feature\nStatistics calculator that computes mean, median, and mode from list of numbers\n\n## Target Implementation File\n/tmp/cerebras-test-py-v3/stats.py\n\n## Context Files\n(none provided)\n\n## Requirements\n1. Write comprehensive tests using STANDARD test framework syntax (do NOT create custom helper functions):\n - **TypeScript/JavaScript**: Use describe/it/expect blocks from vitest or jest\n - Import framework: `import { describe, it, expect } from 'vitest';`\n - Import functions: `import { functionName } from './filename';`\n - Structure: `describe('feature', () => { it('should...', () => { expect(...).toBe(...) }) })`\n - **Python**: Use pytest with def test_* functions\n - Import: `from filename import ClassName` or `import pytest`\n - Structure: `def test_feature(): assert value == expected`\n - **Rust**: Use #[test] attribute or #[cfg(test)] module\n - Import: `use super::*;` or `use crate::module::*;`\n - Structure: `#[test] fn test_name() { assert_eq!(result, expected) }`\n2. Tests MUST fail initially (no implementation exists yet)\n3. Cover happy path AND edge cases\n4. Include setup/teardown if needed\n5. **CRITICAL: Include ALL necessary import statements at the top of the test file**\n6. **Do NOT create custom test helper functions (Given/When/Then helpers, etc.)**\n\nIMPORTANT: Generate ONLY the test file content. No markdown code blocks, no explanations, just raw code.", "timestamp": "2025-12-10T16:14:06.752Z" }, { "role": "assistant", "content": "\nimport pytest\nfrom stats import StatisticsCalculator\n\ndef test_mean_empty_list():\n calc = StatisticsCalculator()\n with pytest.raises(ValueError):\n calc.mean([])\n\ndef test_mean_single_number():\n calc = StatisticsCalculator()\n assert calc.mean([5]) == 5\n\ndef test_mean_positive_numbers():\n calc = StatisticsCalculator()\n assert calc.mean([1, 2, 3, 4, 5]) == 3\n\ndef test_mean_negative_numbers():\n calc = StatisticsCalculator()\n assert calc.mean([-1, -2, -3, -4, -5]) == -3\n\ndef test_mean_mixed_numbers():\n calc = StatisticsCalculator()\n assert calc.mean([-2, 0, 2]) == 0\n\ndef test_mean_with_floats():\n calc = StatisticsCalculator()\n assert calc.mean([1.5, 2.5, 3.0]) == 2.3333333333333335\n\ndef test_median_empty_list():\n calc = StatisticsCalculator()\n with pytest.raises(ValueError):\n calc.median([])\n\ndef test_median_single_number():\n calc = StatisticsCalculator()\n assert calc.median([5]) == 5\n\ndef test_median_odd_count():\n calc = StatisticsCalculator()\n assert calc.median([1, 3, 5]) == 3\n\ndef test_median_even_count():\n calc = StatisticsCalculator()\n assert calc.median([1, 2, 3, 4]) == 2.5\n\ndef test_median_unsorted():\n calc = StatisticsCalculator()\n assert calc.median([5, 1, 3, 2, 4]) == 3\n\ndef test_median_with_floats():\n calc = StatisticsCalculator()\n assert calc.median([1.5, 2.5, 3.5, 4.5]) == 3.0\n\ndef test_mode_empty_list():\n calc = StatisticsCalculator()\n with pytest.raises(ValueError):\n calc.mode([])\n\ndef test_mode_single_number():\n calc = StatisticsCalculator()\n assert calc.mode([5]) == [5]\n\ndef test_mode_unique_numbers():\n calc = StatisticsCalculator()\n assert calc.mode([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n\ndef test_mode_with_duplicates():\n calc = StatisticsCalculator()\n assert calc.mode([1, 2, 2, 3, 3, 3, 4]) == [3]\n\ndef test_mode_multiple_modes():\n calc = StatisticsCalculator()\n assert calc.mode([1, 1, 2, 2, 3, 4]) == [1, 2]\n\ndef test_mode_with_negative_numbers():\n calc = StatisticsCalculator()\n assert calc.mode([-1, -1, -2, -3]) == [-1]\n\ndef test_mode_with_floats():\n calc = StatisticsCalculator()\n assert calc.mode([1.5, 1.5, 2.5, 3.5]) == [1.5]", "timestamp": "2025-12-10T16:14:07.447Z" }, { "role": "user", "content": "# TDD Green Phase: Write Implementation\n\nThe tests you just wrote are now failing. Write the MINIMUM implementation to make them pass.\n\n## Test File Content\n```\nimport pytest\nfrom stats import StatisticsCalculator\n\ndef test_mean_empty_list():\n calc = StatisticsCalculator()\n with pytest.raises(ValueError):\n calc.mean([])\n\ndef test_mean_single_number():\n calc = StatisticsCalculator()\n assert calc.mean([5]) == 5\n\ndef test_mean_positive_numbers():\n calc = StatisticsCalculator()\n assert calc.mean([1, 2, 3, 4, 5]) == 3\n\ndef test_mean_negative_numbers():\n calc = StatisticsCalculator()\n assert calc.mean([-1, -2, -3, -4, -5]) == -3\n\ndef test_mean_mixed_numbers():\n calc = StatisticsCalculator()\n assert calc.mean([-2, 0, 2]) == 0\n\ndef test_mean_with_floats():\n calc = StatisticsCalculator()\n assert calc.mean([1.5, 2.5, 3.0]) == 2.3333333333333335\n\ndef test_median_empty_list():\n calc = StatisticsCalculator()\n with pytest.raises(ValueError):\n calc.median([])\n\ndef test_median_single_number():\n calc = StatisticsCalculator()\n assert calc.median([5]) == 5\n\ndef test_median_odd_count():\n calc = StatisticsCalculator()\n assert calc.median([1, 3, 5]) == 3\n\ndef test_median_even_count():\n calc = StatisticsCalculator()\n assert calc.median([1, 2, 3, 4]) == 2.5\n\ndef test_median_unsorted():\n calc = StatisticsCalculator()\n assert calc.median([5, 1, 3, 2, 4]) == 3\n\ndef test_median_with_floats():\n calc = StatisticsCalculator()\n assert calc.median([1.5, 2.5, 3.5, 4.5]) == 3.0\n\ndef test_mode_empty_list():\n calc = StatisticsCalculator()\n with pytest.raises(ValueError):\n calc.mode([])\n\ndef test_mode_single_number():\n calc = StatisticsCalculator()\n assert calc.mode([5]) == [5]\n\ndef test_mode_unique_numbers():\n calc = StatisticsCalculator()\n assert calc.mode([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n\ndef test_mode_with_duplicates():\n calc = StatisticsCalculator()\n assert calc.mode([1, 2, 2, 3, 3, 3, 4]) == [3]\n\ndef test_mode_multiple_modes():\n calc = StatisticsCalculator()\n assert calc.mode([1, 1, 2, 2, 3, 4]) == [1, 2]\n\ndef test_mode_with_negative_numbers():\n calc = StatisticsCalculator()\n assert calc.mode([-1, -1, -2, -3]) == [-1]\n\ndef test_mode_with_floats():\n calc = StatisticsCalculator()\n assert calc.mode([1.5, 1.5, 2.5, 3.5]) == [1.5]\n```\n\n## Target Implementation File\n/tmp/cerebras-test-py-v3/stats.py\n\n## Requirements\n1. Implement ONLY what the tests require\n2. Don't add extra features (YAGNI)\n3. Make all tests pass\n4. Follow existing code patterns from context\n5. **CRITICAL: Export all functions/classes that the tests import**\n6. **For TypeScript/JavaScript: use `export function name()` or `export { name }`**\n7. **For Python: functions are exported by default**\n8. **For Rust: use `pub fn name()` for public functions**\n\nIMPORTANT: Generate ONLY the implementation file content. No markdown code blocks, no explanations, just raw code.", "timestamp": "2025-12-10T16:14:07.447Z" }, { "role": "assistant", "content": "\nclass StatisticsCalculator:\n def mean(self, numbers):\n if not numbers:\n raise ValueError(\"List cannot be empty\")\n return sum(numbers) / len(numbers)\n \n def median(self, numbers):\n if not numbers:\n raise ValueError(\"List cannot be empty\")\n sorted_numbers = sorted(numbers)\n n = len(sorted_numbers)\n if n % 2 == 1:\n return sorted_numbers[n // 2]\n else:\n return (sorted_numbers[n // 2 - 1] + sorted_numbers[n // 2]) / 2\n \n def mode(self, numbers):\n if not numbers:\n raise ValueError(\"List cannot be empty\")\n frequency = {}\n for num in numbers:\n frequency[num] = frequency.get(num, 0) + 1\n \n max_freq = max(frequency.values())\n modes = [num for num, freq in frequency.items() if freq == max_freq]\n \n return sorted(modes)", "timestamp": "2025-12-10T16:14:07.698Z" } ] }