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; } } 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(); +} 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/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 new file mode 100644 index 0000000000..59a8f39cd8 --- /dev/null +++ b/plsql/texttest_fixture.sql @@ -0,0 +1,34 @@ +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; 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; +/ 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 ;