From 9d5d7d6387525b549488570e74dfcb9a43eb8a6e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 13 Jun 2026 12:37:05 +0000 Subject: [PATCH] Add tests for Super factorial.py Wrapped the interactive root-level logic in Super factorial.py inside an `if __name__ == '__main__':` block to prevent blocking upon import. Created a unittest file `test_super_factorial.py` that dynamically imports `Super factorial.py` to test the `part1` logic across various scenarios including 0, 1, small numbers, and a large number. Tested locally. Co-authored-by: ManupaKDU <95234271+ManupaKDU@users.noreply.github.com> --- Part-1/Hackerrank/Super factorial.py | 21 +++++++------- Part-1/Hackerrank/test_super_factorial.py | 34 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 Part-1/Hackerrank/test_super_factorial.py diff --git a/Part-1/Hackerrank/Super factorial.py b/Part-1/Hackerrank/Super factorial.py index a7e7693..b28a9a0 100644 --- a/Part-1/Hackerrank/Super factorial.py +++ b/Part-1/Hackerrank/Super factorial.py @@ -12,13 +12,14 @@ def part1(ass): return total_1 -ass = int(input()) -count_1 = ass -if 0 <= ass <= 750 : - total_1 = part1(ass) - while count_1 > 0 : - total_1 *= ass - count_1 -= 1 - print(total_1) -else: - print("Invalid answer. ") +if __name__ == '__main__': + ass = int(input()) + count_1 = ass + if 0 <= ass <= 750 : + total_1 = part1(ass) + while count_1 > 0 : + total_1 *= ass + count_1 -= 1 + print(total_1) + else: + print("Invalid answer. ") diff --git a/Part-1/Hackerrank/test_super_factorial.py b/Part-1/Hackerrank/test_super_factorial.py new file mode 100644 index 0000000..7e6c771 --- /dev/null +++ b/Part-1/Hackerrank/test_super_factorial.py @@ -0,0 +1,34 @@ +import unittest +import importlib.util +import os +import sys + +# Add the directory to the path so we can import the module with spaces in the name +current_dir = os.path.dirname(os.path.abspath(__file__)) +if current_dir not in sys.path: + sys.path.insert(0, current_dir) + +# Import the module with spaces in the filename +spec = importlib.util.spec_from_file_location("super_factorial", os.path.join(current_dir, "Super factorial.py")) +super_factorial = importlib.util.module_from_spec(spec) +spec.loader.exec_module(super_factorial) + +class TestSuperFactorial(unittest.TestCase): + def test_part1_zero(self): + self.assertEqual(super_factorial.part1(0), 1) + + def test_part1_one(self): + self.assertEqual(super_factorial.part1(1), 1) + + def test_part1_small_numbers(self): + self.assertEqual(super_factorial.part1(2), 2) + self.assertEqual(super_factorial.part1(3), 6) + self.assertEqual(super_factorial.part1(4), 24) + self.assertEqual(super_factorial.part1(5), 120) + + def test_part1_large_number(self): + # 10! = 3628800 + self.assertEqual(super_factorial.part1(10), 3628800) + +if __name__ == '__main__': + unittest.main()