mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-10-15 18:43:53 +00:00
new version of erlang
This commit is contained in:
1 parent
045597940b
commit
3db5265f46
14 files changed
+177
-143
No files matched your search
@@ -0,0 +1,14 @@
|
||||
{application, 'GildedRose',
|
||||
[{description, "An OTP library"},
|
||||
{vsn, "0.1.0"},
|
||||
{registered, []},
|
||||
{applications,
|
||||
[kernel,
|
||||
stdlib
|
||||
]},
|
||||
{env,[]},
|
||||
{modules, []},
|
||||
|
||||
{licenses, ["Apache 2.0"]},
|
||||
{links, []}
|
||||
]}.
|
||||
@@ -0,0 +1,87 @@
|
||||
-module('GildedRose').
|
||||
|
||||
-include("GildedRose.hrl").
|
||||
|
||||
-export([
|
||||
update_quality/1
|
||||
]).
|
||||
|
||||
-spec update_quality([#item{}]) -> [#item{}].
|
||||
update_quality(Items) ->
|
||||
lists:map(fun update_item/1, Items).
|
||||
|
||||
-spec update_item(#item{}) -> #item{}.
|
||||
update_item(Item = #item{name = Name}) ->
|
||||
Item1 = if
|
||||
Name /= "Aged Brie" andalso Name /= "Backstage passes to a TAFKAL80ETC concert" ->
|
||||
if
|
||||
Item#item.quality > 0 ->
|
||||
if
|
||||
Name /= "Sulfuras, Hand of Ragnaros" ->
|
||||
Item#item{quality = Item#item.quality - 1};
|
||||
true ->
|
||||
Item
|
||||
end;
|
||||
true ->
|
||||
Item
|
||||
end;
|
||||
true ->
|
||||
if
|
||||
Item#item.quality < 50 ->
|
||||
Item2 = Item#item{quality = Item#item.quality + 1},
|
||||
if
|
||||
Name == "Backstage passes to a TAFKAL80ETC concert" ->
|
||||
Item3 = if
|
||||
Item2#item.sell_in < 11 ->
|
||||
if
|
||||
Item2#item.quality < 50 ->
|
||||
Item2#item{quality = Item2#item.quality + 1};
|
||||
true -> Item2
|
||||
end;
|
||||
true -> Item2
|
||||
end,
|
||||
if
|
||||
Item3#item.sell_in < 6 ->
|
||||
if
|
||||
Item3#item.quality < 50 ->
|
||||
Item3#item{quality = Item3#item.quality + 1};
|
||||
true -> Item3
|
||||
end;
|
||||
true -> Item3
|
||||
end;
|
||||
true -> Item2
|
||||
end;
|
||||
true -> Item
|
||||
end
|
||||
end,
|
||||
Item4 = if
|
||||
Name /= "Sulfuras, Hand of Ragnaros" ->
|
||||
Item1#item{sell_in = Item1#item.sell_in - 1};
|
||||
true -> Item1
|
||||
end,
|
||||
if
|
||||
Item4#item.sell_in < 0 ->
|
||||
if
|
||||
Name /= "Aged Brie" ->
|
||||
if
|
||||
Name /= "Backstage passes to a TAFKAL80ETC concert" ->
|
||||
if
|
||||
Item4#item.quality > 0 ->
|
||||
if
|
||||
Name /= "Sulfuras, Hand of Ragnaros" ->
|
||||
Item4#item{quality = Item4#item.quality - 1};
|
||||
true -> Item4
|
||||
end;
|
||||
true -> Item4
|
||||
end;
|
||||
true -> Item4#item{quality = Item4#item.quality - Item4#item.quality}
|
||||
end;
|
||||
true ->
|
||||
if
|
||||
Item4#item.quality < 50 ->
|
||||
Item4#item{quality = Item4#item.quality + 1};
|
||||
true -> Item4
|
||||
end
|
||||
end;
|
||||
true -> Item4
|
||||
end.
|
||||
@@ -0,0 +1,20 @@
|
||||
-module('TextTestFixture').
|
||||
|
||||
-include("GildedRose.hrl").
|
||||
|
||||
-export([print_update_quality/2]).
|
||||
|
||||
print_one_day(Day, Items) ->
|
||||
io:format("~n-------- day ~p --------~n", [Day]),
|
||||
io:format("name, sellIn, quality~n", []),
|
||||
lists:foreach(fun(#item{name = Name, sell_in = SellIn, quality = Quality}) ->
|
||||
io:format("~s, ~p, ~p~n", [Name, SellIn, Quality])
|
||||
end, Items).
|
||||
|
||||
print_update_quality(Days, Items) ->
|
||||
io:format("OMGHAI!"),
|
||||
lists:foreach(
|
||||
fun(Day) -> print_one_day(Day, Items),
|
||||
'GildedRose':update_quality(Items)
|
||||
end, lists:seq(0, Days - 1)).
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{application, gilded_rose, [{vsn, "0.1"}]}.
|
||||
@@ -1,87 +0,0 @@
|
||||
-module(gilded_rose).
|
||||
|
||||
-include("gilded_rose.hrl").
|
||||
|
||||
-export([
|
||||
update_quality/1
|
||||
]).
|
||||
|
||||
-spec update_quality([#item{}]) -> [#item{}].
|
||||
update_quality(Items) ->
|
||||
lists:map(fun update_item/1, Items).
|
||||
|
||||
-spec update_item(#item{}) -> #item{}.
|
||||
update_item(Item = #item{name = Name}) ->
|
||||
Item1 = if
|
||||
Name /= "Aged Brie" andalso Name /= "Backstage passes to a TAFKAL80ETC concert" ->
|
||||
if
|
||||
Item#item.quality > 0 ->
|
||||
if
|
||||
Name /= "Sulfuras, Hand of Ragnaros" ->
|
||||
Item#item{quality = Item#item.quality - 1};
|
||||
true ->
|
||||
Item
|
||||
end;
|
||||
true ->
|
||||
Item
|
||||
end;
|
||||
true ->
|
||||
if
|
||||
Item#item.quality < 50 ->
|
||||
Item2 = Item#item{quality = Item#item.quality + 1},
|
||||
if
|
||||
Name == "Backstage passes to a TAFKAL80ETC concert" ->
|
||||
Item3 = if
|
||||
Item2#item.sell_in < 11 ->
|
||||
if
|
||||
Item2#item.quality < 50 ->
|
||||
Item2#item{quality = Item2#item.quality + 1};
|
||||
true -> Item2
|
||||
end;
|
||||
true -> Item2
|
||||
end,
|
||||
if
|
||||
Item3#item.sell_in < 6 ->
|
||||
if
|
||||
Item3#item.quality < 50 ->
|
||||
Item3#item{quality = Item3#item.quality + 1};
|
||||
true -> Item3
|
||||
end;
|
||||
true -> Item3
|
||||
end;
|
||||
true -> Item2
|
||||
end;
|
||||
true -> Item
|
||||
end
|
||||
end,
|
||||
Item4 = if
|
||||
Name /= "Sulfuras, Hand of Ragnaros" ->
|
||||
Item1#item{sell_in = Item1#item.sell_in - 1};
|
||||
true -> Item1
|
||||
end,
|
||||
if
|
||||
Item4#item.sell_in < 0 ->
|
||||
if
|
||||
Name /= "Aged Brie" ->
|
||||
if
|
||||
Name /= "Backstage passes to a TAFKAL80ETC concert" ->
|
||||
if
|
||||
Item4#item.quality > 0 ->
|
||||
if
|
||||
Name /= "Sulfuras, Hand of Ragnaros" ->
|
||||
Item4#item{quality = Item4#item.quality - 1};
|
||||
true -> Item4
|
||||
end;
|
||||
true -> Item4
|
||||
end;
|
||||
true -> Item4#item{quality = Item4#item.quality - Item4#item.quality}
|
||||
end;
|
||||
true ->
|
||||
if
|
||||
Item4#item.quality < 50 ->
|
||||
Item4#item{quality = Item4#item.quality + 1};
|
||||
true -> Item4
|
||||
end
|
||||
end;
|
||||
true -> Item4
|
||||
end.
|
||||
Reference in new issue
Block a user