summaryrefslogtreecommitdiff
path: root/test/GenomeTest.hs
diff options
context:
space:
mode:
Diffstat (limited to 'test/GenomeTest.hs')
-rw-r--r--test/GenomeTest.hs34
1 files changed, 27 insertions, 7 deletions
diff --git a/test/GenomeTest.hs b/test/GenomeTest.hs
index a09e742..56499a1 100644
--- a/test/GenomeTest.hs
+++ b/test/GenomeTest.hs
@@ -63,16 +63,36 @@ mutationTests = testGroup "mutations" $
([], rand)
(replicate 3 sourceGene)
expected =
- [ Gene { source = M.Input 0, sink = M.Output 1, weight = 7.572357}
- , Gene { source = M.Input 0, sink = M.Output 1, weight = -1.4116564 }
- , Gene { source = M.Input 0, sink = M.Output 1, weight = -7.2413177 }
- ]
+ [ Gene { source = M.Input 0, sink = M.Output 1, weight = 7.572357}
+ , Gene { source = M.Input 0, sink = M.Output 1, weight = -1.4116564 }
+ , Gene { source = M.Input 0, sink = M.Output 1, weight = -7.2413177 }
+ ]
approxEqual a b = abs (a-b) < 0.0001
in do
(map source mutatedGenes) @?= (map source expected)
(map sink mutatedGenes) @?= (map sink expected)
True @?= foldl (&&) True (zipWith approxEqual
- (map weight mutatedGenes)
- (map weight expected)
- )
+ (map weight mutatedGenes)
+ (map weight expected)
+ )
+ , testCase "insert new internal neuron" $
+ let
+ genome = Genome
+ { numInput = 1
+ , numInternal = 2
+ , numOutput = 1
+ , genes =
+ [ Gene { source = M.Input 0, sink = M.Internal 0, weight = 1.0 }
+ , Gene { source = M.Internal 0, sink = M.Internal 1, weight = 1.0 }
+ , Gene { source = M.Internal 1, sink = M.Output 0, weight = 1.0 }
+ ]
+ }
+ r = mkStdGen 5
+ (genome', r') = mutateGenomeAddInternal genome r
+ in do
+ r' @?= r
+ (numInput genome') @?= (numInput genome)
+ (numInternal genome') @?= (1 + numInternal genome)
+ (numOutput genome') @?= (numOutput genome)
+ (genes genome') @?= (genes genome)
]