mirror of
https://github.com/Hizenberg469/Python-tutorial.git
synced 2026-04-19 23:12:24 +03:00
second commit
This commit is contained in:
@@ -1,3 +1,57 @@
|
|||||||
var = '12345'
|
import unittest
|
||||||
|
import random
|
||||||
|
|
||||||
print(var[0:2])
|
globals = None
|
||||||
|
report = unittest.Report()
|
||||||
|
class ODD_EVEN_TEST_001(unittest.SystemTestCase):
|
||||||
|
|
||||||
|
@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())
|
||||||
|
|||||||
@@ -29,3 +29,65 @@
|
|||||||
python -m venv <environment-folder-name>
|
python -m venv <environment-folder-name>
|
||||||
source .venv/bin/activate
|
source .venv/bin/activate
|
||||||
python -m pip install --upgrade pip setuptools wheel
|
python -m pip install --upgrade pip setuptools wheel
|
||||||
|
|
||||||
|
-> Referencing the list and copying the list:
|
||||||
|
|
||||||
|
for example:
|
||||||
|
|
||||||
|
amazon_cart = [
|
||||||
|
'notebooks',
|
||||||
|
'sunglasses',
|
||||||
|
'toys',
|
||||||
|
'grapes'
|
||||||
|
]
|
||||||
|
|
||||||
|
amazon_cart[0] = 'laptop'
|
||||||
|
new_cart_2 = amazon_cart[:] # Copying the list
|
||||||
|
# As list slicing creates a new
|
||||||
|
# list
|
||||||
|
|
||||||
|
new_cart_1 = amazon_cart # Referencing the list
|
||||||
|
|
||||||
|
|
||||||
|
print(new_cart_1)
|
||||||
|
print(new_cart_2)
|
||||||
|
print(amazon_cart)
|
||||||
|
|
||||||
|
-> Sorted function and sort method:
|
||||||
|
|
||||||
|
Sorted function creates a new list.
|
||||||
|
|
||||||
|
sort method do the sorting inplace in the list.
|
||||||
|
|
||||||
|
-> List unpacking:
|
||||||
|
|
||||||
|
a,b,c = [1,2,3]
|
||||||
|
|
||||||
|
#a = 1 , b = 2 , c = 3
|
||||||
|
|
||||||
|
a, b, c, *other, d = [1, 2, 3, 4, 5, 6, 7]
|
||||||
|
|
||||||
|
#a = 1, b = 2, c = 3, other = [4,5,6], d = 7
|
||||||
|
|
||||||
|
|
||||||
|
-> Dictionary key:
|
||||||
|
|
||||||
|
Dictionary key need to be immutable i.e. value of key shouldn't be
|
||||||
|
modified in any case.
|
||||||
|
|
||||||
|
The key also has to unique. If the same key which has been defined
|
||||||
|
is used again then the key with the new assigned value will override
|
||||||
|
the old value and access the value memory with that same key will
|
||||||
|
provide the new overrided value instead of previous value.
|
||||||
|
Hence, key of Dictionary should be unique
|
||||||
|
|
||||||
|
-> list and tuple:
|
||||||
|
|
||||||
|
list are mutable but tuple are immutable
|
||||||
|
|
||||||
|
-> using keyword and using methods:
|
||||||
|
|
||||||
|
using keyword to access anything which may not exist
|
||||||
|
might result in error, but to avoid that we can use
|
||||||
|
methods instead of keyword for accessing any value
|
||||||
|
and avoiding error.
|
||||||
|
|||||||
Reference in New Issue
Block a user