Last active
December 15, 2015 18:28
-
-
Save vasily-kirichenko/5303699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ComposableTesting | |
open System.Net | |
open System.IO | |
open System | |
let download (uri: Uri) = | |
use cl = new WebClient() | |
cl.DownloadString uri | |
let parse (line: string) = | |
line.Split [|';'|] | |
|> Seq.skip 1 | |
|> Seq.take 3 | |
let write file (lines: string seq) = | |
use sw = new StreamWriter (path=file) | |
lines |> Seq.iter sw.WriteLine | |
// we can write only end-to-end tests for it, which will download actual | |
// data then saves it into a real file on disk | |
let processUri uri = | |
uri | |
|> download | |
|> parse | |
|> write "file.txt" | |
// there's no way to test it since the calls to processUri is hardcoded | |
let processUris file = | |
File.ReadLines file | |
|> Seq.map (fun x -> Uri x) | |
|> Seq.iter processUri | |
// yes, we can write (integration) tests for it | |
let processUris' file f = | |
File.ReadLines file | |
|> Seq.map (fun x -> Uri x) | |
|> Seq.iter f | |
// we can easily write unit/property-based tests for it, but... | |
let processUris'' reader file f = | |
reader file | |
|> Seq.map (fun x -> Uri x) | |
|> Seq.iter f | |
// nice | |
processUris "src.txt" | |
// ugly | |
processUris' "src.txt" processUri | |
// even uglier... | |
processUris'' File.ReadLines "src.txt" processUri |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment