Skip to content

Commit

Permalink
Merge remote branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Svazic committed Apr 13, 2011
2 parents 9751bcd + 01b2714 commit b64d54b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions clojure/test/net/auxesia/test/chromosome.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
true
(do
(is (>= (:fitness c) 0))
(is (== 13 (count (:gene c))))
(is (== (count chromosome/*target-gene*) (count (:gene c))))
(let [gene (:gene c)]
(loop [g-idx (int 0)]
(if (== g-idx (count gene))
Expand Down Expand Up @@ -86,20 +86,20 @@
(testing "Size of returned sequence from the mate function"
(is (== 2 (count children))))
(testing "Size of the gene from the first child"
(is (== 13 (count (:gene (first children))))))
(is (== (count chromosome/*target-gene*) (count (:gene (first children))))))
(testing "Size of the gene from the second child"
(is (== 13 (count (:gene (last children))))))
(is (== (count chromosome/*target-gene*) (count (:gene (last children))))))
(testing "Mating results from the first child"
(loop [g-idx 0] ; Check the first child
(when (< g-idx (count (:gene c1)))
(if (< g-idx pivot)
(is (== (int (get (:gene c1) g-idx)) (int (get (:gene (first children)) g-idx))))
(is (== (int (get (:gene c2) g-idx)) (int (get (:gene (first children)) g-idx)))))
(is (= (get (:gene c1) g-idx) (get (:gene (first children)) g-idx)))
(is (= (get (:gene c2) g-idx) (get (:gene (first children)) g-idx))))
(recur (inc g-idx)))))
(testing "Mating results from the second child"
(loop [g-idx 0] ; Check the second child
(when (< g-idx (count (:gene c2)))
(if (< g-idx pivot)
(is (== (int (get (:gene c2) g-idx)) (int (get (:gene (second children)) g-idx))))
(is (== (int (get (:gene c1) g-idx)) (int (get (:gene (second children)) g-idx)))))
(is (= (get (:gene c2) g-idx) (get (:gene (second children)) g-idx)))
(is (= (get (:gene c1) g-idx) (get (:gene (second children)) g-idx))))
(recur (inc g-idx)))))))))
30 changes: 15 additions & 15 deletions clojure/test/net/auxesia/test/population.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@
(let [p1 (population/generate 1024 0.8 0.1 0.05)
p2 (population/generate 1024 0.0 0.1 0.05)
p3 (population/generate 1024 1.0 0.1 0.05)]
(is (= 80 (int (* 100 (:crossover p1)))))
(is (= 0 (int (* 100 (:crossover p2)))))
(is (= 100 (int (* 100 (:crossover p3))))))))
(is (== 80 (int (* 100 (:crossover p1)))))
(is (== 0 (int (* 100 (:crossover p2)))))
(is (== 100 (int (* 100 (:crossover p3))))))))

(deftest test-elitism
(testing "elitism property"
(let [p1 (population/generate 1024 0.8 0.1 0.05)
p2 (population/generate 1024 0.8 0.0 0.05)
p3 (population/generate 1024 0.8 0.99 0.05)]
(is (= 10 (int (* 100 (:elitism p1)))))
(is (= 0 (int (* 100 (:elitism p2)))))
(is (= 99 (int (* 100 (:elitism p3))))))))
(is (== 10 (int (* 100 (:elitism p1)))))
(is (== 0 (int (* 100 (:elitism p2)))))
(is (== 99 (int (* 100 (:elitism p3))))))))

(deftest test-mutation
(testing "mutation property"
(let [p1 (population/generate 1024 0.8 0.1 0.05)
p2 (population/generate 1024 0.8 0.1 0.0)
p3 (population/generate 1024 0.8 0.1 1.0)]
(is (= 5 (int (* 100 (:mutation p1)))))
(is (= 0 (int (* 100 (:mutation p2)))))
(is (= 100 (int (* 100 (:mutation p3))))))))
(is (== 5 (int (* 100 (:mutation p1)))))
(is (== 0 (int (* 100 (:mutation p2)))))
(is (== 100 (int (* 100 (:mutation p3))))))))

(deftest test-population
(testing "population property"
(let [p (population/generate 1024 0.8 0.1 0.5)
c (vec (sort-by #(:fitness %) (:population p)))]
(testing "population size"
(is (= 1024 (count (:population p))))
(is (= 1024 (count c))))
(is (== 1024 (count (:population p))))
(is (== 1024 (count c))))
(testing "The population is actually sorted"
(loop [idx (int 0)]
(when (< (count c) idx)
Expand All @@ -71,10 +71,10 @@
p2 (population/evolve p1)
elitism (int (Math/round (* (count (:population p1)) (:elitism p1))))]
(testing "to ensure the population properties were carried through an evolution"
(is (= (:crossover p1) (:crossover p2)))
(is (= (:elitism p1) (:elitism p2)))
(is (= (:mutation p1) (:mutation p2)))
(is (= (count (:population p1)) (count (:population p2)))))
(is (== (:crossover p1) (:crossover p2)))
(is (== (:elitism p1) (:elitism p2)))
(is (== (:mutation p1) (:mutation p2)))
(is (== (count (:population p1)) (count (:population p2)))))
(testing "to ensure the proper elitism took place"
;; Store the values for p2 into a map
(let [elitism-map (zipmap (:population p2) (repeat (count (:population p2)) 1))]
Expand Down

0 comments on commit b64d54b

Please sign in to comment.