forked from emilybache/GildedRose-Refactoring-Kata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request emilybache#4 from codecop/master
Ported GildedRose to Oracle PL/SQL
- Loading branch information
Showing
11 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
require_once 'gilded_rose.php'; | ||
|
||
echo "OMGHAI!\n"; | ||
|
||
$items = array( | ||
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) | ||
); | ||
|
||
$app = new GildedRose($items); | ||
|
||
$days = 2; | ||
if (count($argv) > 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(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
); | ||
/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ; |