Merge pull request #471 from Intrunatu/matlab

Gilded Rose in Matlab
This commit is contained in:
Emily Bache 2023-09-22 07:58:27 +02:00 committed by GitHub
commit 50e4577099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 131 additions and 0 deletions

1
Matlab/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.asv

64
Matlab/GildedRose.m Normal file
View File

@ -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

23
Matlab/Item.m Normal file
View File

@ -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

12
Matlab/TestGildedRose.m Normal file
View File

@ -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

31
Matlab/TextTest.m Normal file
View File

@ -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