Updated gilded rose to utplsql version 3

Also rewrote the texttest
This commit is contained in:
MickeM 2019-07-02 15:40:46 +02:00
parent fb3853835e
commit 431eee7edf
8 changed files with 118 additions and 117 deletions

View File

@ -1,50 +0,0 @@
PROMPT Creating Table 'ITEM' with auto-increment primary key 'ID'
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE item';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;
CREATE TABLE item
(
id NUMBER(6) NOT NULL,
name VARCHAR2(100) NOT NULL,
sell_in NUMBER(6) NOT NULL,
quality NUMBER(6) NOT NULL
);
/
ALTER TABLE item ADD (
CONSTRAINT item_pk PRIMARY KEY (ID));
/
BEGIN
EXECUTE IMMEDIATE 'DROP SEQUENCE item_id_seq';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -2289 THEN
RAISE;
END IF;
END;
CREATE SEQUENCE item_id_seq
INCREMENT BY 1
START WITH 1
MAXVALUE 999999
MINVALUE 1
NOCYCLE;
/
CREATE OR REPLACE TRIGGER item_bis_trg
BEFORE INSERT ON item
FOR EACH ROW
BEGIN
SELECT item_id_seq.NEXTVAL INTO :new.id FROM dual;
END;
/
SHOW ERRORS;

5
plsql/run_tests.sql Normal file
View File

@ -0,0 +1,5 @@
exec DBMS_SESSION.RESET_PACKAGE;
set serveroutput on;
exec DBMS_OUTPUT.ENABLE(1000000);
exec ut.run(USER||':gilded_rose_tests'||'');

78
plsql/texttest.pkb Normal file
View File

@ -0,0 +1,78 @@
CREATE OR REPLACE PACKAGE BODY texttest IS
co_lf CONSTANT VARCHAR2(1) := CHR(10);
PROCEDURE put_line(p_buffer IN OUT NOCOPY VARCHAR2, p_line VARCHAR2) IS
BEGIN
p_buffer := p_buffer || p_line || co_lf;
END put_line;
PROCEDURE setup IS
BEGIN
DELETE FROM ITEM;
new_item('+5 Dexterity Vest', 10, 20);
new_item('Aged Brie', 2, 0);
new_item('Elixir of the Mongoose', 5, 7);
new_item('Sulfuras, Hand of Ragnaros', 0, 80);
new_item('Sulfuras, Hand of Ragnaros', -1, 80);
new_item('Backstage passes to a TAFKAL80ETC concert', 15, 20);
new_item('Backstage passes to a TAFKAL80ETC concert', 10, 49);
new_item('Backstage passes to a TAFKAL80ETC concert', 5, 49);
-- this conjured item does not work properly yet ;
new_item('Conjured Mana Cake', 3, 6);
END setup;
PROCEDURE main_test IS
v_result VARCHAR2(4000) := '';
v_expected VARCHAR2(4000) := '';
l_days NUMBER(3);
CURSOR c_items IS SELECT name, sell_in, quality FROM item;
l_item c_items%ROWTYPE;
BEGIN
put_line(v_expected, 'OMGHAI!');
put_line(v_expected, '-------- day 0 --------');
put_line(v_expected, 'name, sellIn, quality');
put_line(v_expected, '+5 Dexterity Vest, 10, 20' || co_lf || 'Aged Brie, 2, 0');
put_line(v_expected, 'Elixir of the Mongoose, 5, 7');
put_line(v_expected, 'Sulfuras, Hand of Ragnaros, 0, 80');
put_line(v_expected, 'Sulfuras, Hand of Ragnaros, -1, 80');
put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 15, 20');
put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 10, 49');
put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 5, 49');
put_line(v_expected, 'Conjured Mana Cake, 3, 6');
put_line(v_expected, '-------- day 1 --------');
put_line(v_expected, 'name, sellIn, quality');
put_line(v_expected, '+5 Dexterity Vest, 9, 19');
put_line(v_expected, 'Aged Brie, 1, 1');
put_line(v_expected, 'Elixir of the Mongoose, 4, 6');
put_line(v_expected, 'Sulfuras, Hand of Ragnaros, 0, 80');
put_line(v_expected, 'Sulfuras, Hand of Ragnaros, -1, 80');
put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 14, 21');
put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 9, 50');
put_line(v_expected, 'Backstage passes to a TAFKAL80ETC concert, 4, 50');
put_line(v_expected, 'Conjured Mana Cake, 2, 5');
put_line(v_result, 'OMGHAI!');
l_days := 2;
FOR i IN 0 .. l_days - 1
LOOP
put_line(v_result, '-------- day ' || TO_CHAR(i) || ' --------');
put_line(v_result, 'name, sellIn, quality');
FOR l_item IN c_items
LOOP
put_line(v_result, l_item.name || ', ' || l_item.sell_in || ', ' || l_item.quality);
END LOOP;
update_quality();
END LOOP;
ut.expect(v_result).to_equal(v_expected);
END;
END texttest;
/

12
plsql/texttest.pks Normal file
View File

@ -0,0 +1,12 @@
CREATE OR REPLACE PACKAGE texttest IS
-- %suite(texttest)
-- %suitepath(gilded_rose_tests)
-- %rollback(manual)
-- %beforeall
PROCEDURE setup;
-- %test(main test)
PROCEDURE main_test;
END texttest;
/

View File

@ -1,36 +0,0 @@
SET SERVEROUTPUT ON;
DELETE FROM item;
DECLARE
l_days NUMBER(3);
CURSOR c_items IS
SELECT name, sell_in, quality FROM item;
l_item c_items%ROWTYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('OMGHAI!');
new_item('+5 Dexterity Vest', 10, 20);
new_item('Aged Brie', 2, 0);
new_item('Elixir of the Mongoose', 5, 7);
new_item('Sulfuras, Hand of Ragnaros', 0, 80);
new_item('Sulfuras, Hand of Ragnaros', -1, 80);
new_item('Backstage passes to a TAFKAL80ETC concert', 15, 20);
new_item('Backstage passes to a TAFKAL80ETC concert', 10, 49);
new_item('Backstage passes to a TAFKAL80ETC concert', 5, 49);
-- this conjured item does not work properly yet ;
new_item('Conjured Mana Cake', 3, 6);
l_days := 2;
FOR i IN 0 .. l_days - 1
LOOP
DBMS_OUTPUT.PUT_LINE('-------- day ' || TO_CHAR(i) || ' --------');
DBMS_OUTPUT.PUT_LINE('name, sellIn, quality');
FOR l_item IN c_items LOOP
DBMS_OUTPUT.PUT_LINE(l_item.name || ', ' || l_item.sell_in || ', ' || l_item.quality);
END LOOP;
DBMS_OUTPUT.PUT_LINE('');
update_quality();
END LOOP;
END;

View File

@ -1,18 +1,10 @@
CREATE OR REPLACE PACKAGE BODY ut_update_quality
IS
PROCEDURE ut_setup IS
CREATE OR REPLACE PACKAGE BODY ut_update_quality IS
PROCEDURE cleanup_before_each IS
BEGIN
DELETE FROM item;
END;
PROCEDURE ut_teardown IS
BEGIN
NULL;
END;
PROCEDURE ut_foo
IS
PROCEDURE ut_foo IS
l_name item.name%TYPE;
BEGIN
new_item('foo', 0, 0);
@ -20,8 +12,8 @@ IS
update_quality();
SELECT name INTO l_name FROM item;
utAssert.eq('name did change', l_name, 'fixme');
END ut_foo;
ut.expect(l_name, a_message => 'name did change').to_equal('fixme');
END ut_foo;
END ut_update_quality;
/

View File

@ -1,8 +1,13 @@
CREATE OR REPLACE PACKAGE ut_update_quality
IS
PROCEDURE ut_setup;
PROCEDURE ut_teardown;
-- %suite(UT_REGRESSION_TEST)
-- %suitepath(gilded_rose_tests)
-- %rollback(manual)
-- %beforeeach
PROCEDURE cleanup_before_each;
-- %test(Foo test)
PROCEDURE ut_foo;
END ut_update_quality;
/

View File

@ -1,5 +0,0 @@
-- unit test using utPLSQL 2.2.1, see http://utplsql.sourceforge.net/ ;
-- test package must be named like the procedure we want to test ;
EXEC utplsql.test ('update_quality', recompile_in => FALSE);
-- check DBMS_OUTPUT for output ;