Created
October 7, 2011 16:44
-
-
Save marick/1270755 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
(ns scratch.core | |
(:use midje.sweet | |
[clojure.set :only [union intersection difference]] | |
)) | |
(unfinished ) | |
(defn headed-pairs [head second-halves] | |
(map (fn [second-half] [head second-half]) | |
second-halves)) | |
(fact | |
(headed-pairs :head [2 3]) => [ [:head 2] [:head 3] ]) | |
(defn tails [sequence] | |
(map drop (range 1 (count sequence)) (repeat sequence))) | |
(fact "tails produces each tail of the sequence, not including the sequence itself | |
or the empty list" | |
(tails [1 2 3]) => [ [2 3] [3] ]) | |
(defn downward-pairs [sequence] | |
(mapcat headed-pairs sequence (tails sequence))) | |
(fact "downward-pairs combines each element with all the elements in its tail" | |
(downward-pairs [1 2 3]) => (just [1 2] [1 3] | |
[2 3] | |
:in-any-order) | |
(provided | |
(headed-pairs 1 [2 3]) => [ [1 2] [1 3] ] | |
(headed-pairs 2 [3]) => [ [2 3] ] | |
(tails [1 2 3]) => [ [2 3] [3] ])) | |
(fact "the whole thing" | |
(downward-pairs '[A, B, C, D]) | |
=> (just '[[A,B], [A,C], [A,D], [B, C], [B,D], [C,D]] | |
:in-any-order)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment