Permalink
Browse files

Move scoring code out

  • Loading branch information...
1 parent e7d8120 commit ade66264efe13ffaf0b612e74a1e45d3865c09ef @lvh committed Mar 6, 2014
Showing with 26 additions and 21 deletions.
  1. +2 −15 src/hood/core.clj
  2. +15 −0 src/hood/score.clj
  3. +0 −6 test/hood/core_test.clj
  4. +9 −0 test/hood/score_test.clj
View
@@ -1,19 +1,6 @@
(ns hood.core
- (:require [clojure.set :refer [difference]]))
-
-(def score-funcs
- [[1 (constantly 1)]
- [5 (fn [a] (if (:student a) 1 0))]])
-
-(defn score*
- "Computes the score of an allocation."
- [a]
- (reduce (fn [acc [w f]]
- (+ acc (* w (f a))))
- 0 score-funcs))
-
-(def score
- (memoize score*))
+ (:require [clojure.set :refer [difference]]
+ [hood.score :refer [score]]))
(defn one-pass-alloc
"Allocates funds to all people that are requesting less than their
View
@@ -0,0 +1,15 @@
+(ns hood.score)
+
+(def score-funcs
+ [[1 (constantly 1)]
+ [5 (fn [a] (if (:student a) 1 0))]])
+
+(defn score*
+ "Computes the score of an allocation."
+ [a]
+ (reduce (fn [acc [w f]]
+ (+ acc (* w (f a))))
+ 0 score-funcs))
+
+(def score
+ (memoize score*))
View
@@ -2,12 +2,6 @@
(:require [clojure.test :refer :all]
[hood.core :refer :all]))
-(deftest score-test
- (testing "scores don't fail on empty apps"
- (is (= (score* {}) 1)))
- (testing "a student"
- (is (= (score* {:student :true}) 6))))
-
(deftest needs-alloc?-test
(testing "is reviewed"
(is (needs-alloc? {:state :reviewed})))
View
@@ -0,0 +1,9 @@
+(ns hood.score-test
+ (:require [hood.score :refer :all]
+ [clojure.test :refer :all]))
+
+(deftest score-test
+ (testing "scores don't fail on empty apps"
+ (is (= (score* {}) 1)))
+ (testing "a student"
+ (is (= (score* {:student :true}) 6))))

0 comments on commit ade6626

Please sign in to comment.