F. I. Sh. Qoraqulov Sulaymon Guruh: 912-21 Amaliyot
self.assertAlmostEqual(getPerimeter(4), 25.13272)
Download 115.9 Kb.
|
MTA LAB 13
- Bu sahifa navigatsiya:
- Natija: Ran 1 test in 0.001s OK
self.assertAlmostEqual(getPerimeter(4), 25.13272)
unittest.main()) Natija: Ran 2 tests in 0.001s OK Mantiqiy qiymatlarni tekshirish: def tubSonmi(n): if n==2 or n==3: return True if n%2==0 or n<2: return False for i in range(3, int(n**0.5)+1, 2): # faqat toq sonlarni tekshiramiz if n%i==0: return False return True Test: import unittest from tubSonmi import tubSonmi class tubSonTest(unittest.TestCase): def test_true(self): self.assertTrue(tubSonmi(7)) self.assertTrue(tubSonmi(193)) self.assertTrue(tubSonmi(547)) def test_false(self): self.assertFalse(tubSonmi(6)) self.assertFalse(tubSonmi(265)) self.assertFalse(tubSonmi(489)) unittest.main() Natija: Ran 3 tests in 0.001s OK 1.Funksiyani tekshirish: Funksiya: def get_full_name(ism, familiya): return f"{ism} {familiya}".title() Qolda testlash: >>> print(get_full_name('alijon','valiyev')) 'Alijon Valiyev' Avtomatlashtirilgan test: import unittest from name import get_full_name class NameTest(unittest.TestCase): def test_toliq_ism(self): formatted_name = get_full_name('alijon','valiyev') self.assertEqual(formatted_name, 'Alijon Valiyev') unittest.main() Natija: Ran 1 test in 0.001s OK Sonlarni tekshirish: def getArea(r,pi=3.14159): """Doiraning yuzini qaytaruvchi funksiya""" return pi*(r**2) def getPerimeter(r,pi=3.14159): """Doiraning perimetrini qaytaruvchi funksiya""" return 2*pi*r Test: import unittest from circle import getArea, getPerimeter class CircleTest(unittest.TestCase): def test_area(self): self.assertAlmostEqual(getArea(10), 314.159) self.assertAlmostEqual(getArea(3),28.27431) def test_perimeter(self): self.assertAlmostEqual(getPerimeter(10), 62.8318) self.assertAlmostEqual(getPerimeter(4), 25.13272) unittest.main()) Natija: Download 115.9 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2025
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling