Skip to content

Commit

Permalink
Merge pull request UTSAVS26#93 from Richajaishwal0/feature/NumberChecker
Browse files Browse the repository at this point in the history
AddednumberCheckingfiles
  • Loading branch information
UTSAVS26 authored Oct 30, 2024
2 parents 4239e9a + d480f86 commit 9504139
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Tests/SpecialNumbers/Test_Armstrong.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
from Armstrong import is_armstrong

class TestIsArmstrong(unittest.TestCase):

def test_case_armstrong_number(self):
# Test with an Armstrong number (153)
self.assertEqual(is_armstrong(153), "153 is an Armstrong number.")

def test_case_non_armstrong_number(self):
# Test with a non-Armstrong number (13)
self.assertEqual(is_armstrong(13), "13 is not an Armstrong number.")

def test_case_single_digit(self):
# Test with a single digit number (all single digits are Armstrong numbers)
self.assertEqual(is_armstrong(5), "5 is an Armstrong number.")

def test_case_large_armstrong_number(self):
# Test with a large Armstrong number (9474)
self.assertEqual(is_armstrong(9474), "9474 is an Armstrong number.")

def test_case_large_non_armstrong_number(self):
# Test with a large non-Armstrong number (9475)
self.assertEqual(is_armstrong(9475), "9475 is not an Armstrong number.")

if __name__ == "__main__":
unittest.main()
24 changes: 24 additions & 0 deletions Tests/SpecialNumbers/Test_Automorphic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest
from Automorphic import is_automorphic

class TestIsAutomorphic(unittest.TestCase):

def test_case_automorphic_number(self):
self.assertEqual(is_automorphic(25), "25 is an Automorphic number.")
self.assertEqual(is_automorphic(5), "5 is an Automorphic number.")

def test_case_non_automorphic_number(self):
self.assertEqual(is_automorphic(16), "16 is not an Automorphic number.")
self.assertEqual(is_automorphic(7), "7 is not an Automorphic number.")

def test_case_single_digit_automorphic(self):
self.assertEqual(is_automorphic(6), "6 is an Automorphic number.") # 6^2 = 36

def test_case_large_automorphic_number(self):
self.assertEqual(is_automorphic(376), "376 is an Automorphic number.") # 376^2 = 141376

def test_case_large_non_automorphic_number(self):
self.assertEqual(is_automorphic(123), "123 is not an Automorphic number.")

if __name__ == "__main__":
unittest.main()
40 changes: 40 additions & 0 deletions Tests/SpecialNumbers/Test_Neon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import unittest
from Neon import is_neon
from io import StringIO
import sys

class TestIsNeon(unittest.TestCase):

def setUp(self):
# Redirect stdout to capture print statements
self.held, sys.stdout = sys.stdout, StringIO()

def tearDown(self):
# Restore original stdout
sys.stdout = self.held

def test_case_neon_number(self):
is_neon(9)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "9 is a Neon number.")

is_neon(1)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "1 is a Neon number.")

def test_case_non_neon_number(self):
is_neon(20)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "20 is not a Neon number.")

is_neon(5)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "5 is not a Neon number.")

def test_case_large_non_neon_number(self):
is_neon(100)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "100 is not a Neon number.")

if __name__ == "__main__":
unittest.main()
35 changes: 35 additions & 0 deletions Tests/SpecialNumbers/Test_Palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
from Palindrome import is_palindrome
from io import StringIO
import sys

class TestIsPalindrome(unittest.TestCase):

def setUp(self):
# Redirect stdout to capture print statements
self.held, sys.stdout = sys.stdout, StringIO()

def tearDown(self):
# Restore original stdout
sys.stdout = self.held

def test_case_palindrome_number(self):
is_palindrome(101)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "101 is a palindrome.")

is_palindrome(12321)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "12321 is a palindrome.")

def test_case_non_palindrome_number(self):
is_palindrome(10)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "10 is not a palindrome.")

is_palindrome(123)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "123 is not a palindrome.")

if __name__ == "__main__":
unittest.main()
35 changes: 35 additions & 0 deletions Tests/SpecialNumbers/Test_Perfect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
from PerfectNumber import is_perfect
from io import StringIO
import sys

class TestIsPerfect(unittest.TestCase):

