Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Part-1/Hackerrank/Super factorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. ")
34 changes: 34 additions & 0 deletions Part-1/Hackerrank/test_super_factorial.py
Original file line number Diff line number Diff line change
@@ -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()