Last active
July 15, 2019 09:48
gilded_rose_plsql_test_update_quality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE PACKAGE test_update_quality | |
IS | |
--%suite(Update quality) | |
--%beforeeach | |
PROCEDURE setup; | |
--%test(sell in decreases every day) | |
PROCEDURE sell_in_decreases_every_day; | |
--%test(quality decreases every day) | |
PROCEDURE quality_decreases_every_day; | |
--%test(quality decreases twice as fast one sell in has passed) | |
PROCEDURE quality_decreases_twice; | |
--%test(quality is never negative) | |
PROCEDURE quality_is_never_negative; | |
--%test(aged brie increases quality) | |
PROCEDURE aged_brie_increases_quality; | |
--%test(item never increase quality when has reached the maximum) | |
PROCEDURE quality_has_a_maximun; | |
--%test(sulfuras never changes the quality) | |
PROCEDURE sulfuras_never_changes_quality; | |
--%test(sulfuras never changes the sell in) | |
PROCEDURE sulfuras_never_changes_sell_in; | |
--%test(backstage increase quality) | |
PROCEDURE backstage_increase_quality; | |
--%test(backstage increase quality by 2 when sell in is 10 or less) | |
PROCEDURE bkstg_q_by_2_sellin_is_10_less; | |
--%test(backstage increase quality by 3 when sell in is 5 or less) | |
PROCEDURE bkstg_q_by_3_sellin_is_5_less; | |
--%test(backstage drops to 0 quality after the concert) | |
PROCEDURE bkstg_q_drops_0_after_concert; | |
--%test(aged brie expired gets the maximum quality when has the quality minus 1) | |
PROCEDURE aged_brie_expired_the_max_q; | |
END test_update_quality; | |
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE PACKAGE BODY test_update_quality | |
IS | |
expired_sellin CONSTANT int := 0; | |
minimun_quality CONSTANT int := 0; | |
maximum_quality CONSTANT int := 50; | |
PROCEDURE expectQualityToBe(qualityExpected IN int) IS | |
quality item.quality%TYPE; | |
BEGIN | |
SELECT QUALITY INTO quality FROM item; | |
ut.expect(quality).to_equal(qualityExpected); | |
END; | |
PROCEDURE expectSellinToBe(sellinExpected IN int) IS | |
sell_in item.SELL_IN%TYPE; | |
BEGIN | |
SELECT SELL_IN INTO sell_in FROM item; | |
ut.expect(sell_in).to_equal(sellinExpected); | |
END; | |
PROCEDURE add_regular_product_with(sell_in item.sell_in%TYPE, | |
quality item.quality%TYPE) | |
IS | |
BEGIN | |
new_item('any_product', sell_in, quality); | |
END; | |
PROCEDURE add_aged_brie_with(sell_in item.sell_in%TYPE, | |
quality item.quality%TYPE) | |
IS | |
BEGIN | |
new_item('Aged Brie', sell_in, quality); | |
END; | |
PROCEDURE add_sulfuras_with(sell_in item.sell_in%TYPE, | |
quality item.quality%TYPE) | |
IS | |
BEGIN | |
new_item('Sulfuras, Hand of Ragnaros', sell_in, quality); | |
END; | |
PROCEDURE add_backstage_with(sell_in item.sell_in%TYPE, | |
quality item.quality%TYPE) | |
IS | |
BEGIN | |
new_item('Backstage passes to a TAFKAL80ETC concert', sell_in, quality); | |
END; | |
------------ TESTS ---------- | |
PROCEDURE setup IS | |
BEGIN | |
DELETE FROM item; | |
END; | |
PROCEDURE sell_in_decreases_every_day | |
IS | |
BEGIN | |
add_regular_product_with(sell_in => 5, quality => 15); | |
update_quality(); | |
expectSellinToBe(4); | |
END; | |
PROCEDURE quality_decreases_every_day | |
IS | |
BEGIN | |
add_regular_product_with(sell_in => 5, quality => 15); | |
update_quality(); | |
expectQualityToBe(14); | |
END; | |
PROCEDURE quality_decreases_twice | |
IS | |
BEGIN | |
add_regular_product_with(sell_in => expired_sellin, quality => 15); | |
update_quality(); | |
expectQualityToBe(13); | |
END; | |
PROCEDURE quality_is_never_negative | |
IS | |
BEGIN | |
add_regular_product_with(sell_in => expired_sellin, quality => minimun_quality); | |
update_quality(); | |
expectQualityToBe(minimun_quality); | |
END; | |
PROCEDURE aged_brie_increases_quality | |
IS | |
BEGIN | |
add_aged_brie_with(sell_in => 5, quality => 15); | |
update_quality(); | |
expectQualityToBe(16); | |
END; | |
PROCEDURE quality_has_a_maximun | |
IS | |
BEGIN | |
add_aged_brie_with(sell_in => 5, quality => maximum_quality); | |
update_quality(); | |
expectQualityToBe(50); | |
END; | |
PROCEDURE sulfuras_never_changes_quality | |
IS | |
BEGIN | |
add_sulfuras_with(sell_in => 4, quality => 30); | |
update_quality(); | |
expectQualityToBe(30); | |
END; | |
PROCEDURE sulfuras_never_changes_sell_in | |
IS | |
BEGIN | |
add_sulfuras_with(sell_in => 4, quality => 30); | |
update_quality(); | |
expectSellinToBe(4); | |
END; | |
PROCEDURE backstage_increase_quality | |
IS | |
BEGIN | |
add_backstage_with(sell_in => 15, quality => 30); | |
update_quality(); | |
expectQualityToBe(31); | |
END; | |
PROCEDURE bkstg_q_by_2_sellin_is_10_less | |
IS | |
BEGIN | |
add_backstage_with(sell_in => 10, quality => 30); | |
update_quality(); | |
expectQualityToBe(32); | |
END; | |
PROCEDURE bkstg_q_by_3_sellin_is_5_less | |
IS | |
BEGIN | |
add_backstage_with(sell_in => 5, quality => 30); | |
update_quality(); | |
expectQualityToBe(33); | |
END; | |
PROCEDURE bkstg_q_drops_0_after_concert | |
IS | |
BEGIN | |
add_backstage_with(sell_in => expired_sellin, quality => 30); | |
update_quality(); | |
expectQualityToBe(0); | |
END; | |
PROCEDURE aged_brie_expired_the_max_q | |
IS | |
BEGIN | |
add_aged_brie_with(sell_in => expired_sellin, quality => maximum_quality - 1); | |
update_quality(); | |
expectQualityToBe(maximum_quality); | |
END; | |
END test_update_quality; | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment