So far, all the properties we have written have tested stateless code. Stateless code is made up of pure functions and is inherently easier to test than stateful code with side effects. The chief problem with testing stateful code is that the input to output mapping depends on the current state of the program. Previous operations can cause the same function to return different output given the same input. Therefore, in order to test stateful code, our tests must maintain some state of their own. This state is known as the model state and is updated as part of the testing process.
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
;; Deriving something like generators, but I didn't really feel like | |
;; doing exactly that. | |
;; It doesn't, for instance, support sending back into the generator | |
;; This applys a function across a range from 0 to x. | |
(define (apply-to-range f i x) | |
(when (< i x) | |
(f i) | |
(apply-to-range f (+ 1 i) x))) |
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
#Code from http://fmota.eu/, great! | |
class Monoid: | |
def __init__(self, null, lift, op): | |
self.null = null | |
self.lift = lift | |
self.op = op | |
def fold(self, xs): | |
if hasattr(xs, "__fold__"): | |
return xs.__fold__(self) |
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
(ns markerbot.core | |
(:require [taoensso.timbre :as log] | |
[clojure.data.json :as json] | |
[clojure.string :as s] | |
[clj-http.client :as client]) | |
(:import (java.net Socket) | |
(java.io PrintWriter InputStreamReader BufferedReader)) | |
(:gen-class)) | |
;; marksy |
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
Latency Comparison Numbers | |
-------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns | |
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms | |
Read 4K randomly from SSD* 150,000 ns 0.15 ms |
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
/** | |
* Creates an ArrayBuffer, converts the binary to a Uint8 Array, and | |
* places the buffer in a DataView, which is needed to create a Blob | |
**/ | |
_makeBlob: function(binary) { | |
var data = new ArrayBuffer(binary.length), | |
mimeString = "text/plain", | |
ui8a = new Uint8Array(data, 0), | |
dataView, | |
blob; |
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
import os, sys, glob | |
import cv | |
import math | |
import argparse | |
HAAR_CASCADE_FRONT = \ | |
"/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml" | |
HAAR_CASCADE_PROFILE = \ | |
"/usr/local/share/OpenCV/haarcascades/haarcascade_profileface.xml" |
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
import os | |
import sys | |
import glob | |
import cv | |
import math | |
import argparse | |
from collections import OrderedDict | |
HAAR_CASCADE_FRONT = \ | |
"/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml" |
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
_.mixin({ | |
capitalize: function(string) { | |
return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase(); | |
}, | |
startsWith: function(string, start) { | |
return string.slice(0, start.length) == start; | |
}, |
NewerOlder