summaryrefslogtreecommitdiff
path: root/test/GenomeTest.hs
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-29 12:41:09 -0600
committersanine <sanine.not@pm.me>2023-11-29 12:41:09 -0600
commit62a04f27ecbaf714c08fa0594566da83581f7a97 (patch)
tree60b399143cd9137aa02816a6d5daf680c1beb153 /test/GenomeTest.hs
parentfa28b97de15b00946788f4f78cf932bc202f4811 (diff)
implement mutateGenomeAddInternal
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)
]