??? ?? ??(TDD) ?? ??? ???? Python?? ??? ???? ???????. ?? ?? ??? ???? ?? ? ??? ?? ???? ????? ?????.
TDD ??? ?? ?????? https://osherove.com/tdd-kata-1 ??? ????? ???. ??? ??? ? ?? ??? ??? ?????.
????
???? ??? string_calculator.py? ???/test_string_calculator.py?? ? ?? ??? ????. ??? ???? ???????. ?? add ???? ???? StringCalculator ???? ???? ???.
1??: ? ???? "0"? ???? ???.
unittest ?????? ???? ??????? ?? ? ?? ???? ??? ?????. ???/test_string_calculator.py ??? ?? ?? ??? ?????.
import unittest from string_calculator import StringCalculator class TestStringCalculator(unittest.TestCase): """Test suite for the StringCalculator class.""" def setUp(self): """ Create a new instance of StringCalculator for each test. Can use static method to avoid creating a new instance. """ self.calculator = StringCalculator() def test_empty_string_returns_zero(self): """ Test case: Adding an empty string should return 0. Input: "" Expected Output: 0 """ self.assertEqual(self.calculator.add(""), 0)
?? string_calculator.py ??? StringCalculator ???? ??? ?????.
class StringCalculator: def add(self, numbers:str): if not numbers: return 0
???? ????? ?? ??? ????.
string_calculator.py ? ???/test_string_calculator.py ??? ?? ???? ????? ??? ?????.
????? ?? ????? ???.
?? ??? ???? ???? ?????.
python -m unittest discover tests
? ??? ??? ?? ?? ?? ???? ???? ???? ?????.
?? ??:
???? ???? ??? ?? ??? ?????.
---------------------------------------------------------------------- Ran 1 test in 0.001s OK
?? ?? ???? ???? ??? ??? ???? ? ??? ?? ??? ???? ????? ?????.
2??: ?? ?? ? ?? ??? ???? ?? ??? ????? ???.
?? ???? ??? ?? ?? ? ?? ?? ??? ????? ???? ?????? ?? ?? ??? ??? ???? ???. ? ???? ?? ???? 0? ???? ???.
??? ??
tests/test_string_calculator.py ??? ?? ?? ????? ???? ?? ??? ??? ?????.
def test_add_single_number(self): """ Test case: Adding a single number should return the number itself. Input: "1" Expected Output: 1 """ self.assertEqual(self.calculator.add("1"), 1) def test_add_two_numbers(self): """ Test case: Adding two numbers should return their sum. Input: "1,2" Expected Output: 3 """ self.assertEqual(self.calculator.add("1,2"),3)
?? ??
?? string_calculator.py ??? add ???? ?????? ?? ?? ? ?? ?? ??? ?????.
class StringCalculator: def add(self, numbers:str): if not numbers: return 0 ''' Split the string by commas, convert each value to an integer, and sum them up ''' numbers_list = map(int,numbers.split(',')) return sum(numbers_list)
?? ??? ?? ??? ?? ???? ? ????.
3??: ?? ?? ??
???? ??? ??? ?? ??? ??? ? ??? ???? ?? ??? ??? ???????.
??? ??
tests/test_string_calculator.py ??? ?? ?? ??? ???? ??? ??? ?????.
import unittest from string_calculator import StringCalculator class TestStringCalculator(unittest.TestCase): """Test suite for the StringCalculator class.""" def setUp(self): """ Create a new instance of StringCalculator for each test. Can use static method to avoid creating a new instance. """ self.calculator = StringCalculator() def test_empty_string_returns_zero(self): """ Test case: Adding an empty string should return 0. Input: "" Expected Output: 0 """ self.assertEqual(self.calculator.add(""), 0)
??? ?? ??????? ?? ???? ??? ? ?? ??? ??? ? ????.
4??: ?? ??? ? ? ??
?? ? ?(n)? ?? ?? ?? ??? ??? ?? ??? ????? add ???? ???? ???.
??? ??
tests/test_string_calculator.py ??? ?? ??? ??? ???? ???? ? ?? ?? ??? ???? ????? ?????.
class StringCalculator: def add(self, numbers:str): if not numbers: return 0
?? ??
????, ? ?(n)? ?? ??? ????? string_calculator.py ??? add ???? ???????. n? ??? ?? ?? ???? ??? ????? ???? ??? ? ????.
?? ???? ?? ????? ??? ??? ????.
python -m unittest discover tests
1??? ??? ?? ??? ?? ??? ?? ???? ? ????.
5??: ??? ?? ?? ?? ??
? ????? ??? ?? ?? ??? ????? ??? ?? ??? ????. ?? ??, ???? ??? ?? ??? ??? ?? ?? ??? ??? ? ??? ???. ?:
- ?? ???? //? ???? ? ?? ?? ?? ??? ? ? ????. ?? ?? //;n1;2;3? 6? ???? ???.
- //;n1;2;3? ?? ?? ??? ?????.
??? ??
tests/test_string_calculator.py ??? ?? ??? ?? ?? ?? ??? ???? ??? ??? ?????.
---------------------------------------------------------------------- Ran 1 test in 0.001s OK
?? ??
??? ?? ?? ??? ????? ?? ????? ?? ??? ??? add ???? ???????. // ?? ??? ?? ??? ?? ??? ???? ???.
????? ?? ??? ??? ????.
def test_add_single_number(self): """ Test case: Adding a single number should return the number itself. Input: "1" Expected Output: 1 """ self.assertEqual(self.calculator.add("1"), 1) def test_add_two_numbers(self): """ Test case: Adding two numbers should return their sum. Input: "1,2" Expected Output: 3 """ self.assertEqual(self.calculator.add("1,2"),3)
6??: ?? ??
? ????? ??? ????? add ???? ???? ???. ??? ???? "??? ???? ????"?? ???? ?? ??? ????? ??? ??? ???? ???.
??? ??
tests/test_string_calculator.py ??? ?? ?? ??? ???? ??? ??? ?????.
class StringCalculator: def add(self, numbers:str): if not numbers: return 0 ''' Split the string by commas, convert each value to an integer, and sum them up ''' numbers_list = map(int,numbers.split(',')) return sum(numbers_list)
?? ??
?? add ???? ???? ??? ???? ??? ???? ?? ValueError? ??????.
????? ?? ??? ??? ????.
def test_add_multiple_numbers(self): """ Test case: Adding multiple numbers should return their sum. Input: "1,2,3,4,5" Expected Output: 15 """ self.assertEqual(self.calculator.add("1,2,3,4,5"), 15)
7??: Add ??? ?? ??
? ????? add() ???? ??? ??? ???? GetCalledCount()?? ???? StringCalculator ???? ?????. ?? ??? ???? ??? ? ??? ???? ???? TDD ????? ??????.
??? ??
GetCalledCount() ???? ?? ??? ??? ???? ??? ?????. ? ?????? ???? add()? ??? ??? ???? ????? ???? ???.
tests/test_string_calculator.py ??? ?? ?? ???? ?????.
import unittest from string_calculator import StringCalculator class TestStringCalculator(unittest.TestCase): """Test suite for the StringCalculator class.""" def setUp(self): """ Create a new instance of StringCalculator for each test. Can use static method to avoid creating a new instance. """ self.calculator = StringCalculator() def test_empty_string_returns_zero(self): """ Test case: Adding an empty string should return 0. Input: "" Expected Output: 0 """ self.assertEqual(self.calculator.add(""), 0)
?? ??
?? StringCalculator ???? GetCalledCount() ???? ?????. ? ???? add()? ??? ??? ???? ???.
????? StringCalculator ???? ??? ????.
class StringCalculator: def add(self, numbers:str): if not numbers: return 0
8?? ? 9??: 1000?? ? ??? ???? ?? ??? ??? ?? ?? ?? ??
? ????? ? ?? ?? ??? ?????.
- ???? 1000?? ? ??? ????? ???.
- ??? ?? ?? ??? //[delimiter]n ??? ???? ??? ??? ??? ???? ?? ???? ???.
?? ? ? ?? ?? ??? ?? ???? ??? ?? StringCalculator ???? ??? ?????.
??? ??
1000?? ? ?? ?? ? ?? ??? ??? ?? ?? ?? ??? ?? ?? ???? ?????. ???/test_string_calculator.py ??? ?? ??? ?????.
python -m unittest discover tests
?? ??
?? StringCalculator ???? ??? ??? ?????. ???? ??? ?????.
- 1000?? ? ??? ?????.
- ?? ??? ??? ?? ?? ??? ?????.
????? StringCalculator ???? ??? ????.
---------------------------------------------------------------------- Ran 1 test in 0.001s OK
10??: ?? ?? ?? ??
? ????? ?? ??? ?? ?? ??? ????? add() ???? ?????. ?? ?? //[delimiter1][delimiter2]n ??? ?? ??? ?? ? ?? ??? ??? ? ????.
??? ??
?? ?? ??? ???? ??? ??? ???? ??? ?????. ???/test_string_calculator.py ??? ?? ?? ???? ?????.
def test_add_single_number(self): """ Test case: Adding a single number should return the number itself. Input: "1" Expected Output: 1 """ self.assertEqual(self.calculator.add("1"), 1) def test_add_two_numbers(self): """ Test case: Adding two numbers should return their sum. Input: "1,2" Expected Output: 3 """ self.assertEqual(self.calculator.add("1,2"),3)
?? ??
?? ?? ?? ??? ????? add() ???? ?????. ?? ??? [] ??? ???? //[delimiter1][delimiter2]n ??? ?? ?? ?? ??? ???? ???.
?? ???? ?? ????? StringCalculator ???? ??? ????.
class StringCalculator: def add(self, numbers:str): if not numbers: return 0 ''' Split the string by commas, convert each value to an integer, and sum them up ''' numbers_list = map(int,numbers.split(',')) return sum(numbers_list)
?????
???? ?? ???? ?? ???? ?? ??? ? ??? ?? ?? ?? ?? ??? ???? ?? ?? ????? ?????.
def test_add_multiple_numbers(self): """ Test case: Adding multiple numbers should return their sum. Input: "1,2,3,4,5" Expected Output: 15 """ self.assertEqual(self.calculator.add("1,2,3,4,5"), 15)
?? ??
?? ??? ? ?? ?? ???? ???? ???.
def test_add_numbers_with_newlines(self): """ Test case: Adding numbers separated by newlines should return their sum. Input: "1\n2\n3" Expected Output: 6 """ self.assertEqual(self.calculator.add("1\n2\n3"), 6)
? TDD ???? ??????? ?????! ??? ???? ????.
? ??? ??? ?? ??(TDD)? ???? ??? ??? ??: ??? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

