From 62a04f27ecbaf714c08fa0594566da83581f7a97 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 29 Nov 2023 12:41:09 -0600 Subject: implement mutateGenomeAddInternal --- test/GenomeTest.hs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'test') 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) ] -- cgit v1.2.1