Skip to content

Instantly share code, notes, and snippets.

@smat
Created September 17, 2011 10:26
Show Gist options
  • Save smat/1223822 to your computer and use it in GitHub Desktop.
Save smat/1223822 to your computer and use it in GitHub Desktop.
Exercise on BEKK-course of clojure
(ns testproj.exercise1
(:use [clojure.test])
(:use [midje.sweet])
)
(unfinished procedures animals in-use? can-be-done?)
(defn on-animal [predicate arg]
(fn [x] (predicate arg x)))
(defn exclusion-per-procedure [procedure]
(set (remove (on-animal can-be-done? procedure) (animals))))
(defn exclusion-by-time [timeslice]
(set (filter (on-animal in-use? timeslice) (animals))))
(defn exclusion-by-procedure []
(zipmap (procedures) (map exclusion-per-procedure (procedures)) ))
(defn exclusions [timeslice]
(merge-with (comp set concat) (exclusion-by-procedure) (zipmap (procedures) (repeat (exclusion-by-time timeslice)))))
(deftest wrapper
(fact ""
(exclusion-per-procedure ...horse-only...) => #{...cow...}
(provided (animals) => [...horse... ...cow...])
(provided (can-be-done? ...horse-only... ...horse...) => true)
(provided (can-be-done? ...horse-only... ...cow...) => false)
)
(fact ""
(exclusion-by-time ...timeslice...) => #{...an-animal...}
(provided (animals) => [...an-animal... ...another-animal...])
(provided (in-use? ...timeslice... ...an-animal...) => true)
(provided (in-use? ...timeslice... ...another-animal...) => false)
)
(fact ""
(exclusion-by-procedure) => {...horse-only... [...cow...]
...all-animals... []
...cow-only... [...horse...]}
(provided (procedures) => [...horse-only... ...cow-only... ...all-animals...])
(provided (exclusion-per-procedure ...horse-only...) => [...cow...])
(provided (exclusion-per-procedure ...all-animals...) => [])
(provided (exclusion-per-procedure ...cow-only...) => [...horse...])
)
(fact ""
(exclusions ...time-slice...) => { ...horse-only... #{...cow... ...horse...}
...all-animal... #{...horse...}
...cow-only... #{...horse...}
}
(provided (exclusion-by-procedure) => {...all-animal... []
...horse-only... [...cow...]
...cow-only... [...horse...]
})
(provided (exclusion-by-time ...time-slice...) => #{...horse...})
(provided (procedures) => [...horse-only... ...all-animal... ...cow-only...])
)
) (run-tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment