using System.Collections.Generic;
public class WastedSandCounter
public int Count(int[,] sandPile)
throw new NotImplementedException();
private readonly string[] _people;
private readonly string[] _productTypes;
private readonly int _initialInventory;
public Marketplace(string[] people, string[] productTypes, int initialInventory)
_productTypes = productTypes;
_initialInventory = initialInventory;
public int CheckInventory(IEnumerable<string> transactions, string person, string productType)
throw new NotImplementedException();
public static void Main()
private static void Run()
new WastedSandCounterTests().Start();
new MarketplaceTests().Start();
public class WastedSandCounterTests
Tests.Run("WastedSandCounter should", (it) =>
it.Should(NotCountSandFallingOnTheTable,
"not count sand that falls on the table");
it.Should(CountAllSandFallingOffTheTable,
"count sand that falls off the table");
it.Should(FullyCollapseTallSandPiles,
"fully collapse tall piles of the sand");
public void NotCountSandFallingOnTheTable()
var counter = new WastedSandCounter();
counter.Count(table).ShouldBe(0);
public void CountAllSandFallingOffTheTable()
var counter = new WastedSandCounter();
counter.Count(table).ShouldBe(12);
public void FullyCollapseTallSandPiles()
var counter = new WastedSandCounter();
counter.Count(table).ShouldBe(6);
public class MarketplaceTests
Tests.Run("Marketplace should", (it) =>
it.Should(() => NotDoInvalidTransactions(), "not do transactions that are invalid");
it.Should(() => DoValidTransactions(), "do transactions that are invalid");
public void NotDoInvalidTransactions()
var marketplace = new Marketplace(new []{"Ana", "Ion"}, new []{"apples"}, 3);
marketplace.CheckInventory(new[] {"Ana sold 4 apples to Ion"}, "Ana", "apples").ShouldBe(3);
marketplace.CheckInventory(new[] {"Ion bought 4 apples from Ana"}, "Ana", "apples").ShouldBe(3);
public void DoValidTransactions()
var marketplace = new Marketplace(new []{"Ana", "Ion"}, new []{"apples"}, 4);
marketplace.CheckInventory(new[] {"Ana sold 4 apples to Ion", "Ion sold 2 apples to Ana"}, "Ana", "apples").ShouldBe(2);
public static void Run(string testGroup, Action<Tests> tests)
public static void StartTests(string testGroup)
Console.WriteLine("====================================================");
Console.WriteLine(testGroup);
Console.WriteLine("====================================================");
public void Should(Action test, string testName)
Console.WriteLine(testName);
Console.WriteLine(" Passed");
Console.WriteLine(" Failed");
Console.WriteLine(" " + e.Message);
public static void EndTests()