d63492e75d84 — MiyamotoAkira 10 months ago
Changed test to reflect the c# version
1 files changed, 112 insertions(+), 107 deletions(-)

M tests/GildedRose.FSharp.Tests/Tests.fs
M tests/GildedRose.FSharp.Tests/Tests.fs +112 -107
@@ 5,136 5,141 @@ open Xunit
 
 open GildedRose.Console
 
-module StandardItem =
-    let Vest = "+5 Dexterity Vest"
+module Tests =
+
+    let findItemByName (app: Program) name =
+        app.Items |> Seq.toList |> List.find (fun x -> x.Name = name)
+        
+    module StandardItem =
+        let Vest = "+5 Dexterity Vest"
 
-    [<Fact>]
-    let ``Standard item degrades quality before "sell in"`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Vest, SellIn = 2, Quality = 20)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Vest)
+        [<Fact>]
+        let ``Standard item degrades quality before "sell in"`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Vest, SellIn = 2, Quality = 20)])
+            let item = findItemByName app Vest
 
-        Assert.Equal(20, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(19, item.Quality)
+            Assert.Equal(20, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(19, item.Quality)
 
 
-    [<Fact>]
-    let ``Standard item sell in gets reduced`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Vest, SellIn = 2, Quality = 20)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Vest)
+        [<Fact>]
+        let ``Standard item sell in gets reduced`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Vest, SellIn = 2, Quality = 20)])
+            let item = findItemByName app Vest
 
-        Assert.Equal(2, item.SellIn)
-        app.UpdateQuality()
-        Assert.Equal(1, item.SellIn)
+            Assert.Equal(2, item.SellIn)
+            app.UpdateQuality()
+            Assert.Equal(1, item.SellIn)
 
-    [<Fact>]
-    let ``Standard item degrades in quality after "sell in"`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Vest, SellIn = 0, Quality = 20)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Vest)
+        [<Fact>]
+        let ``Standard item degrades in quality after "sell in"`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Vest, SellIn = 0, Quality = 20)])
+            let item = findItemByName app Vest
 
-        Assert.Equal(20, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(18, item.Quality)
-
-    [<Fact>]
-    let ``Standard item don't go below 0 quality`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Vest, SellIn = 0, Quality = 0)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Vest)
+            Assert.Equal(20, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(18, item.Quality)
 
-        Assert.Equal(0, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(0, item.Quality)
+        [<Fact>]
+        let ``Standard item don't go below 0 quality`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Vest, SellIn = 0, Quality = 0)])
+            let item = findItemByName app Vest
+            
+            Assert.Equal(0, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(0, item.Quality)
 
-module SulfurasRules =
-    let Sulfuras = "Sulfuras, Hand of Ragnaros"
-
-    [<Fact>]
-    let ``Sulfuras quality is constant`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Sulfuras, SellIn = 0, Quality = 80)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Sulfuras)
+    module SulfurasRules =
+        let Sulfuras = "Sulfuras, Hand of Ragnaros"
 
-        Assert.Equal(80, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(80, item.Quality)
+        [<Fact>]
+        let ``Sulfuras quality is constant`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Sulfuras, SellIn = 0, Quality = 80)])
+            let item = findItemByName app Sulfuras
+
+            Assert.Equal(80, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(80, item.Quality)
 
-    [<Fact>]
-    let ``Sulfuras "sell in" is always Zero`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Sulfuras, SellIn = 0, Quality = 80)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Sulfuras)
+        [<Fact>]
+        let ``Sulfuras "sell in" is always Zero`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Sulfuras, SellIn = 0, Quality = 80)])
+            let item = findItemByName app Sulfuras
 
-        Assert.Equal(0, item.SellIn)
-        app.UpdateQuality()
-        Assert.Equal(0, item.SellIn)
+            Assert.Equal(0, item.SellIn)
+            app.UpdateQuality()
+            Assert.Equal(0, item.SellIn)
 
-module BackstageRules =
-    let Backstage = "Backstage passes to a TAFKAL80ETC concert"
+    module BackstageRules =
+        let Backstage = "Backstage passes to a TAFKAL80ETC concert"
 
-    [<Fact>]
-    let ``Backstage goes to zero quality after "sell in"`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Backstage, SellIn = 0, Quality = 3)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Backstage)
+        [<Fact>]
+        let ``Backstage goes to zero quality after "sell in"`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Backstage, SellIn = 0, Quality = 3)])
+            let item = findItemByName app Backstage
 
-        Assert.Equal(3, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(0, item.Quality)
+            Assert.Equal(3, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(0, item.Quality)
 
-    [<Fact>]
-    let ``Backstage quality goes up by two with 10 or less days`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Backstage, SellIn = 10, Quality = 3)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Backstage)
+        [<Fact>]
+        let ``Backstage quality goes up by two with 10 or less days`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Backstage, SellIn = 10, Quality = 3)])
+            let item = findItemByName app Backstage
 
-        Assert.Equal(3, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(5, item.Quality)
+            Assert.Equal(3, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(5, item.Quality)
 
-    [<Fact>]
-    let ``Backstage quality goes up by three with 5 or less days`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Backstage, SellIn = 5, Quality = 3)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Backstage)
+        [<Fact>]
+        let ``Backstage quality goes up by three with 5 or less days`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Backstage, SellIn = 5, Quality = 3)])
+            let item = findItemByName app Backstage
 
-        Assert.Equal(3, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(6, item.Quality)
+            Assert.Equal(3, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(6, item.Quality)
 
-module BrieRules =
-    let Brie = "Aged Brie"
+    module BrieRules =
+        let Brie = "Aged Brie"
 
-    [<Fact>]
-    let ``Aged brie increases quality `` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Brie, SellIn = 2, Quality = 0)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Brie)
+        [<Fact>]
+        let ``Aged brie increases quality `` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Brie, SellIn = 2, Quality = 0)])
+            let item = findItemByName app Brie
 
-        Assert.Equal(0, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(1, item.Quality)
+            Assert.Equal(0, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(1, item.Quality)
 
-    [<Fact>]
-    let ``Aged brie quality doesn't go over 50`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Brie, SellIn = 2, Quality = 50)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Brie)
+        [<Fact>]
+        let ``Aged brie quality doesn't go over 50`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Brie, SellIn = 2, Quality = 50)])
+            let item = findItemByName app Brie
 
-        Assert.Equal(50, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(50, item.Quality)
+            Assert.Equal(50, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(50, item.Quality)
 
-    [<Fact>]
-    let ``Aged brie quality doesn't increase if already over 50`` () =
-        let app = new Program()
-        app.Items <- ResizeArray<Item>([new Item (Name = Brie, SellIn = 2, Quality = 51)])
-        let item = app.Items |> Seq.toList |> List.find (fun x -> x.Name = Brie)
+        [<Fact>]
+        let ``Aged brie quality doesn't increase if already over 50`` () =
+            let app = new Program()
+            app.Items <- ResizeArray<Item>([new Item (Name = Brie, SellIn = 2, Quality = 51)])
+            let item = findItemByName app Brie
 
-        Assert.Equal(51, item.Quality)
-        app.UpdateQuality()
-        Assert.Equal(51, item.Quality)
-    
+            Assert.Equal(51, item.Quality)
+            app.UpdateQuality()
+            Assert.Equal(51, item.Quality)
+