Skip to content

Instantly share code, notes, and snippets.

View lefthandedgoat's full-sized avatar

Chris Holt lefthandedgoat

View GitHub Profile
@lefthandedgoat
lefthandedgoat / fsharpgravitykata
Created February 28, 2012 00:17
fsharp gravity kata
let floored block =
snd block = 0
let collision blocks block =
List.exists(fun b -> b = block) blocks
let otherblocks blocks block = List.filter(fun b -> b <> block) blocks
let rec fall blocks block =
let fallenBlock = (fst block, snd block - 1)
@lefthandedgoat
lefthandedgoat / gist:2211454
Created March 27, 2012 01:17
f# basic mancala
//test framework
let mutable tests = []
let test f = tests <- List.append tests [f]
let run _ = List.map (fun f -> (f ())) tests
let runp _ = List.toArray tests |> Array.Parallel.map (fun f -> (f ()))
let (==) value1 value2 = System.Console.WriteLine("{0} expected: {1} got: {2}", (value1 = value2), value2, value1)
let describe description = System.Console.WriteLine(description.ToString())
//implementation
let mutable tests = []
let test f = tests <- List.append tests [f]
let run _ = List.map (fun f -> (f ())) tests
let runp _ = List.toArray tests |> Array.Parallel.map (fun f -> (f ()))
let (==) value1 value2 = System.Console.WriteLine("{0} expected: {1} got: {2}", (value1 = value2), value2, value1)
let describe description = System.Console.WriteLine(description.ToString())
type Cell = { x : int; y : int; moves : int }
let rec go (canGo : Cell list) (toTest : Cell list) (obstacles : Cell list)=
@lefthandedgoat
lefthandedgoat / gist:3000685
Created June 27, 2012 01:30
calendar kata fs
module runner
let mutable tests = []
let test f = tests <- List.append tests [f]
let xtest f = ()
let mutable before = fun () -> ()
let run _ = List.map (fun f -> (before ()
f ())) tests
let (==) value1 value2 = System.Console.WriteLine("{0} expected: {1} got: {2}", (value1 = value2), value2, value1)
let describe description = System.Console.WriteLine(description.ToString())
@lefthandedgoat
lefthandedgoat / gist:3505905
Created August 29, 2012 01:29
shorter mancala
//test framework
open System
let mutable tests = []
let test f = tests <- List.append tests [f]
let xtest f = ()
let mutable before = fun () -> ()
let run _ = List.map (fun f -> (before ()
f ())) tests
let describe description = Console.WriteLine(description.ToString())
let (==) value1 value2 =
let setTerminationDate agentNumber toTerminated =
using(new AgencyManagement()) (fun db ->
let agent = query <@ seq { for a in db.Agents do
if a.AgentNumber = agentNumber then yield a } @> |> Seq.head
if toTerminated = true then
agent.TerminationDate <- new Nullable<DateTime>(DateTime.Now)
else
agent.TerminationDate <- new Nullable<DateTime>()
db.SaveChanges() |> ignore
)
@lefthandedgoat
lefthandedgoat / gist:3762507
Created September 21, 2012 16:32
multi-lib tests
// Learn more about F# at http://fsharp.net
open canopy
open runner
let switchTo b = browser <- b
let index = "http://dry-peak-5299.herokuapp.com/"
let createGame = ".nav li a"
let cardCzar = "#notificationCardCzar"
let waiting = "#notificationWaitingOnRound"
@lefthandedgoat
lefthandedgoat / gist:3984326
Created October 31, 2012 01:43
minesweeper kata
// Learn more about F# at http://fsharp.net
open System
let mutable tests = []
let test f = tests <- List.append tests [f]
let xtest f = ()
let mutable before = fun () -> ()
let run _ = List.map (fun f -> (before ()
f ())) tests
let describe description = Console.WriteLine(description.ToString())
@lefthandedgoat
lefthandedgoat / gist:5644949
Created May 24, 2013 17:03
canopy gherkin
module gherkin
open System.Text.RegularExpressions
open System.Linq
type Mode = Given | When | Then
type gwt () = class
let mutable mode = Given
let mutable givens : (unit -> unit) list = []
let mutable whens : (unit -> unit) list = []
open canopy
open runner
open Microsoft.FSharp.Reflection
type command =
| Ram
| Dragon
| Rat
| Tiger
| Dog