PYPROGLIB Telegram 6541
👍 Промпт для генерации юнит-тестов

Используйте следующий промпт для генерации юнит-тестов с помощью pytest:

💬 Промпт:
Please generate comprehensive unit tests for the following Python function using pytest.

Requirements:
1. Carefully analyze the function’s functionality, inputs, and outputs.
2. Generate unit tests that cover standard use cases and edge cases.
3. Ensure that the tests are clear, easy to understand, and well-organized.
4. Challenge potential inaccuracies with false outcomes, testing against possible mistakes.
5. Use assertions that test both expected outcomes and exception handling.

[insert function code here]


Что вы получите?
▪️ Полный набор юнит-тестов, охватывающих все аспекты функции.
▪️ Применение лучших практик тестирования.
▪️ Обеспечение надежности кода и упрощение отладки.

✔️ Пример:

Предположим, у нас есть функция, которая вычисляет факториал числа:
def factorial(n: int) -> int:
if n == 0 or n == 1:
return 1
return n * factorial(n-1)


Промпт позволит получить набор юнит-тестов для этой функции:
import pytest
from your_module import factorial

def test_factorial_base_case():
"""Проверка, что факториал 0 и 1 возвращает 1."""
assert factorial(0) == 1
assert factorial(1) == 1

def test_factorial_positive_integers():
"""Проверка факториала для положительных целых чисел."""
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120

def test_factorial_large_number():
"""Проверка факториала для большего числа."""
assert factorial(10) == 3628800

def test_factorial_negative():
"""Проверка, что функция выбрасывает исключение для отрицательных чисел."""
with pytest.raises(ValueError):
factorial(-1)

def test_factorial_edge_case():
"""Проверка факториала для граничного случая."""
assert factorial(6) == 720


Библиотека питониста #буст
Please open Telegram to view this post
VIEW IN TELEGRAM
👍13🥱94🔥4😢3



tgoop.com/pyproglib/6541
Create:
Last Update:

👍 Промпт для генерации юнит-тестов

Используйте следующий промпт для генерации юнит-тестов с помощью pytest:

💬 Промпт:

Please generate comprehensive unit tests for the following Python function using pytest.

Requirements:
1. Carefully analyze the function’s functionality, inputs, and outputs.
2. Generate unit tests that cover standard use cases and edge cases.
3. Ensure that the tests are clear, easy to understand, and well-organized.
4. Challenge potential inaccuracies with false outcomes, testing against possible mistakes.
5. Use assertions that test both expected outcomes and exception handling.

[insert function code here]


Что вы получите?
▪️ Полный набор юнит-тестов, охватывающих все аспекты функции.
▪️ Применение лучших практик тестирования.
▪️ Обеспечение надежности кода и упрощение отладки.

✔️ Пример:

Предположим, у нас есть функция, которая вычисляет факториал числа:
def factorial(n: int) -> int:
if n == 0 or n == 1:
return 1
return n * factorial(n-1)


Промпт позволит получить набор юнит-тестов для этой функции:
import pytest
from your_module import factorial

def test_factorial_base_case():
"""Проверка, что факториал 0 и 1 возвращает 1."""
assert factorial(0) == 1
assert factorial(1) == 1

def test_factorial_positive_integers():
"""Проверка факториала для положительных целых чисел."""
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120

def test_factorial_large_number():
"""Проверка факториала для большего числа."""
assert factorial(10) == 3628800

def test_factorial_negative():
"""Проверка, что функция выбрасывает исключение для отрицательных чисел."""
with pytest.raises(ValueError):
factorial(-1)

def test_factorial_edge_case():
"""Проверка факториала для граничного случая."""
assert factorial(6) == 720


Библиотека питониста #буст

BY Библиотека питониста | Python, Django, Flask


Share with your friend now:
tgoop.com/pyproglib/6541

View MORE
Open in Telegram


Telegram News

Date: |

To delete a channel with over 1,000 subscribers, you need to contact user support As of Thursday, the SUCK Channel had 34,146 subscribers, with only one message dated August 28, 2020. It was an announcement stating that police had removed all posts on the channel because its content “contravenes the laws of Hong Kong.” Add up to 50 administrators Informative With the sharp downturn in the crypto market, yelling has become a coping mechanism for many crypto traders. This screaming therapy became popular after the surge of Goblintown Ethereum NFTs at the end of May or early June. Here, holders made incoherent groaning sounds in late-night Twitter spaces. They also role-played as urine-loving Goblin creatures.
from us


Telegram Библиотека питониста | Python, Django, Flask
FROM American