Skip to content

Add pytest number guessing game - #42

Open
Nonoka-T wants to merge 3 commits into
sehmaluva:mainfrom
Nonoka-T:add-pytest-number-guessing-game
Open

Add pytest number guessing game#42
Nonoka-T wants to merge 3 commits into
sehmaluva:mainfrom
Nonoka-T:add-pytest-number-guessing-game

Conversation

@Nonoka-T

Copy link
Copy Markdown
Contributor

📋 Description

This PR adds a pytest test suite for the Number Guessing Game challenge.

What type of contribution is this?

  • 👤 Profile (Adding or updating a student profile)
  • 🧩 Challenge (Solving a coding challenge)
  • 🚀 Project (Building a new project or feature)
  • 📜 Script (Adding a helpful script or tool)
  • 📝 Documentation (Improving docs, README, or guides)
  • 🐛 Bug Fix (Fixing an issue)
  • ✨ Enhancement (Improving existing functionality)
  • 🎨 Design (UI/UX improvements)

What does this PR do?

This PR adds pytest tests for the testable logic functions in sehmaluva_number_guessing_game.py. Functions that rely on input() such as select_difficulty and get_guess were intentionally excluded since they require interactive user input.

Related Issue


🎯 For Beginners: Step-by-Step Guide

Before Submitting

  1. ✅ I have tested my changes locally

    • Run your code to make sure it works
    • Check for any errors or warnings
  2. ✅ I have followed the project guidelines

  3. ✅ I have updated documentation (if needed)

    • Updated README if adding new features
    • Added comments to complex code
    • Created/updated any relevant docs

Need Help?

  • 💬 Ask questions in the comments below
  • 📖 Read the guides in docs/guides/
  • 🆘 Tag a maintainer with @mention if stuck
  • 🎓 Check our FAQ for common issues

🧪 Testing

How to test this PR?

  1. Navigate to challenges/intermediate/number-guessing-game/tests/
  2. Run pytest test_number_guessing_game.py -v
  3. Confirm all 7 tests pass

Test Results

<img width="952" height="335" alt="Screenshot 2026-06-14 at 18 23 45" src="https://github.com/user-attachments/assets/2c72a88f-5c0b-4356-b465-d8583a114feb" />


📸 Screenshots / Demo

Before

After


📝 Checklist

Code Quality

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings or errors
  • I have checked for and fixed any typos

Documentation

  • I have updated the README (if applicable)
  • I have added/updated comments in my code
  • I have updated relevant documentation in /docs
  • My profile follows the template (for profile contributions)

Testing & Validation

  • I have tested my changes locally
  • I have added tests that prove my fix/feature works (if applicable)
  • All existing tests pass with my changes
  • I have checked that my changes don't break other features

Git & Commit

  • My branch is up to date with the main branch
  • I have used clear, descriptive commit messages
  • I have squashed any unnecessary commits
  • My PR title clearly describes what this PR does

🎓 For Different Contribution Types

📱 Profile Contributions

Profile Checklist

  • Used the profile template from docs/templates/PROFILE_TEMPLATE.md
  • File is named profiles/YOUR_GITHUB_USERNAME.md
  • Included your name, school, and interests
  • Profile is professional and respectful
  • No personal sensitive information included

Profile Tips

  • ✅ Be authentic and showcase your personality
  • ✅ Include your learning goals
  • ✅ Mention technologies you're interested in
  • ✅ Add a fun fact about yourself
  • ❌ Don't include email, phone, or address
  • ❌ Don't use offensive language
🧩 Challenge Solutions

Challenge Checklist

  • My solution is in the correct directory (challenges/level/challenge-name/)
  • I have included clear comments explaining my approach
  • My solution handles edge cases
  • I have tested with different inputs
  • My code follows the challenge requirements

Challenge Tips

  • ✅ Explain your thought process in comments
  • ✅ Consider time and space complexity
  • ✅ Test with edge cases (empty inputs, large numbers, etc.)
  • ✅ Write clean, readable code
  • ❌ Don't just copy solutions from the internet
  • ❌ Don't submit untested code
🚀 Project Contributions

Project Checklist

  • Project has a clear README with setup instructions
  • All dependencies are documented
  • Code is organized and well-structured
  • Project follows the directory structure guidelines
  • Includes examples or demo (if applicable)

Project Tips

  • ✅ Include a demo or screenshots
  • ✅ Write clear setup/installation steps
  • ✅ Add error handling
  • ✅ Make it beginner-friendly
  • ✅ Include a "How to Use" section
  • ❌ Don't commit node_modules, .env, or build artifacts
  • ❌ Don't include sensitive data or API keys
📝 Documentation

Documentation Checklist

  • Writing is clear and easy to understand
  • Grammar and spelling are correct
  • Links are working and relevant
  • Examples are included where helpful
  • Follows the project's documentation style

Documentation Tips

  • ✅ Write for beginners
  • ✅ Use examples to clarify complex topics
  • ✅ Break content into sections with headers
  • ✅ Include code blocks with proper syntax highlighting
  • ❌ Don't assume prior knowledge
  • ❌ Don't use overly technical jargon without explanation

🌟 Additional Information

What I learned while working on this:

How to separate "pure logic" functions which take inputs and return outputs like calculate_score from interactive functions which rely on input() so that the pure logic can be tested without simulating user input.

Challenges I faced:

Since the solution file is in a different folder than the test file, I needed to use sys.path.insert to make the import work correctly.

Questions for reviewers:


📚 Resources I Used


💬 Notes for Reviewers


@Nonoka-T

Copy link
Copy Markdown
Contributor Author

@sehmaluva Hi, I added a pytest to your Number Guessing Game. Please kindly check this PR. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] - Add pytest test for Number Guessing Game

1 participant