Skip to content

Conversation

@momstrosity
Copy link
Owner

@momstrosity momstrosity commented May 20, 2025

Implement Efficient Prime Number Checker with Comprehensive Testing

Description

Task

Implement Prime Number Checker

Acceptance Criteria

  • Function should return boolean indicating if number is prime
  • Implement efficient primality test
  • Handle edge cases (negative numbers, 0, 1)
  • Include unit tests for various cases

Summary of Work

Prime Number Checker Implementation

Overview

This pull request adds a robust prime number checking function to validate whether a given integer is prime, with comprehensive testing and error handling.

Changes Made

  • Created src/prime_checker.py with an efficient prime number validation function
  • Implemented comprehensive input validation and error handling
  • Added detailed test suite in tests/test_prime_checker.py

Implementation Details

Function: is_prime(number: int) -> bool

  • Efficiently checks primality by testing divisibility up to the square root of the number
  • Handles special cases: 0, 1, and negative numbers
  • Provides strong type checking and input validation

Key Features

  • O(√n) time complexity for primality testing
  • Raises TypeError for non-integer inputs
  • Returns False for numbers less than 2
  • Supports testing of small and large prime/non-prime numbers

Testing Approach

  • Comprehensive test coverage using pytest
  • Test scenarios include:
    1. Verified prime numbers
    2. Known non-prime numbers
    3. Large prime and non-prime numbers
    4. Negative number handling
    5. Invalid input type checking

Test Results

  • 6 test cases implemented
  • All tests passing ✅
  • 100% coverage of major use cases

Acceptance Criteria

  • ✓ Correctly identifies prime numbers
  • ✓ Handles edge cases (0, 1, negative numbers)
  • ✓ Provides clear error handling
  • ✓ Efficient implementation
  • ✓ Comprehensive test coverage

Notes

  • Requires Python 3.6+
  • Pytest used for testing
  • Optimized for performance while maintaining readability

Changes Made

  • Created src/prime_checker.py with is_prime() function
  • Implemented efficient primality testing algorithm
  • Added comprehensive input validation
  • Created tests/test_prime_checker.py with multiple test scenarios
  • Ensured O(√n) time complexity for prime checking

Tests

  • Verify prime number detection
  • Test non-prime number identification
  • Check large prime and non-prime numbers
  • Validate handling of edge cases (0, 1, negative numbers)
  • Ensure proper error handling for invalid inputs

Signatures

Staking Key

AEghvdqmRtc3fjKXfNTMJJ6WshksgWuJ9YBExgsZu8cN: c2tmxxyqUFWDUAkXVxax2SyY6CboZrRydMzxZGMzpoZpgb8TM1Djr1PfnirQaNKtAEigKmyqem9oVDHnJ9CzxJPguAZpEGPuvUJ9WUL17KrbxVyWSkg7gbAF1FspkHa8NDk8QZfpb5HKZt1VgjudrzkA7YbbHs3yvEU3SmbqX58rejxpHJAnXanY6EAhYrUGVCUnkHAFiEcgWNNgWBZKxNogr5hFMv6r7QLk8yVgSxk8qaiZDYR4DPr3xfQ7GYGcL72n2DUWamTszb8ZZygrpJndYqyvDjJv1hjBJnWsZ4BnYdpEYFBfJCQuyC27kcLNJuBmQfMUZMivpoCTYp2oK1Dw7r5C9EJaSQsN1976mT7osfPPTGGGi9qoM1nyKsAavHomXwj9QiEnhw2AAFjHuMtybp6MuDnAR2

Public Key

AwXAtX7tMhL4JyB8NfXdsrqc1UifaMyap3c9bpN9RMse: bJjCTLZArb12qqzgn12UCL5x4uDiWCKWVzCHuBbt44qHRwAqRK8kFkhjwjCF5kehQLnRpWzNprckz1oDdtXyAKLpzzg6usb6Le3JwPbHDje895NKeZPjtKouKkvuxqFo9YhfYryCSaLvqxt7yxTkTcnx8y17a2ydCmcVj31rrwGidFT4SyqsdjDuY4p7gZcjzBaxRR2tsaDC3KTzLHnC7qAktD4xemEaeSUbAUsGbQmuTLWTeqgCFJXWvqeHEfDtZ5W1vaM51VArzt25qyktJ63rJQuykSm1YqM8jmhuqDqUdVe9s4GtKud3cLLLnN4yiBRmhJpdCt5eRxeDFBqbKD4PKgZdENY9Fc2p6a99BqGVASUyjob1g2kFFrjYz1QSS2ctnCwjfafU4jRnDcsmTpGaifna7Uydsi

@momstrosity momstrosity changed the title [WIP] Implement Prime Number Checker Function Implement Efficient Prime Number Checker with Comprehensive Testing May 20, 2025
@momstrosity momstrosity marked this pull request as ready for review May 20, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants