diff --git a/.trae/specs/hello-feature/checklist.md b/.trae/specs/hello-feature/checklist.md new file mode 100644 index 0000000..885862c --- /dev/null +++ b/.trae/specs/hello-feature/checklist.md @@ -0,0 +1,7 @@ +- [x] Hello module structure is created with proper organization +- [x] Hello function returns "Hello" message when called without parameters +- [x] Hello function returns personalized greeting when name parameter is provided +- [x] Error handling is implemented for edge cases +- [x] Test file exists with comprehensive test coverage +- [x] All tests pass successfully +- [x] Code follows project conventions and style guidelines diff --git a/.trae/specs/hello-feature/spec.md b/.trae/specs/hello-feature/spec.md new file mode 100644 index 0000000..ae9d5ae --- /dev/null +++ b/.trae/specs/hello-feature/spec.md @@ -0,0 +1,31 @@ +# Hello Feature Spec + +## Why +Implement a basic "hello" feature to demonstrate the spec-driven development workflow and establish a foundation for future features. + +## What Changes +- Add a simple hello functionality that outputs a greeting message +- Create basic structure for handling greeting requests +- Implement configurable greeting messages + +## Impact +- Affected specs: None (new feature) +- Affected code: New greeting module/component + +## ADDED Requirements +### Requirement: Greeting Feature +The system SHALL provide a hello/greeting functionality that responds with a welcome message. + +#### Scenario: Success case +- **WHEN** user requests a greeting +- **THEN** system returns a friendly "Hello" message + +#### Scenario: Custom greeting +- **WHEN** user provides a name parameter +- **THEN** system returns a personalized greeting with the name + +## MODIFIED Requirements +None + +## REMOVED Requirements +None diff --git a/.trae/specs/hello-feature/tasks.md b/.trae/specs/hello-feature/tasks.md new file mode 100644 index 0000000..db67c58 --- /dev/null +++ b/.trae/specs/hello-feature/tasks.md @@ -0,0 +1,18 @@ +# Tasks +- [x] Task 1: Create hello module structure + - [x] Subtask 1.1: Create directory structure for hello feature + - [x] Subtask 1.2: Add module initialization file + +- [x] Task 2: Implement hello functionality + - [x] Subtask 2.1: Create hello function that returns greeting message + - [x] Subtask 2.2: Add support for optional name parameter + - [x] Subtask 2.3: Add basic error handling + +- [x] Task 3: Add tests for hello feature + - [x] Subtask 3.1: Create test file for hello module + - [x] Subtask 3.2: Add test cases for basic greeting + - [x] Subtask 3.3: Add test cases for personalized greeting + +# Task Dependencies +- [Task 2] depends on [Task 1] +- [Task 3] depends on [Task 2] diff --git a/pycchess/hello.py b/pycchess/hello.py new file mode 100644 index 0000000..7ba3dba --- /dev/null +++ b/pycchess/hello.py @@ -0,0 +1,31 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# pycchess - just another chinese chess UI +# Copyright (C) 2011 - 2015 timebug + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +""" +The hello module provides basic greeting functionality for the pycchess application. + +This module serves as an example module following the project's coding standards +and licensing requirements. +""" + + +def hello(name=None): + if name is None or not isinstance(name, str) or not name.strip(): + return "Hello" + return "Hello, {}!".format(name.strip()) diff --git a/pycchess/test_hello.py b/pycchess/test_hello.py new file mode 100644 index 0000000..fcef92e --- /dev/null +++ b/pycchess/test_hello.py @@ -0,0 +1,78 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# pycchess - just another chinese chess UI +# Copyright (C) 2011 - 2015 timebug + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +""" +Test module for the hello functionality. + +This module contains unit tests for the hello function. +""" + +from hello import hello + + +def test_hello_no_args(): + result = hello() + assert result == "Hello", "hello() should return 'Hello'" + + +def test_hello_with_name(): + result = hello("World") + assert result == "Hello, World!", "hello('World') should return 'Hello, World!'" + + +def test_hello_empty_string(): + result = hello("") + assert result == "Hello", "hello('') should return 'Hello'" + + +def test_hello_none(): + result = hello(None) + assert result == "Hello", "hello(None) should return 'Hello'" + + +def test_hello_whitespace_only(): + result = hello(" ") + assert result == "Hello", "hello(' ') should return 'Hello'" + + +def test_hello_with_whitespace(): + result = hello(" Alice ") + assert result == "Hello, Alice!", "hello(' Alice ') should return 'Hello, Alice!'" + + +if __name__ == "__main__": + test_hello_no_args() + print("test_hello_no_args passed") + + test_hello_with_name() + print("test_hello_with_name passed") + + test_hello_empty_string() + print("test_hello_empty_string passed") + + test_hello_none() + print("test_hello_none passed") + + test_hello_whitespace_only() + print("test_hello_whitespace_only passed") + + test_hello_with_whitespace() + print("test_hello_with_whitespace passed") + + print("\nAll tests passed!")