csci4130projectdemo / functions.csv
SennPiee's picture
add files
2280f0f
Raw
History Blame Contribute Delete
757 Bytes
function_code,test_code
"def calculate_discount(price, discount_percent):
if discount_percent < 0 or discount_percent > 100:
raise ValueError('Discount must be between 0 and 100')
discount = price * discount_percent / 100
return round(price - discount, 2)","import unittest
from target import calculate_discount
class TestCalculateDiscount(unittest.TestCase):
def test_basic(self):
self.assertEqual(calculate_discount(100, 10), 90.0)
"
"def count_words(text):
if not text or not text.strip():
return 0
return len(text.strip().split())","import unittest
from target import count_words
class TestCountWords(unittest.TestCase):
def test_basic(self):
self.assertEqual(count_words('hello world'), 2)
"