pushing unittests

This commit is contained in:
Naren2055 2025-02-16 16:52:54 -08:00
parent ae332e1ed5
commit d849f41886
4 changed files with 173 additions and 0 deletions

View File

@ -0,0 +1,42 @@
from python.components.gilded_rose import Item
import unittest
from python.src.aged_brie import AgedBrieLogic
class TestAgedBrieLogic(unittest.TestCase):
def test_update_quality_before_sell_in(self):
# Test case where sell_in is greater than 0
item = Item(name="Aged Brie",sell_in=5,quality=10)
aged_brie = AgedBrieLogic(item)
quality, sell_in = aged_brie.update_quality()
self.assertEqual(quality, 11) # Quality increases by 1
self.assertEqual(sell_in, 4) # Sell_in decreases by 1
def test_update_quality_after_sell_in(self):
# Test case where sell_in is 0 or negative
item = Item(name="Aged Brie", sell_in= 0, quality=10)
aged_brie = AgedBrieLogic(item)
quality, sell_in = aged_brie.update_quality()
self.assertEqual(quality, 12) # Quality increases by 2 after sell_in is 0
self.assertEqual(sell_in, -1) # Sell_in decreases by 1
def test_update_quality_max_quality(self):
# Test case where quality is already at 50
item = Item(name="Aged Brie", sell_in=5, quality=50)
aged_brie = AgedBrieLogic(item)
quality, sell_in = aged_brie.update_quality()
self.assertEqual(quality, 50) # Quality should not increase above 50
self.assertEqual(sell_in, 4) # Sell_in decreases by 1
def test_update_quality_sell_in_negative(self):
# Test case where sell_in is negative and quality is not at max
item = Item(name="Aged Brie", sell_in=-1, quality=48)
aged_brie = AgedBrieLogic(item)
quality, sell_in = aged_brie.update_quality()
self.assertEqual(quality, 50) # Quality increases by 2 when sell_in is negative
self.assertEqual(sell_in, -2) # Sell_in decreases by 1
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,58 @@
import unittest
from python.components.gilded_rose import Item
from python.src.backstage_passes import BackstagePassesLogic
class TestBackstagePassesLogic(unittest.TestCase):
def test_update_quality_before_10_days(self):
# Test case where sell_in > 10
item = Item(name="Backstage passes", sell_in=15, quality=10)
backstage_pass = BackstagePassesLogic(item)
quality, sell_in = backstage_pass.update_quality()
self.assertEqual(quality, 11) # Quality increases by 1
self.assertEqual(sell_in, 14) # Sell_in decreases by 1
def test_update_quality_before_5_days(self):
# Test case where sell_in < 10 but > 5
item = Item(name="Backstage passes", sell_in=9, quality=10)
backstage_pass = BackstagePassesLogic(item)
quality, sell_in = backstage_pass.update_quality()
self.assertEqual(quality, 12) # Quality increases by 2 (1 before 10 and 1 before 5)
self.assertEqual(sell_in, 8) # Sell_in decreases by 1
def test_update_quality_on_last_day(self):
# Test case where sell_in <= 5
item = Item(name="Backstage passes", sell_in=4, quality=10)
backstage_pass = BackstagePassesLogic(item)
quality, sell_in = backstage_pass.update_quality()
self.assertEqual(quality, 13) # Quality increases by 3 (1 before 10, 1 before 5, 1 before 0)
self.assertEqual(sell_in, 3) # Sell_in decreases by 1
def test_update_quality_after_sell_in(self):
# Test case where sell_in < 0 (should set quality to 0)
item = Item(name="Backstage passes", sell_in=0, quality=10)
backstage_pass = BackstagePassesLogic(item)
quality, sell_in = backstage_pass.update_quality()
self.assertEqual(quality, 0) # Quality should be set to 0 after sell_in < 0
self.assertEqual(sell_in, -1) # Sell_in decreases by 1
def test_update_quality_max_quality(self):
# Test case where quality is already at 50
item = Item(name="Backstage passes", sell_in=15, quality=50)
backstage_pass = BackstagePassesLogic(item)
quality, sell_in = backstage_pass.update_quality()
self.assertEqual(quality, 50) # Quality should not increase above 50
self.assertEqual(sell_in, 14) # Sell_in decreases by 1
def test_update_quality_when_quality_reaches_max(self):
# Test case where quality is at 49 and sell_in is under 10 but above 5
item = Item(name="Backstage passes", sell_in=6, quality=49)
backstage_pass = BackstagePassesLogic(item)
quality, sell_in = backstage_pass.update_quality()
self.assertEqual(quality, 50) # Quality should max out at 50
self.assertEqual(sell_in, 5) # Sell_in decreases by 1
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,42 @@
import unittest
from python.components.gilded_rose import Item
from python.src.conjured import ConjuredItem
class TestConjuredItem(unittest.TestCase):
def test_update_quality_before_sell_in(self):
# Test case where sell_in > 0
item = Item(name="Conjured", sell_in=5, quality=10)
conjured_item = ConjuredItem(item)
quality, sell_in = conjured_item.update_quality()
self.assertEqual(quality, 8) # Quality decreases by 2
self.assertEqual(sell_in, 4) # Sell_in decreases by 1
def test_update_quality_after_sell_in(self):
# Test case where sell_in <= 0
item = Item(name="Conjured", sell_in=0, quality=10)
conjured_item = ConjuredItem(item)
quality, sell_in = conjured_item.update_quality()
self.assertEqual(quality, 6) # Quality decreases by 2 twice (once for regular update and once after sell_in <= 0)
self.assertEqual(sell_in, -1) # Sell_in decreases by 1
def test_update_quality_when_sell_in_is_zero(self):
# Test case where sell_in is exactly 0 (should decrease quality by 4)
item = Item(name="Conjured", sell_in=0, quality=5)
conjured_item = ConjuredItem(item)
quality, sell_in = conjured_item.update_quality()
self.assertEqual(quality, 1) # Quality decreases by 4, can't go below 0
self.assertEqual(sell_in, -1) # Sell_in decreases by 1
def test_update_quality_when_quality_is_0(self):
# Test case where quality is already 0
item = Item(name="Conjured", sell_in=5, quality=0)
conjured_item = ConjuredItem(item)
quality, sell_in = conjured_item.update_quality()
self.assertEqual(quality, 0) # Quality remains 0 as it can't go below 0
self.assertEqual(sell_in, 4) # Sell_in decreases by 1
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,31 @@
import unittest
from python.components.gilded_rose import Item
from python.src.sulfuras import SulfurasLogic
class TestSulfurasLogic(unittest.TestCase):
def setUp(self):
# Setup the initial conditions for the tests.
self.item = Item(name="Sulfuras", sell_in=10, quality=80)
self.sulfuras = SulfurasLogic(self.item)
def test_update_quality_does_not_change_quality(self):
# Ensure that calling update_quality does not change the quality of the item.
initial_quality = self.item.quality
self.sulfuras.update_quality()
self.assertEqual(self.item.quality, initial_quality, "Quality should remain the same.")
def test_update_quality_does_not_change_sell_in(self):
# Ensure that calling update_quality does not change the sell_in of the item.
initial_sell_in = self.item.sell_in
self.sulfuras.update_quality()
self.assertEqual(self.item.sell_in, initial_sell_in, "Sell_in should remain the same.")
def test_initial_values(self):
# Ensure the initial values of the item are set correctly.
self.assertEqual(self.item.quality, 80, "Initial quality should be 80.")
self.assertEqual(self.item.sell_in, 10, "Initial sell_in should be 10.")
if __name__ == '__main__':
unittest.main()