本文整理汇总了Python中gilded_rose.GildedRose类的典型用法代码示例。如果您正苦于以下问题:Python GildedRose类的具体用法?Python GildedRose怎么用?Python GildedRose使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GildedRose类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_foo
def test_foo(self):
items = [Item("foo", 0, 0)]
gilded_rose = GildedRose(items)
gilded_rose.update_quality()
self.assertEquals("foo", items[0].name)
self.assertEqual(0, items[0].quality)
self.assertEqual(-1, items[0].sell_in)
示例2: test_quality_is_never_negative
def test_quality_is_never_negative(self):
items = [ItemFactory("foo", 3, 1)]
gilded_rose = GildedRose(items)
gilded_rose.update_quality()
self.assertTrue(items[0].quality == 0)
gilded_rose.update_quality()
self.assertTrue(items[0].quality == 0)
示例3: test_QualityMax
def test_QualityMax(self):
items = [Item(name="+5 Dexterity Vest", sell_in=10, quality=20),
Item(name="Aged Brie", sell_in=2, quality=0),
Item(name="Elixir of the Mongoose", sell_in=5, quality=7),
Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=15, quality=20),
Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=10, quality=49),
Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=5, quality=49),
Item(name="Conjured Mana Cake", sell_in=3, quality=6),
]
gilded_rose = GildedRose(items)
#We test by running update on the input items until either
# 1) quality has stabilized (success)
# 2) quality of any item exceeds 50 (failure)
# 3) 100 iterations have taken place (failure)
is_stable = False
num_iterations = 0
max_num_iters = 100
qualities_prev = gilded_rose.Qualities()
while not is_stable:
num_iterations += 1
self.assertLessEqual(num_iterations, max_num_iters, \
"Quality not stabilized after " + str(max_num_iters) + " iterations")
gilded_rose.update_quality()
qualities = gilded_rose.Qualities()
is_stable = True
for q, qp in zip(qualities, qualities_prev):
self.assertLessEqual(q, gilded_rose.quality_max, "Quality exceeds max allowed")
if q != qp:
is_stable = False;
qualities_prev = qualities
示例4: Item
def test_increases_the_quality_by_three_of_the_products_that_get_better_as_they_age_when_there_are_5_days_or_less_left(self):
item = Item("Backstage passes to a TAFKAL80ETC concert", 5, 15)
gilded_rose = GildedRose([item])
gilded_rose.update_quality()
self._assert_quality_and_sell_in(item, sell_in=4, quality=18)
示例5: test_quality_zero_for_backstage_passes_and_brie_when_we_have_passed_the_sell_in_date
def test_quality_zero_for_backstage_passes_and_brie_when_we_have_passed_the_sell_in_date(self):
item = Item("Backstage passes to a TAFKAL80ETC concert", 0, 20)
gilded_rose = GildedRose([item])
gilded_rose.update_quality()
self._assert_quality_and_sell_in(item, sell_in=-1, quality=0)
示例6: test_backstage
def test_backstage(self):
items = [
Item("Backstage passes to a TAFKAL80ETC concert", 11, 30),
Item("Backstage passes to a TAFKAL80ETC concert", 10, 30),
Item("Backstage passes to a TAFKAL80ETC concert", 6, 30),
Item("Backstage passes to a TAFKAL80ETC concert", 5, 30),
Item("Backstage passes to a TAFKAL80ETC concert", -1, 30)
]
gilded_rose = GildedRose(items)
gilded_rose.update_quality()
self.assertEqual(31, gilded_rose.items[0].quality)
self.assertEqual(32, gilded_rose.items[1].quality)
self.assertEqual(32, gilded_rose.items[2].quality)
self.assertEqual(33, gilded_rose.items[3].quality)
self.assertEqual(0, gilded_rose.items[4].quality)
self.assertEqual(10, gilded_rose.items[0].sell_in)
self.assertEqual(9, gilded_rose.items[1].sell_in)
self.assertEqual(5, gilded_rose.items[2].sell_in)
self.assertEqual(4, gilded_rose.items[3].sell_in)
self.assertEqual(-2, gilded_rose.items[4].sell_in)
# one more day
gilded_rose.update_quality()
self.assertEqual(33, gilded_rose.items[0].quality)
self.assertEqual(34, gilded_rose.items[1].quality)
self.assertEqual(35, gilded_rose.items[2].quality)
self.assertEqual(36, gilded_rose.items[3].quality)
self.assertEqual(0, gilded_rose.items[4].quality)
self.assertEqual(9, gilded_rose.items[0].sell_in)
self.assertEqual(8, gilded_rose.items[1].sell_in)
self.assertEqual(4, gilded_rose.items[2].sell_in)
self.assertEqual(3, gilded_rose.items[3].sell_in)
self.assertEqual(-3, gilded_rose.items[4].sell_in)
示例7: test_QualityBrie
def test_QualityBrie(self):
items = [Item(name="Aged Brie", sell_in=10, quality=0),
Item(name="Aged Brie", sell_in=10, quality=0),
]
gilded_rose = GildedRose(items)
gilded_rose.update_quality()
qualities = gilded_rose.Qualities()
for q in qualities:
self.assertGreater(q, 0, "Brie quality did not increase")
示例8: test_modified
def test_modified(item, tstexpect):
gr = GildedRose(list([item]))
print(gr.items)
for expected in tstexpect:
gr.update_quality()
ref = gr.items[0]
print(expected, ref.sell_in, ref.quality)
assert expected == [ref.sell_in, ref.quality]
示例9: test_decreses_by_one_the_quality_and_sell_in_for_regular_items
def test_decreses_by_one_the_quality_and_sell_in_for_regular_items(self):
items = [
Item("+5 Dexterity Vest", 10, 20),
Item("Conjured Mana Cake", 3,6)
]
gilded_rose = GildedRose(items)
gilded_rose.update_quality()
self._assert_quality_and_sell_in(items[0], sell_in=9, quality=19)
self._assert_quality_and_sell_in(items[1], sell_in=2, quality=5)
示例10: test_decreases_the_quality_of_the_rpoducts_twice_as_fast_when_we_have_passed_the_sell_in_date
def test_decreases_the_quality_of_the_rpoducts_twice_as_fast_when_we_have_passed_the_sell_in_date(self):
items = [
Item("+5 Dexterity Vest", 0, 20),
Item("Conjured Mana Cake", 0, 6)
]
gilded_rose = GildedRose(items)
gilded_rose.update_quality()
self._assert_quality_and_sell_in(items[0], sell_in=-1, quality=18)
self._assert_quality_and_sell_in(items[1], sell_in=-1, quality=4)
示例11: test_Sulfuras
def test_Sulfuras(self):
items = [Item(name="Sulfuras, Hand of Ragnaros", sell_in=0, quality=80)]
gilded_rose = GildedRose(items)
quality_pre = gilded_rose.Qualities()[0]
sell_in_pre = gilded_rose.SellIns()[0]
gilded_rose.update_quality()
quality_post = gilded_rose.Qualities()[0]
sell_in_post = gilded_rose.SellIns()[0]
self.assertEqual(quality_pre, quality_post, "Sulfuras quality has changed")
self.assertEqual(sell_in_pre, sell_in_post, "Sulfuras sell-in value changed")
示例12: test_increases_quality_by_one_for_products_that_get_better_as_they_age
def test_increases_quality_by_one_for_products_that_get_better_as_they_age(self):
items = [
Item("Aged Brie", 20, 30),
Item("Backstage passes to a TAFKAL80ETC concert", 20, 30)
]
gilded_rose = GildedRose(items)
gilded_rose.update_quality()
self._assert_quality_and_sell_in(items[0], sell_in=19, quality=31)
self._assert_quality_and_sell_in(items[1], sell_in=19, quality=31)
示例13: test_past_date
def test_past_date(self):
items = [
Item("Regular thing", 0, 4),
Item("Other thing", 1, 2),
Item("Widget 33", 1, 5)
]
gilded_rose = GildedRose(items)
gilded_rose.update_quality()
self.assertEqual(2, gilded_rose.items[0].quality)
self.assertEqual(1, gilded_rose.items[1].quality)
self.assertEqual(4, gilded_rose.items[2].quality)
gilded_rose.update_quality()
self.assertEqual(0, gilded_rose.items[0].quality)
self.assertEqual(0, gilded_rose.items[1].quality)
self.assertEqual(2, gilded_rose.items[2].quality)
示例14: test_brie
def test_brie(self):
items = [Item("Aged Brie", 2, 46)]
gilded_rose = GildedRose(items)
gilded_rose.update_quality()
self.assertEqual("Aged Brie", gilded_rose.items[0].name)
self.assertEqual(47, gilded_rose.items[0].quality)
gilded_rose.update_quality()
self.assertEqual(48, gilded_rose.items[0].quality)
gilded_rose.update_quality() #increase by 2 now
self.assertEqual(50, gilded_rose.items[0].quality)
gilded_rose.update_quality()
self.assertEqual(50, gilded_rose.items[0].quality)
示例15: test_QualityConjured
def test_QualityConjured(self):
items = [Item(name="Conjured Mana Cake", sell_in=10, quality=6),
Item(name="Conjured Mana Cake", sell_in=-10, quality=6)]
gilded_rose = GildedRose(items)
qualities_pre = gilded_rose.Qualities()
gilded_rose.update_quality()
qualities_post = gilded_rose.Qualities()
#Sell-In >=0
default_conj_dec = 2 * gilded_rose.default_qual_dec
self.assertEqual(qualities_pre[0] - qualities_post[0], default_conj_dec, \
"Invalid Conjured item default decrement")
#Sell-In < 0
overdue_conj_dec = 4 * gilded_rose.default_qual_dec
self.assertEqual(qualities_pre[1] - qualities_post[1], overdue_conj_dec, \
"Invalid Conjured item overdue decrement")