示例#1
0
    def test_can_identify_special_items(self):
        self.assertTrue(
            ItemService.is_special_item(
                Item('Backstage passes to johny concert', 50, 30)))

        self.assertFalse(
            ItemService.is_special_item(Item('passes to john legend', 25, 50)))
 def update_item_quality(item):
     ItemService.reduce_item_sell_in(item)
     if item.sell_in in range(6, 11):
         BackstageService.increase_item_quality(item, 2)
         return item.quality
     elif item.sell_in in range(0, 6):
         BackstageService.increase_item_quality(item, 3)
         return item.quality
     elif item.sell_in < 0:
         BackstageService.set_item_quality(item, 0)
         return item.quality
     else:
         BackstageService.increase_item_quality(item, 1)
         return item.quality
示例#3
0
 def update_items(items, current_time):
     if GildedRose.is_end_of_the_day(current_time):
         for item in items:
             if ItemService.is_item_conjured(item):
                 ConjuredService.update_quality(item)
             elif ItemService.is_item_back_stage(item):
                 BackstageService.update_item_quality(item)
             elif ItemService.is_item_sulfuras(item):
                 SulfuraService.update_item(item)
             elif ItemService.is_aged_brie(item):
                 AgedBrieService.update_item(item)
             elif not ItemService.is_special_item(item):
                 StandardItemService.update_item_quality(item)
         return items
示例#4
0
    def test_attribute_is_defined(self):
        self.assertTrue(
            ItemService.item_has_given_attributte(Item('concert', 12, 30),
                                                  'name'))

        self.assertRaises(AttributeError,
                          ItemService.item_has_given_attributte,
                          Item('concert', 12, 30), 'price')
示例#5
0
    def test_can_reduce_item_sell_in(self):
        item = Item("Sulfuras", 20, 80)
        item2 = Item("AgedBrie", "20", 50)

        expected_value = item.sell_in - 1

        self.assertTrue(
            ItemService.reduce_item_sell_in(item) == expected_value)

        self.assertRaises(TypeError, ItemService.reduce_item_sell_in, item2)
示例#6
0
    def test_identify_aged_brie_type(self):
        item = Item('Aged Brie', 25, 50)

        item2 = Item("sulfuras", 35, 50)

        item3 = Item("conjured", 35, 50)

        item4 = Item("Backstage passes to johny concert", 35, 50)

        item5 = Item('passes to john legend', 25, 50)

        self.assertTrue(ItemService.is_aged_brie, item)

        self.assertTrue(ItemService.is_item_sulfuras, item2)

        self.assertFalse(ItemService.is_aged_brie(item2))

        self.assertTrue(ItemService.is_item_conjured, item3)

        self.assertTrue(ItemService.is_item_back_stage(item4))

        self.assertFalse(ItemService.is_item_back_stage(item5))
    def test_can_update_items(self):
        current_time = "00:00:00"
        items = [
            Item("Sulfuras", 20, 40),
            Item("Conjured", 25, 60),
            Item("Backstage passes to johny", 2, 46)
        ]

        expected_first_item = Item("Sulfuras", 19, 80)
        expected_second_item = Item("Conjured", 24, 50)
        tirth_expeted_item = Item("Backstage passes to johny", 1, 49)

        new_items_list = GildedRose.update_items(items, current_time)

        self.assertTrue(
            ItemService.are_item_equal(new_items_list[0], expected_first_item))

        self.assertTrue(
            ItemService.are_item_equal(new_items_list[1],
                                       expected_second_item))

        self.assertTrue(
            ItemService.are_item_equal(new_items_list[2], tirth_expeted_item))
 def update_item(item):
     ItemService.reduce_item_sell_in(item)
     AgedBrieService.increase_item_quality(item, 1)
     return item.quality, item.sell_in
 def set_item_quality(item, q_value):
     if ItemService.is_item_back_stage(item):
         return ItemService.set_quality_in_range(item, q_value)
示例#10
0
 def set_item_quality(item):
     if ItemService.is_item_sulfuras(item):
         item.quality = 80
         return item.quality
示例#11
0
 def update_item(item):
     SulfuraService.set_item_quality(item)
     ItemService.reduce_item_sell_in(item)
     return item.quality, item.sell_in
 def set_item_quality(item, q_value):
     if ItemService.is_item_conjured(item):
         return ItemService.set_quality_in_range(item, q_value)
 def update_item_quality(item):
     ItemService.reduce_item_sell_in(item)
     StandardItemService.reduce_item_quality_by(item, 1)
     return item.quality, item.sell_in
 def reduce_item_quality_by(item, value):
     if not ItemService.is_special_item(item):
         StandardItemService.set_item_quality(item, item.quality - value)
         return item.quality
示例#15
0
    def test_can_compare_two_items(self):
        item = Item('Aged Brie', 25, 50)

        item2 = Item('Aged Brie', 25, 50)

        self.assertTrue(ItemService.are_item_equal(item, item2))
 def set_item_quality(item, q_value):
     if ItemService.is_aged_brie(item):
         return ItemService.set_quality_in_range(item, q_value)
 def set_item_quality(item, q_value):
     if not ItemService.is_special_item(item):
         ItemService.set_quality_in_range(item, q_value)
 def update_quality(item):
     ItemService.reduce_item_sell_in(item)
     ConjuredService.reduce_item_quality(item, 2)
     return item.quality