Skip to content

Instantly share code, notes, and snippets.

@jasondown
Created December 23, 2021 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasondown/ef01722b94cc9676ec8168ec2b51bb5b to your computer and use it in GitHub Desktop.
Save jasondown/ef01722b94cc9676ec8168ec2b51bb5b to your computer and use it in GitHub Desktop.
// test
let consolePrinter = Printer(System.Console.Out.WriteLine)
let vm = VendingMachine(3, consolePrinter)
consolePrinter.Print(sprintf $"Current stock: {vm.GetStock()}")
// fsi:
// Current stock: 3
let custId1 = 1
let custId2 = 2
vm.BuyItem(custId1)
// fsi:
// Vend item to customer 1
// New stock: 2
vm.BuyItem(custId2)
// fsi:
// Vend item to customer 2
// New stock: 1
vm.BuyItem(custId1)
// fsi:
// Vend item to customer 1
// New stock: 0
vm.BuyItem(custId2)
// fsi:
// Request for customer 2 will be fulfilled after machine is restocked
vm.BuyItem(custId1)
// fsi:
// Request for customer 1 will be fulfilled after machine is restocked
vm.Restock(3)
// fsi:
// Restocking with 3
// Current stock: 3
// Vend item to customer 2
// New stock: 2
// Vend item to customer 2
// New stock: 1
vm.Restock(7)
// fsi:
// Restocking with 7
// Current stock: 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment