6b6e4413482e — MiyamotoAkira 11 months ago
Set tests for the basic rules on F#
1 files changed, 136 insertions(+), 4 deletions(-)

M tests/GildedRose.FSharp.Tests/Tests.fs
M tests/GildedRose.FSharp.Tests/Tests.fs +136 -4
@@ 1,8 1,140 @@ 
-module Tests
+namespace GildedRose.Tests
 
 open System
 open Xunit
 
-[<Fact>]
-let ``My test`` () =
-    Assert.True(true)
+open GildedRose.Console
+
+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)
+
+        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)
+
+        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)
+
+        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(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)
+
+        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)
+
+        Assert.Equal(0, item.SellIn)
+        app.UpdateQuality()
+        Assert.Equal(0, item.SellIn)
+
+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)
+
+        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)
+
+        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)
+
+        Assert.Equal(3, item.Quality)
+        app.UpdateQuality()
+        Assert.Equal(6, item.Quality)
+
+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)
+
+        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)
+
+        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)
+
+        Assert.Equal(51, item.Quality)
+        app.UpdateQuality()
+        Assert.Equal(51, item.Quality)
+