From 4facdd8a1a5f141b158acbe1959da3d10d4c8ce9 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 29 Nov 2023 17:40:38 -0600 Subject: implement parseGenome --- test/GenomeTest.hs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/GenomeTest.hs b/test/GenomeTest.hs index aa6d310..2222347 100644 --- a/test/GenomeTest.hs +++ b/test/GenomeTest.hs @@ -2,7 +2,8 @@ module GenomeTest (suite) where import Test.Tasty import Test.Tasty.HUnit -import Mind (NeuronIndex (..)) +import Mind (Edge (..), NeuronIndex (..)) +import qualified Mind as N (Network (..)) import Genome import System.Random import Data.Ix @@ -204,4 +205,30 @@ mutationTests = testGroup "mutations" $ [ Gene { source = Internal 0, sink = Internal 1, weight = 1.0 } , Gene { source = Internal 2, sink = Output 0, weight = 1.0 } ] + , testCase "parse genome into network" $ + let + genome = Genome + { numInput = 1 + , numInternal = 3 + , numOutput = 1 + , genes = + [ Gene { source = Input 0, sink = Internal 0, weight = 1.0 } + , Gene { source = Internal 0, sink = Internal 1, weight = 2.0 } + , Gene { source = Internal 1, sink = Internal 2, weight = 3.0 } + , Gene { source = Internal 2, sink = Output 0, weight = 4.0 } + ] + } + network = parseGenome genome + expected = N.Network + { N.numInput = 1 + , N.internalNeurons = + [ [ Edge (Input 0, 1.0) ] + , [ Edge (Internal 0, 2.0) ] + , [ Edge (Internal 1, 3.0) ] + ] + , N.outputNeurons = + [ [ Edge (Internal 2, 4.0) ] + ] + } + in network @?= expected ] -- cgit v1.2.1