forked from UTSAVS26/PySnippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request UTSAVS26#93 from Richajaishwal0/feature/NumberChecker
AddednumberCheckingfiles
- Loading branch information
Showing
13 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |