From 16b7b4665361fe9405282dc329586722b3486aad Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 13 Apr 2014 13:40:22 +0200 Subject: [PATCH 1/5] add missing @Override annotation to item's toString --- Java/com/gildedrose/Item.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Java/com/gildedrose/Item.java b/Java/com/gildedrose/Item.java index 33ab7398ea..65b02c6b89 100644 --- a/Java/com/gildedrose/Item.java +++ b/Java/com/gildedrose/Item.java @@ -14,7 +14,8 @@ public Item(String name, int sellIn, int quality) { this.quality = quality; } - public String toString() { + @Override + public String toString() { return this.name + ", " + this.sellIn + ", " + this.quality; } } From 1ad3fcd95ef94db1553ce1244b86d0e414105214 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 13 Apr 2014 13:45:49 +0200 Subject: [PATCH 2/5] port GildedRose to Oracle PL/SQL table and stored procedure --- plsql/create_user_if_needed.sql | 7 ++++ plsql/item.sql | 9 +++++ plsql/item_with_id.sql | 31 ++++++++++++++++ plsql/texttest_fixture.sql | 35 +++++++++++++++++ plsql/update_quality.sql | 66 +++++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 plsql/create_user_if_needed.sql create mode 100644 plsql/item.sql create mode 100644 plsql/item_with_id.sql create mode 100644 plsql/texttest_fixture.sql create mode 100644 plsql/update_quality.sql diff --git a/plsql/create_user_if_needed.sql b/plsql/create_user_if_needed.sql new file mode 100644 index 0000000000..59078daecd --- /dev/null +++ b/plsql/create_user_if_needed.sql @@ -0,0 +1,7 @@ +PROMPT Creating User 'DOJO' +DROP USER dojo; +CREATE USER dojo IDENTIFIED BY pass + DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE temp; + GRANT RESOURCE TO dojo; + GRANT CONNECT TO dojo; +/ diff --git a/plsql/item.sql b/plsql/item.sql new file mode 100644 index 0000000000..199acd73ff --- /dev/null +++ b/plsql/item.sql @@ -0,0 +1,9 @@ +PROMPT Creating Table 'ITEM' +DROP TABLE item; +CREATE TABLE item + ( + name VARCHAR2(100) NOT NULL, + sell_in NUMBER(6) NOT NULL, + quality NUMBER(6) NOT NULL + ); +/ diff --git a/plsql/item_with_id.sql b/plsql/item_with_id.sql new file mode 100644 index 0000000000..7d78aedfad --- /dev/null +++ b/plsql/item_with_id.sql @@ -0,0 +1,31 @@ +PROMPT Creating Table 'ITEM' with auto-increment primary key 'ID' +DROP TABLE item; +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)); +/ + +DROP SEQUENCE item_id_seq; +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; +/ diff --git a/plsql/texttest_fixture.sql b/plsql/texttest_fixture.sql new file mode 100644 index 0000000000..ce56ff2513 --- /dev/null +++ b/plsql/texttest_fixture.sql @@ -0,0 +1,35 @@ +DELETE FROM item; + +INSERT INTO item (name, sell_in, quality) VALUES ('+5 Dexterity Vest', 10, 20); +INSERT INTO item (name, sell_in, quality) VALUES ('Aged Brie', 2, 0); +INSERT INTO item (name, sell_in, quality) VALUES ('Elixir of the Mongoose', 5, 7); +INSERT INTO item (name, sell_in, quality) VALUES ('Sulfuras, Hand of Ragnaros', 0, 80); +INSERT INTO item (name, sell_in, quality) VALUES ('Sulfuras, Hand of Ragnaros', -1, 80); +INSERT INTO item (name, sell_in, quality) VALUES ('Backstage passes to a TAFKAL80ETC concert', 15, 20); +INSERT INTO item (name, sell_in, quality) VALUES ('Backstage passes to a TAFKAL80ETC concert', 10, 49); +INSERT INTO item (name, sell_in, quality) VALUES ('Backstage passes to a TAFKAL80ETC concert', 5, 49); +-- this conjured item does not work properly yet ; +INSERT INTO item (name, sell_in, quality) VALUES ('Conjured Mana Cake', 3, 6); +COMMIT; + +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!'); + + 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; diff --git a/plsql/update_quality.sql b/plsql/update_quality.sql new file mode 100644 index 0000000000..c1f2febe1a --- /dev/null +++ b/plsql/update_quality.sql @@ -0,0 +1,66 @@ +CREATE OR REPLACE PROCEDURE update_quality +IS + CURSOR c_items IS + SELECT name, sell_in, quality FROM item FOR UPDATE; + l_item c_items%ROWTYPE; + l_name item.name%TYPE; + l_sell_in item.sell_in%TYPE; + l_quality item.quality%TYPE; +BEGIN + FOR l_item IN c_items + LOOP + l_name := l_item.name; + l_sell_in := l_item.sell_in; + l_quality := l_item.quality; + + IF l_name != 'Aged Brie' AND l_name != 'Backstage passes to a TAFKAL80ETC concert' THEN + IF l_quality > 0 THEN + IF l_name != 'Sulfuras, Hand of Ragnaros' THEN + l_quality := l_quality - 1; + END IF; + END IF; + ELSE + IF (l_quality < 50) THEN + l_quality := l_quality + 1; + IF l_name = 'Backstage passes to a TAFKAL80ETC concert' THEN + IF l_sell_in < 11 THEN + IF l_quality < 50 THEN + l_quality := l_quality + 1; + END IF; + END IF; + IF l_sell_in < 6 THEN + IF l_quality < 50 THEN + l_quality := l_quality + 1; + END IF; + END IF; + END IF; + END IF; + END IF; + + IF l_name != 'Sulfuras, Hand of Ragnaros' THEN + l_sell_in := l_sell_in - 1; + END IF; + + IF l_sell_in < 0 THEN + IF l_name != 'Aged Brie' THEN + IF l_name != 'Backstage passes to a TAFKAL80ETC concert' THEN + IF l_quality > 0 THEN + IF l_name != 'Sulfuras, Hand of Ragnaros' THEN + l_quality := l_quality - 1; + END IF; + END IF; + ELSE + l_quality := l_quality - l_quality; + END IF; + ELSE + IF l_quality < 50 THEN + l_quality := l_quality + 1; + END IF; + END IF; + END IF; + + UPDATE item + SET name = l_name, sell_in = l_sell_in, quality = l_quality WHERE CURRENT OF c_items; + END LOOP; +END update_quality; +/ From 66495cb8721e11a41d57db9cd269b32c4e3f0a86 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 13 Apr 2014 15:21:47 +0200 Subject: [PATCH 3/5] create helper procedure to insert an item --- plsql/new_item.sql | 9 +++++++++ plsql/texttest_fixture.sql | 23 +++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 plsql/new_item.sql diff --git a/plsql/new_item.sql b/plsql/new_item.sql new file mode 100644 index 0000000000..63c46fe782 --- /dev/null +++ b/plsql/new_item.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE PROCEDURE new_item( + i_name item.name%TYPE, + i_sell_in item.sell_in%TYPE, + i_quality item.quality%TYPE) +IS +BEGIN + INSERT INTO item (name, sell_in, quality) VALUES (i_name, i_sell_in, i_quality); +END new_item; +/ diff --git a/plsql/texttest_fixture.sql b/plsql/texttest_fixture.sql index ce56ff2513..59a8f39cd8 100644 --- a/plsql/texttest_fixture.sql +++ b/plsql/texttest_fixture.sql @@ -1,17 +1,5 @@ DELETE FROM item; -INSERT INTO item (name, sell_in, quality) VALUES ('+5 Dexterity Vest', 10, 20); -INSERT INTO item (name, sell_in, quality) VALUES ('Aged Brie', 2, 0); -INSERT INTO item (name, sell_in, quality) VALUES ('Elixir of the Mongoose', 5, 7); -INSERT INTO item (name, sell_in, quality) VALUES ('Sulfuras, Hand of Ragnaros', 0, 80); -INSERT INTO item (name, sell_in, quality) VALUES ('Sulfuras, Hand of Ragnaros', -1, 80); -INSERT INTO item (name, sell_in, quality) VALUES ('Backstage passes to a TAFKAL80ETC concert', 15, 20); -INSERT INTO item (name, sell_in, quality) VALUES ('Backstage passes to a TAFKAL80ETC concert', 10, 49); -INSERT INTO item (name, sell_in, quality) VALUES ('Backstage passes to a TAFKAL80ETC concert', 5, 49); --- this conjured item does not work properly yet ; -INSERT INTO item (name, sell_in, quality) VALUES ('Conjured Mana Cake', 3, 6); -COMMIT; - DECLARE l_days NUMBER(3); CURSOR c_items IS @@ -20,6 +8,17 @@ DECLARE 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 From 15576d77156ccdff000cf7b88e34f6e9ec9bb108 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 13 Apr 2014 15:28:36 +0200 Subject: [PATCH 4/5] add empty unit test case for utPLSQL --- plsql/ut_update_quality.pkb | 27 +++++++++++++++++++++++++++ plsql/ut_update_quality.pks | 8 ++++++++ plsql/ut_update_quality.sql | 5 +++++ 3 files changed, 40 insertions(+) create mode 100644 plsql/ut_update_quality.pkb create mode 100644 plsql/ut_update_quality.pks create mode 100644 plsql/ut_update_quality.sql diff --git a/plsql/ut_update_quality.pkb b/plsql/ut_update_quality.pkb new file mode 100644 index 0000000000..9952051882 --- /dev/null +++ b/plsql/ut_update_quality.pkb @@ -0,0 +1,27 @@ +CREATE OR REPLACE PACKAGE BODY ut_update_quality +IS + + PROCEDURE ut_setup IS + BEGIN + DELETE FROM item; + END; + + PROCEDURE ut_teardown IS + BEGIN + NULL; + END; + + PROCEDURE ut_foo + IS + l_name item.name%TYPE; + BEGIN + new_item('foo', 0, 0); + + update_quality(); + + SELECT name INTO l_name FROM item; + utAssert.eq('name did change', l_name, 'fixme'); + END ut_foo; + +END ut_update_quality; +/ diff --git a/plsql/ut_update_quality.pks b/plsql/ut_update_quality.pks new file mode 100644 index 0000000000..db0a8f1ec1 --- /dev/null +++ b/plsql/ut_update_quality.pks @@ -0,0 +1,8 @@ +CREATE OR REPLACE PACKAGE ut_update_quality +IS + PROCEDURE ut_setup; + PROCEDURE ut_teardown; + + PROCEDURE ut_foo; +END ut_update_quality; +/ diff --git a/plsql/ut_update_quality.sql b/plsql/ut_update_quality.sql new file mode 100644 index 0000000000..2d5cd6a7a9 --- /dev/null +++ b/plsql/ut_update_quality.sql @@ -0,0 +1,5 @@ +-- 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 ; From a5a06c797976a5265b9d96f96fbbf35cc90355c1 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Sun, 13 Apr 2014 15:57:10 +0200 Subject: [PATCH 5/5] add missing texttest fixture for PHP code --- php/src/texttest_fixture.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 php/src/texttest_fixture.php diff --git a/php/src/texttest_fixture.php b/php/src/texttest_fixture.php new file mode 100644 index 0000000000..36688b7daf --- /dev/null +++ b/php/src/texttest_fixture.php @@ -0,0 +1,35 @@ + 1) { + $days = (int) $argv[1]; +} + +for ($i = 0; $i < $days; $i++) { + echo("-------- day $i --------\n"); + echo("name, sellIn, quality\n"); + foreach ($items as $item) { + echo $item . PHP_EOL; + } + echo PHP_EOL; + $app->update_quality(); +}