mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-10-13 17:49:25 +00:00
Added F# starter solution based on .NET Core
This commit is contained in:
1 parent
a0a860d0fe
commit
7ce7df7c7e
8 files changed
+588
No files matched your search
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Update="FSharp.Core" Version="4.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,65 @@
|
||||
namespace GildedRose
|
||||
|
||||
open System.Collections.Generic
|
||||
|
||||
type Item = { Name: string; SellIn: int; Quality: int }
|
||||
|
||||
type GildedRose(items:IList<Item>) =
|
||||
let Items = items
|
||||
|
||||
member this.UpdateQuality() =
|
||||
for i = 0 to Items.Count - 1 do
|
||||
if Items.[i].Name <> "Aged Brie" && Items.[i].Name <> "Backstage passes to a TAFKAL80ETC concert" then
|
||||
if Items.[i].Quality > 0 then
|
||||
if Items.[i].Name <> "Sulfuras, Hand of Ragnaros" then
|
||||
Items.[i] <- { Items.[i] with Quality = (Items.[i].Quality - 1) }
|
||||
else
|
||||
if Items.[i].Quality < 50 then
|
||||
Items.[i] <- { Items.[i] with Quality = (Items.[i].Quality + 1) }
|
||||
if Items.[i].Name = "Backstage passes to a TAFKAL80ETC concert" then
|
||||
if Items.[i].SellIn < 11 then
|
||||
if Items.[i].Quality < 50 then
|
||||
Items.[i] <- { Items.[i] with Quality = (Items.[i].Quality + 1) }
|
||||
if Items.[i].SellIn < 6 then
|
||||
if Items.[i].Quality < 50 then
|
||||
Items.[i] <- { Items.[i] with Quality = (Items.[i].Quality + 1) }
|
||||
if Items.[i].Name <> "Sulfuras, Hand of Ragnaros" then
|
||||
Items.[i] <- { Items.[i] with SellIn = (Items.[i].SellIn - 1) }
|
||||
if Items.[i].SellIn < 0 then
|
||||
if Items.[i].Name <> "Aged Brie" then
|
||||
if Items.[i].Name <> "Backstage passes to a TAFKAL80ETC concert" then
|
||||
if Items.[i].Quality > 0 then
|
||||
if Items.[i].Name <> "Sulfuras, Hand of Ragnaros" then
|
||||
Items.[i] <- { Items.[i] with Quality = (Items.[i].Quality - 1) }
|
||||
else
|
||||
Items.[i] <- { Items.[i] with Quality = (Items.[i].Quality - Items.[i].Quality) }
|
||||
else
|
||||
if Items.[i].Quality < 50 then
|
||||
Items.[i] <- { Items.[i] with Quality = (Items.[i].Quality + 1) }
|
||||
()
|
||||
|
||||
|
||||
module Program =
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
printfn "OMGHAI!"
|
||||
let Items = new List<Item>()
|
||||
Items.Add({Name = "+5 Dexterity Vest"; SellIn = 10; Quality = 20})
|
||||
Items.Add({Name = "Aged Brie"; SellIn = 2; Quality = 0})
|
||||
Items.Add({Name = "Elixir of the Mongoose"; SellIn = 5; Quality = 7})
|
||||
Items.Add({Name = "Sulfuras, Hand of Ragnaros"; SellIn = 0; Quality = 80})
|
||||
Items.Add({Name = "Sulfuras, Hand of Ragnaros"; SellIn = -1; Quality = 80})
|
||||
Items.Add({Name = "Backstage passes to a TAFKAL80ETC concert"; SellIn = 15; Quality = 20})
|
||||
Items.Add({Name = "Backstage passes to a TAFKAL80ETC concert"; SellIn = 10; Quality = 49})
|
||||
Items.Add({Name = "Backstage passes to a TAFKAL80ETC concert"; SellIn = 5; Quality = 49})
|
||||
Items.Add({Name = "Conjured Mana Cake"; SellIn = 3; Quality = 6})
|
||||
|
||||
let app = new GildedRose(Items)
|
||||
for i = 0 to 30 do
|
||||
printfn "-------- day %d --------" i
|
||||
printfn "name, sellIn, quality"
|
||||
for j = 0 to Items.Count - 1 do
|
||||
printfn "%s, %d, %d" Items.[j].Name Items.[j].SellIn Items.[j].Quality
|
||||
printfn ""
|
||||
app.UpdateQuality()
|
||||
0
|
||||
Reference in new issue
Block a user