From fa28b97de15b00946788f4f78cf932bc202f4811 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 29 Nov 2023 12:12:46 -0600 Subject: rewrite genome tests to use approximate float comparison --- test/GenomeTest.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/GenomeTest.hs b/test/GenomeTest.hs index 0a27a94..a09e742 100644 --- a/test/GenomeTest.hs +++ b/test/GenomeTest.hs @@ -62,11 +62,17 @@ mutationTests = testGroup "mutations" $ ) ([], rand) (replicate 3 sourceGene) - in - mutatedGenes @?= - [ 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.Internal 1, weight = -7.2413177 } - ] - + 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 } + ] + 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) + ) ] -- cgit v1.2.1