def setUp(self):
# Redirect stdout to capture print statements
self.held, sys.stdout = sys.stdout, StringIO()

def tearDown(self):
# Restore original stdout
sys.stdout = self.held

def test_case_perfect_number(self):
is_perfect(6)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "6 is a Perfect number.")

is_perfect(28)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "28 is a Perfect number.")

def test_case_non_perfect_number(self):
is_perfect(20)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "20 is not a Perfect number.")

is_perfect(12)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "12 is not a Perfect number.")

if __name__ == "__main__":
unittest.main()
35 changes: 35 additions & 0 deletions Tests/SpecialNumbers/Test_strong.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
from Strong import is_strong
from io import StringIO
import sys

class TestIsStrong(unittest.TestCase):

def setUp(self):
# Redirect stdout to capture print statements
self.held, sys.stdout = sys.stdout, StringIO()

def tearDown(self):
# Restore original stdout
sys.stdout = self.held

def test_case_strong_number(self):
is_strong(145)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "145 is a Strong number.")

is_strong(1)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "1 is a Strong number.")

def test_case_non_strong_number(self):
is_strong(134)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "134 is not a Strong number.")

is_strong(10)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, "10 is not a Strong number.")

if __name__ == "__main__":
unittest.main()
16 changes: 16 additions & 0 deletions pysnippets/SpecialNumbers/Armstrong.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def is_armstrong(number):
num_str = str(number)
num_digits = len(num_str)

armstrong_sum = sum(int(digit) ** num_digits for digit in num_str)
if (armstrong_sum == number):
print(f"{number} is an Armstrong number.")
else:
print(f"{number} is not an Armstrong number.")


if __name__ == "__main__":
# Input from user
is_armstrong(153)
is_armstrong(13)

13 changes: 13 additions & 0 deletions pysnippets/SpecialNumbers/Automorphic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def is_automorphic(number):
square = number ** 2
if(str(square).endswith(str(number))):
print(f"{number} is an Automorphic number.")
else:
print(f"{number} is not an Automorphic number.")




if __name__ == "__main__":
is_automorphic(25)
is_automorphic(16)
14 changes: 14 additions & 0 deletions pysnippets/SpecialNumbers/Neon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def is_neon(number):
square = number ** 2
digit_sum = sum(int(digit) for digit in str(square))
if(digit_sum == number):
print(f"{number} is a Neon number.")
else:
print(f"{number} is not a Neon number.")



if __name__ == "__main__":
is_neon(9)
is_neon(20)

15 changes: 15 additions & 0 deletions pysnippets/SpecialNumbers/Palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def is_palindrome(number):
# Convert the number to a string to easily reverse it
str_num = str(number)

# Check if the original number is the same as its reverse
if str_num == str_num[::-1]:
print(f"{number} is a palindrome.")
else:
print(f"{number} is not a palindrome.")


# Example usage
if __name__ == "__main__":
is_palindrome(101)
is_palindrome(10)
17 changes: 17 additions & 0 deletions pysnippets/SpecialNumbers/PerfectNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def is_perfect(number):
# Find all divisors of the number (excluding the number itself)
divisors_sum = sum(i for i in range(1, number) if number % i == 0)

# Check if the sum of divisors equals the original number
if (divisors_sum == number):
print(f"{number} is a Perfect number.")
else:
print(f"{number} is not a Perfect number.")



if __name__ == "__main__":
# Input from user
is_perfect(6)
is_perfect(20)

21 changes: 21 additions & 0 deletions pysnippets/SpecialNumbers/Strong.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import math

def is_strong(number):
num_str = str(number)

# Calculate the sum of factorials of each digit
strong_sum = sum(math.factorial(int(digit)) for digit in num_str)

# Check if the sum equals the original number
if (strong_sum == number):
print(f"{number} is a Strong number.")
else:
print(f"{number} is not a Strong number.")


if __name__ == "__main__":
# Input from user
is_strong(145)
is_strong(134)


4 changes: 4 additions & 0 deletions pysnippets/SpecialNumbers/_init_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# __init__.py

# This file allows the snippets folder to be treated as a package.
# It can be empty or used to expose certain functions for easy imports.

0 comments on commit 9504139

Please sign in to comment.