summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-21 10:35:07 -0600
committersanine <sanine.not@pm.me>2023-11-21 10:35:07 -0600
commit6ab486c73d4d5764ac7b63c46e04c361c776385b (patch)
tree4ad0cb1c89dda0ad195255b5610240ad351acb67
parentd128c42a96110eceb3a82ff26263388efff20623 (diff)
add createEmptyNetwork
-rw-r--r--src/Mind.hs27
-rw-r--r--test/MindTest.hs10
2 files changed, 32 insertions, 5 deletions
diff --git a/src/Mind.hs b/src/Mind.hs
index 02b98b1..45b90da 100644
--- a/src/Mind.hs
+++ b/src/Mind.hs
@@ -1,11 +1,30 @@
module Mind
( NeuronIndex (..)
, getNeuronIndex
+
+ , Edge (..)
+
+ , Network (..)
+ , createEmptyNetwork
) where
--- types
-data NeuronIndex = Input Int | Internal Int | Output Int
+-- index different neuron types
+data NeuronIndex = Input Int | Internal Int | Output Int deriving (Show, Eq)
+
getNeuronIndex :: NeuronIndex -> Int
-getNeuronIndex i = undefined
+getNeuronIndex (Input i) = i
+getNeuronIndex (Internal i) = i
+getNeuronIndex (Output i) = i
+
+-- define incident edges
+newtype Edge = Edge (NeuronIndex, Float) deriving (Show, Eq)
+
+-- define networks
+data Network = Network
+ { numInput :: Int
+ , internalNeurons :: [[Edge]]
+ , outputNeurons :: [[Edge]]
+ } deriving (Show, Eq)
-newtype Edge = Edge (NeuronIndex, Float)
+createEmptyNetwork :: Int -> Int -> Int -> Network
+createEmptyNetwork i h o = Network i (replicate h []) (replicate o [])
diff --git a/test/MindTest.hs b/test/MindTest.hs
index 227aa0c..5eb1734 100644
--- a/test/MindTest.hs
+++ b/test/MindTest.hs
@@ -2,15 +2,23 @@ module MindTest (suite) where
import Test.Tasty
import Test.Tasty.HUnit
-
import Mind
suite :: TestTree
suite = testGroup "mind tests" $
[ neuronIndexTests
+ , networkTests
]
neuronIndexTests :: TestTree
neuronIndexTests = testGroup "neuron index tests" $
[ testCase "get input index" $ getNeuronIndex (Input 4) @?= 4
+ , testCase "get internal index" $ getNeuronIndex (Internal 12) @?= 12
+ , testCase "get output index" $ getNeuronIndex (Output 0) @?= 0
+ ]
+
+networkTests :: TestTree
+networkTests = testGroup "network tests" $
+ [ testCase "create empty network" $
+ (createEmptyNetwork 3 2 1) @?= Network 3 [[], []] [[]]
]