From c4cde444355f62fa88dc72b354e56bc17fee8206 Mon Sep 17 00:00:00 2001 From: Alexander Ilin Date: Sun, 3 Mar 2024 21:34:34 +0100 Subject: [PATCH] gilded-rose: new vocab Translated from: https://github.com/emilybache/GildedRose-Refactoring-Kata/blob/main/Delphi/GildedRose.pas https://github.com/emilybache/GildedRose-Refactoring-Kata/blob/main/Delphi/TextTestFixture.dpr --- extra/gilded-rose/authors.txt | 1 + extra/gilded-rose/gilded-rose-docs.factor | 15 ++++ extra/gilded-rose/gilded-rose.factor | 98 +++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 extra/gilded-rose/authors.txt create mode 100644 extra/gilded-rose/gilded-rose-docs.factor create mode 100644 extra/gilded-rose/gilded-rose.factor diff --git a/extra/gilded-rose/authors.txt b/extra/gilded-rose/authors.txt new file mode 100644 index 0000000000..8e1955f8e1 --- /dev/null +++ b/extra/gilded-rose/authors.txt @@ -0,0 +1 @@ +Alexander Ilin diff --git a/extra/gilded-rose/gilded-rose-docs.factor b/extra/gilded-rose/gilded-rose-docs.factor new file mode 100644 index 0000000000..6436290401 --- /dev/null +++ b/extra/gilded-rose/gilded-rose-docs.factor @@ -0,0 +1,15 @@ +! Copyright (C) 2024 Alexander Ilin. +! See https://factorcode.org/license.txt for BSD license. +USING: help.markup help.syntax kernel strings ; +IN: gilded-rose + +ARTICLE: "gilded-rose" "gilded-rose" +"The " { $vocab-link "gilded-rose" } " vocab contains the Gilded Rose kata, " +"which is a bit of source code for you to practice refactoring. See the history " +"behind the original code, as well as the task description in the READMEs " +"here: " { $url "https://github.com/emilybache/GildedRose-Refactoring-Kata" } +"." +$nl +"The Factor source is based on the Delphi translation of the C# original." ; + +ABOUT: "gilded-rose" diff --git a/extra/gilded-rose/gilded-rose.factor b/extra/gilded-rose/gilded-rose.factor new file mode 100644 index 0000000000..034a019381 --- /dev/null +++ b/extra/gilded-rose/gilded-rose.factor @@ -0,0 +1,98 @@ +! Copyright (C) 2024 Alexander Ilin. +! See https://factorcode.org/license.txt for BSD license. +USING: accessors command-line formatting io kernel make math +math.parser namespaces sequences ; +IN: gilded-rose + +TUPLE: GildedRose + Items ; + +TUPLE: Item + Name SellIn Quality ; + +: Item.ToString ( item -- str ) + [ Name>> ] [ SellIn>> ] [ Quality>> ] tri "%s %d %d" sprintf ; + +:: GildedRose.UpdateQuality ( this -- ) + this Items>> length [| i | + i this Items>> nth Name>> "Aged Brie" = not + i this Items>> nth Name>> "Backstage passes to a TAFKAL80ETC concert" = not + and [ + i this Items>> nth Quality>> 0 > [ + i this Items>> nth Name>> "Sulfuras, Hand of Ragnaros" = not [ + i this Items>> nth Quality>> 1 - + i this Items>> nth Quality<< + ] when + ] when + ] [ + i this Items>> nth Quality>> 50 < [ + i this Items>> nth Quality>> 1 + + i this Items>> nth Quality<< + i this Items>> nth Name>> "Backstage passes to a TAFKAL80ETC concert" = [ + i this Items>> nth SellIn>> 11 < [ + i this Items>> nth Quality>> 50 < [ + i this Items>> nth Quality>> 1 + + i this Items>> nth Quality<< + ] when + ] when + i this Items>> nth SellIn>> 6 < [ + i this Items>> nth Quality>> 50 < [ + i this Items>> nth Quality>> 1 + + i this Items>> nth Quality<< + ] when + ] when + ] when + ] when + ] if + + i this Items>> nth Name>> "Sulfuras, Hand of Ragnaros" = not [ + i this Items>> nth SellIn>> 1 - + i this Items>> nth SellIn<< + ] when + + i this Items>> nth SellIn>> 0 < [ + i this Items>> nth Name>> "Aged Brie" = not [ + i this Items>> nth Name>> "Backstage passes to a TAFKAL80ETC concert" = [ + i this Items>> nth Quality>> 0 > [ + i this Items>> nth Name>> "Sulfuras, Hand of Ragnaros" = not [ + i this Items>> nth Quality>> 1 - + i this Items>> nth Quality<< + ] when + ] when + ] [ + i this Items>> nth Quality>> i this Items>> nth Quality>> - + i this Items>> nth Quality<< + ] if + ] [ + i this Items>> nth Quality>> 50 < [ + i this Items>> nth Quality>> 1 + + i this Items>> nth Quality<< + ] when + ] if + ] when + ] each-integer ; + +: main ( -- ) + "OMGHAI!" print + [ + "+5 Dexterity Vest" 10 20 Item boa , + "Aged Brie" 2 0 Item boa , + "Elixir of the Mongoose" 5 7 Item boa , + "Sulfuras, Hand of Ragnaros" 0 80 Item boa , + "Sulfuras, Hand of Ragnaros" -1 80 Item boa , + "Backstage passes to a TAFKAL80ETC concert" 15 20 Item boa , + "Backstage passes to a TAFKAL80ETC concert" 10 49 Item boa , + "Backstage passes to a TAFKAL80ETC concert" 5 49 Item boa , + ! This conjured item does not work properly yet. + "Conjured Mana Cake" 3 6 Item boa , + ] { } make GildedRose boa + + command-line get [ 2 ] [ first dec> ] if-empty [ + "-------- day %d --------\n" printf + "name, sellIn, quality" print + dup Items>> [ Item.ToString print ] each + nl + GildedRose.UpdateQuality + ] with each-integer ; + +MAIN: main -- 2.34.1