???? Python ?? ?? ?????? ?? ????, "??? ?????, ?? ??"? ???? ??? ??? ??? ?? ??? ?????. 1. ???? ?? ? ??? ?? ?????. ?? ???? ?? ??? ???? ??? ? ? ????. ?? ??, Spoke () ?? ???? ??? ??? ?? ??? ?? ????? ?? ??? ??? ????. 2. ???? ?? ???? ??? ??? ?????? Draw () ???? ???? ????? ?? ???? ?? ??? ???? ??? ???? ?? ?? ?? ??? ????? ?? ?? ????? ?? ?????. 3. Python ?? ???? ???????. ?? ???? ??? ???? ?? ???? ??? ????? ??? ?? ???? ??? ???? ????. ??? ??? ??? ???? ? ??? "?? ??"??????. 4. ???? ? ???? ?? ??? ?????

???? __iter __ () ? __next __ () ???? ???? ?????. ???? ??? ? ??? ????, ?? ???? ?? ??? ??? ???? ?????. 1. ???? ?? () ?? ? ??? ??? ???? ? ?? ??? ?? ? ?? ???? ??? ????. 2. ???? ?? ??? ???? ??? ???? ???? ???? ???? ?? ???? ?????. 3. ???? ???? ?? ??? ?? ? ? ? ??? ?? ? ???????? ? ? ??? ?? ??? ??? ???? ?? ? ? ???? ??????. ?? : ??? ?? ???? ??? ???? ????. ???? ?? ?? ? ??? ?????? ???? ? ?? ?? ? ? ????.

