summaryrefslogtreecommitdiff
path: root/test/GenomeTest.hs
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-29 15:45:44 -0600
committersanine <sanine.not@pm.me>2023-11-29 15:45:44 -0600
commit3047e46f3478e20250556de833c1b6dd1b1a31f0 (patch)
treeab8bd56416a64ce1236d23e1bcdadd943d46832d /test/GenomeTest.hs
parent62a04f27ecbaf714c08fa0594566da83581f7a97 (diff)
imlement mutateGenomeRemoveNeuron
Diffstat (limited to 'test/GenomeTest.hs')
-rw-r--r--test/GenomeTest.hs50
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 }
+ ]
]