Created
January 24, 2014 00:25
-
-
Save eraserhd/8589703 to your computer and use it in GitHub Desktop.
An attempt at testing multiple splices via simple-check.
This file contains hidden or 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
;; 1. What I'm testing: A rope implementation where the binary tree is | |
;; balanced by splaying. | |
;; 2. To simplify things, it supports one update operation: | |
;; (splice rope start-offset end-offset new-data) | |
;; 3. I'd like to verify that the nodes are in the right order and other | |
;; properties after multiple splicings | |
;; Here's a spec I wrote for testing that the rope has the right | |
;; string representation after a single insertion-type splice: | |
(defspec splice-for-insertion 100 | |
(prop/for-all* [(gen/bind | |
gen/string | |
(fn [string] | |
(gen/tuple (gen/return string) | |
(gen/choose 0 (count string)) | |
gen/string)))] | |
(fn [[initial-value offset inserted]] | |
(= (str (splice (rope initial-value) offset offset inserted)) | |
(str (.substring initial-value 0 offset) | |
inserted | |
(.substring initial-value offset)))))) | |
;; So far, so good. Here's the problem. I want to generate a number | |
;; of tests which are: | |
;; a. An initial string | |
;; b. A number of offsets and strings to insert. | |
;; | |
;; I can get close with: | |
(gen/bind | |
gen/string | |
(fn [string] | |
(gen/tuple (gen/return string) | |
(gen/vector (gen/tuple (gen/choose 0 (count string)) | |
gen/string))))) | |
;; The problem: the gen/choose's upper bound needs to grow as the | |
;; string would grow. (In fact, there's edge cases for insertions | |
;; at the end for sure.) I imagine this could be done recursively, | |
;; but gen/bind doesn't seem to be powerful enough to do that. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment