Skip to content

Commit

Permalink
Added the test_cases files
Browse files Browse the repository at this point in the history
  • Loading branch information
Richajaishwal0 committed Oct 12, 2024
1 parent 4fddbd2 commit d480f86
Show file tree
Hide file tree
Showing 6 changed files with 196 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()

0 comments on commit d480f86

Please sign in to comment.