diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/GenomeTest.hs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/GenomeTest.hs b/test/GenomeTest.hs index 56499a1..8448133 100644 --- a/test/GenomeTest.hs +++ b/test/GenomeTest.hs @@ -95,4 +95,54 @@ mutationTests = testGroup "mutations" $ (numInternal genome') @?= (1 + numInternal genome) (numOutput genome') @?= (numOutput genome) (genes genome') @?= (genes genome) + , testCase "remove internal neuron" $ + let + r = mkStdGen 1 -- randomR (0, 2) produces (1, 2, 0, ...) + genome = Genome + { numInput = 1 + , numInternal = 3 + , 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.Internal 2, weight = 1.0 } + , Gene { source = M.Internal 2, sink = M.Output 0, weight = 1.0 } + ] + } + (genome', r') = mutateGenomeRemoveInternal genome r + (genome'', r'') = mutateGenomeRemoveInternal genome r' + (genome''', _) = mutateGenomeRemoveInternal genome r'' + in do + (numInput genome') @?= (numInput genome) + (numInput genome'') @?= (numInput genome) + (numInput genome''') @?= (numInput genome) + + (numInternal genome') @?= (numInternal genome - 1) + (numInternal genome'') @?= (numInternal genome - 1) + (numInternal genome''') @?= (numInternal genome - 1) + + (numOutput genome') @?= (numOutput genome) + (numOutput genome'') @?= (numOutput genome) + (numOutput genome''') @?= (numOutput genome) + + (genes genome') @?= + [ 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 0, sink = M.Internal 1, weight = 1.0 } + , Gene { source = M.Internal 1, sink = M.Output 0, weight = 1.0 } + ] + + (genes genome'') @?= + [ 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 } + , Gene { source = M.Internal 1, sink = M.Output 0, weight = 1.0 } + ] + + (genes genome''') @?= + [ Gene { source = M.Input 0, sink = M.Internal 0, weight = 1.0 } + , 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 } + ] ] |