diff --git a/Matlab/.gitignore b/Matlab/.gitignore new file mode 100644 index 00000000..21229f76 --- /dev/null +++ b/Matlab/.gitignore @@ -0,0 +1 @@ +*.asv \ No newline at end of file diff --git a/Matlab/GildedRose.m b/Matlab/GildedRose.m new file mode 100644 index 00000000..2b607cbf --- /dev/null +++ b/Matlab/GildedRose.m @@ -0,0 +1,64 @@ +classdef GildedRose + + properties + items + end + + methods + function obj = GildedRose(items) + obj.items = items; + end + + function update_quality(obj) + for i = 1:length(obj.items) + item = obj.items(i); + if item.name ~= "Aged Brie" && item.name ~= "Backstage passes to a TAFKAL80ETC concert" + if item.quality > 0 + if item.name ~= "Sulfuras, Hand of Ragnaros" + item.quality = item.quality - 1; + end + end + else + if item.quality < 50 + item.quality = item.quality + 1; + if item.name == "Backstage passes to a TAFKAL80ETC concert" + if item.sell_in < 11 + if item.quality < 50 + item.quality = item.quality + 1; + end + end + if item.sell_in < 6 + if item.quality < 50 + item.quality = item.quality + 1; + end + end + end + end + end + if item.name ~= "Sulfuras, Hand of Ragnaros" + item.sell_in = item.sell_in - 1; + end + if item.sell_in < 0 + if item.name ~= "Aged Brie" + if item.name ~= "Backstage passes to a TAFKAL80ETC concert" + if item.quality > 0 + if item.name ~= "Sulfuras, Hand of Ragnaros" + item.quality = item.quality - 1; + end + end + else + item.quality = item.quality - item.quality; + end + else + if item.quality < 50 + item.quality = item.quality + 1; + end + end + end + end + end + end +end + + + diff --git a/Matlab/Item.m b/Matlab/Item.m new file mode 100644 index 00000000..917c2293 --- /dev/null +++ b/Matlab/Item.m @@ -0,0 +1,23 @@ +classdef Item < handle + % Do not edit or the goblin will one-shot you ! + + properties + name + sell_in + quality + end + + methods + function obj = Item(name, sell_in, quality) + obj.name = name; + obj.sell_in = sell_in; + obj.quality = quality; + end + + function disp(obj) + fprintf("%s, %d, %d\n", obj.name, obj.sell_in, obj.quality) + end + + end +end + diff --git a/Matlab/TestGildedRose.m b/Matlab/TestGildedRose.m new file mode 100644 index 00000000..2037ed91 --- /dev/null +++ b/Matlab/TestGildedRose.m @@ -0,0 +1,12 @@ +classdef TestGildedRose < matlab.unittest.TestCase + + methods(Test) + % Test methods + function test_standard_item(tc) + items = [Item("foo", 4, 5)]; + gilded_rose = GildedRose(items); + gilded_rose.update_quality(); + tc.verifyEqual(items(1).name, "Fixme") + end + end +end \ No newline at end of file diff --git a/Matlab/TextTest.m b/Matlab/TextTest.m new file mode 100644 index 00000000..cab6ea7d --- /dev/null +++ b/Matlab/TextTest.m @@ -0,0 +1,31 @@ +function TextTest(nDays) + +if nargin < 1 + nDays = 2; +end + +items = [ + Item("+5 Dexterity Vest", 10, 20); + Item("Aged Brie", 2, 0); + Item("Elixir of the Mongoose", 5, 7); + Item("Sulfuras, Hand of Ragnaros", 0, 80); + Item("Sulfuras, Hand of Ragnaros", -1, 80); + Item("Backstage passes to a TAFKAL80ETC concert", 15, 20); + Item("Backstage passes to a TAFKAL80ETC concert", 10, 49); + Item("Backstage passes to a TAFKAL80ETC concert", 5, 49); + Item("Conjured Mana Cake", 3, 6)]; + + +for day = 1:nDays + fprintf("-------- day %d --------\n", day) + disp("name, sellIn, quality") + for i = 1:length(items) + disp(items(i)) + end + disp(" ") + GildedRose(items).update_quality() +end + +end + +