mirror of
https://github.com/Hizenberg469/Python-tutorial.git
synced 2026-04-19 23:12:24 +03:00
OOP finished
This commit is contained in:
@@ -1,57 +1,13 @@
|
||||
import unittest
|
||||
import random
|
||||
def j(n):
|
||||
if n == 1:
|
||||
return 1
|
||||
|
||||
if n % 2 == 0 :
|
||||
return 2 * j(n/2) - 1
|
||||
else:
|
||||
return 2 * j((n-1)/2) + 1
|
||||
|
||||
|
||||
globals = None
|
||||
report = unittest.Report()
|
||||
class ODD_EVEN_TEST_001(unittest.SystemTestCase):
|
||||
for i in range(1,33):
|
||||
print(f'{i} : {j(i)}')
|
||||
|
||||
@classmethod
|
||||
def setUpClass(inst):
|
||||
""" Add the initial configuration if any """
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(inst):
|
||||
""" Add the teardown configuration if any """
|
||||
|
||||
# """Add the definitions for tests defined in suite here"""
|
||||
# def dummy_assert(self):
|
||||
# report.normal("This is normal print")
|
||||
# report.error("This is errored print")
|
||||
# report.notification("This is notify print")
|
||||
# assrt=unittest.Assert(self)
|
||||
# assrt.isEquals("1", "2", "1 Equals 2")
|
||||
# assrt.isEquals("1", "1", "1 Equals 2")
|
||||
|
||||
def generate_number(self,seed_value):
|
||||
random.seed(seed_value)
|
||||
|
||||
gen_value = random.randrange(1,7)
|
||||
|
||||
return gen_value
|
||||
|
||||
|
||||
def check_testcase(self):
|
||||
|
||||
for x in range(1,26):
|
||||
generated_value = self.generate_number(x)
|
||||
|
||||
report.normal(f'For test case {x}:')
|
||||
assrt = unittest.Assert(self)
|
||||
|
||||
if( generated_value == 3):
|
||||
assrt.isEquals("1",str(generated_value), "You win!!!")
|
||||
elif( generated_value == 6):
|
||||
assrt.isEquals("6",str(generated_value), "You win!!!")
|
||||
else:
|
||||
assrt.isEquals("6",str(generated_value), "You lose!!!")
|
||||
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
"""Add your tests into the suite here"""
|
||||
suite.addTest(ODD_EVEN_TEST_001("check_testcase"))
|
||||
return suite
|
||||
|
||||
def main():
|
||||
runner = unittest.TextTestRunner()
|
||||
return runner.run(suite())
|
||||
|
||||
Reference in New Issue
Block a user