From cb45ff3fe7d2d96d598df98818dea548f2cd579c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Oct 2015 13:38:45 +0100 Subject: [PATCH] add fsharp version --- .../GildedRose.Tests/GildedRose.Tests.fsproj | 97 +++++++++++++++++++ fsharp/GildedRose.Tests/GildedRoseTest.fs | 32 ++++++ fsharp/GildedRose.Tests/packages.config | 6 ++ fsharp/GildedRose.sln | 28 ++++++ fsharp/GildedRose/App.config | 6 ++ fsharp/GildedRose/GildedRose.fs | 63 ++++++++++++ fsharp/GildedRose/GildedRose.fsproj | 76 +++++++++++++++ 7 files changed, 308 insertions(+) create mode 100644 fsharp/GildedRose.Tests/GildedRose.Tests.fsproj create mode 100644 fsharp/GildedRose.Tests/GildedRoseTest.fs create mode 100644 fsharp/GildedRose.Tests/packages.config create mode 100644 fsharp/GildedRose.sln create mode 100644 fsharp/GildedRose/App.config create mode 100644 fsharp/GildedRose/GildedRose.fs create mode 100644 fsharp/GildedRose/GildedRose.fsproj diff --git a/fsharp/GildedRose.Tests/GildedRose.Tests.fsproj b/fsharp/GildedRose.Tests/GildedRose.Tests.fsproj new file mode 100644 index 00000000..f021553f --- /dev/null +++ b/fsharp/GildedRose.Tests/GildedRose.Tests.fsproj @@ -0,0 +1,97 @@ + + + + + Debug + AnyCPU + 2.0 + 9f9d20e1-cfc0-442c-870a-76e5abf0e7fe + Library + GildedRose.Tests + GildedRose.Tests + v4.5 + true + 4.3.1.0 + GildedRose.Tests + + + true + full + false + false + bin\Debug\ + DEBUG;TRACE + 3 + AnyCPU + bin\Debug\GildedRose.Tests.XML + true + + + pdbonly + true + true + bin\Release\ + TRACE + 3 + AnyCPU + bin\Release\GildedRose.Tests.XML + true + + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + + + + + + + ..\packages\ApprovalTests.3.0.10\lib\net40\ApprovalTests.dll + True + + + ..\packages\ApprovalUtilities.3.0.10\lib\net45\ApprovalUtilities.dll + True + + + ..\packages\ApprovalUtilities.3.0.10\lib\net45\ApprovalUtilities.Net45.dll + True + + + + True + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + True + + + + + + GildedRose + {2660ef56-b4c1-4dcf-b106-278211bd26c6} + True + + + + \ No newline at end of file diff --git a/fsharp/GildedRose.Tests/GildedRoseTest.fs b/fsharp/GildedRose.Tests/GildedRoseTest.fs new file mode 100644 index 00000000..d29ed6d6 --- /dev/null +++ b/fsharp/GildedRose.Tests/GildedRoseTest.fs @@ -0,0 +1,32 @@ +module GildedRoseTest + +open GildedRose +open System +open System.IO +open System.Text +open NUnit.Framework +open System.Collections.Generic +open ApprovalTests +open ApprovalTests.Reporters + +[] +type GildedRoseTest () as this = + [] member this.Foo ()= + let Items = new List() + Items.Add({Name = "foo"; SellIn = 0; Quality = 0}) + let app = new GildedRose(Items) + app.UpdateQuality() + Assert.AreEqual("fixme", Items.[0].Name) + +[] +[)>] +type ApprovalTest () as this = + [] member this.ThirtyDays ()= + let fakeoutput = new StringBuilder() + Console.SetOut(new StringWriter(fakeoutput)) + Console.SetIn(new StringReader("a\n")) + + main Array.empty + let output = fakeoutput.ToString() + Approvals.Verify(output) + () \ No newline at end of file diff --git a/fsharp/GildedRose.Tests/packages.config b/fsharp/GildedRose.Tests/packages.config new file mode 100644 index 00000000..eff071b2 --- /dev/null +++ b/fsharp/GildedRose.Tests/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/fsharp/GildedRose.sln b/fsharp/GildedRose.sln new file mode 100644 index 00000000..027a29bf --- /dev/null +++ b/fsharp/GildedRose.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GildedRose", "GildedRose\GildedRose.fsproj", "{2660EF56-B4C1-4DCF-B106-278211BD26C6}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GildedRose.Tests", "GildedRose.Tests\GildedRose.Tests.fsproj", "{9F9D20E1-CFC0-442C-870A-76E5ABF0E7FE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2660EF56-B4C1-4DCF-B106-278211BD26C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2660EF56-B4C1-4DCF-B106-278211BD26C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2660EF56-B4C1-4DCF-B106-278211BD26C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2660EF56-B4C1-4DCF-B106-278211BD26C6}.Release|Any CPU.Build.0 = Release|Any CPU + {9F9D20E1-CFC0-442C-870A-76E5ABF0E7FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F9D20E1-CFC0-442C-870A-76E5ABF0E7FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F9D20E1-CFC0-442C-870A-76E5ABF0E7FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F9D20E1-CFC0-442C-870A-76E5ABF0E7FE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/fsharp/GildedRose/App.config b/fsharp/GildedRose/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/fsharp/GildedRose/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/fsharp/GildedRose/GildedRose.fs b/fsharp/GildedRose/GildedRose.fs new file mode 100644 index 00000000..f14f4cc9 --- /dev/null +++ b/fsharp/GildedRose/GildedRose.fs @@ -0,0 +1,63 @@ +module GildedRose + +open System.Collections.Generic + +type Item = { Name: string; SellIn: int; Quality: int } + +type GildedRose(items:IList) as this = + 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) } + () + +[] +let main argv = + printfn "OMGHAI!" + let Items = new List() + 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 \ No newline at end of file diff --git a/fsharp/GildedRose/GildedRose.fsproj b/fsharp/GildedRose/GildedRose.fsproj new file mode 100644 index 00000000..520dda6e --- /dev/null +++ b/fsharp/GildedRose/GildedRose.fsproj @@ -0,0 +1,76 @@ + + + + + Debug + AnyCPU + 2.0 + 2660ef56-b4c1-4dcf-b106-278211bd26c6 + Exe + GildedRose + GildedRose + v4.5 + true + 4.3.1.0 + GildedRose + + + true + full + false + false + bin\Debug\ + DEBUG;TRACE + 3 + AnyCPU + bin\Debug\GildedRose.XML + true + + + pdbonly + true + true + bin\Release\ + TRACE + 3 + AnyCPU + bin\Release\GildedRose.XML + true + + + + + True + + + + + + + + + + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + + \ No newline at end of file