API ??? ??? ??? ?? ??? ???? ???? ???? ????. 1. Apikey? ?? ??? ?? ????, ????? ?? ?? ?? URL ?? ??? ?????. 2. Basicauth? ?? ???? ??? Base64 ??? ??? ??? ??? ????? ?????. 3. OAUTH2? ?? Client_ID ? Client_Secret? ?? ??? ?? ?? ?? ??? BearEtroken? ???????. 4. ?? ??? ???? ?? ?? ?? ???? ????? ???? ?? ?? ? ????. ???, ??? ?? ??? ??? ???? ?? ??? ???? ???? ?? ?????.

Assert? ????? ???? ???? ?? ? ???? ??? ???? ??? ?? ?? ????. ??? ??? ??? ?? ??? ?????, ?? ?? ?? ??, ?? ?? ?? ?? ?? ?? ??? ????? ?? ?? ??? ?? ???? ??? ? ??? ??? ??? ??? ?? ???????. ?? ??? ???? ?? ?? ???? ?? ????? ??? ? ????.

inpython, iteratorsareobjectsthatlowloppingthroughcollections __ () ? __next __ ()

typehintsinpythonsolvetheproblemombiguityandpotentialbugsindynamicallytypedcodebyallowingdevelopscifyexpectiontypes. theyenhancereadability, enablearylybugdetection ? improvetoomingsupport.typehintsareaddedusingaColon (:) forvariblesAndAramete

????? ??? ? ??? ??? ?? ??? ???? ??? zip () ??? ???? ????.? ??? ?? ??? ???? ?? ??? ?? ????. ?? ??? ???? ?? ?? itertools.zip_longest ()? ???? ?? ?? ? ??? ?? ? ????. enumerate ()? ???? ??? ???? ?? ? ????. 1.zip ()? ???? ????? ?? ??? ??? ??? ?????. 2.zip_longest ()? ???? ?? ??? ?? ? ? ???? ?? ? ????. 3. Enumental (Zip ())? ??? ??? ????? ??? ???? ???? ?? ???? ?? ? ????.

Python? ???? ????? ???? API? ???? Fastapi? ?????. ?? ??? ?? ????? ?????? ??? ??? ??? ???? ?? ? ? ????. Fastapi ? Asgi Server Uvicorn? ?? ? ? ????? ??? ??? ? ????. ??? ??, ?? ?? ?? ? ???? ?????? API? ???? ?? ? ? ????. Fastapi? ??? HTTP ??? ???? ?? ?? ? Swaggerui ? Redoc Documentation Systems? ?????. ?? ??? ?? URL ?? ??? ?? ? ??? ??, ?? ?? ??? ???? ???? ?? ?? ??? ??? ? ????. Pydantic ??? ???? ??? ?? ???? ???? ????? ? ??? ? ? ????.
