<commit_before>{-# OPTIONS_GHC -fno-warn-orphans #-}

module UnitTests.GenesSpec (spec, DnaString, Basis) where

import Test.Hspec
import Test.QuickCheck
import Data.List

import Genes
import ListUtils

instance Arbitrary Basis where
  arbitrary =
       elements [ G1
                , G2
                , G3
                ]

instance Arbitrary DnaString where
     arbitrary = DnaString <$> vector 10

newtype PointInString = PointInString Int deriving Show
instance Arbitrary PointInString  where
     arbitrary = PointInString <$> elements [0..11]

newtype IndexInString = IndexInString Int deriving Show
instance Arbitrary IndexInString  where
     arbitrary = IndexInString <$> elements [0..9]

spec :: Spec
spec = parallel $
    describe "Genes" $ do

        it "show DNA string looks like '[12213]'" $
            show (DnaString [G1, G2, G2, G1, G3]) `shouldBe` "[12213]"

        it "length of crosovered dna is the same as the mother dnas" $
            property ( \(DnaString dna1) (DnaString dna2)  ->
                length dna1
                    ==
                length (genes $ crossover 4 (DnaString dna1) (DnaString dna2))
            )

        it "beginning of crosovered DNA is from the first mother string" $
            property ( \(PointInString n) (DnaString dna1) (DnaString dna2)  ->
                take n dna1
                    ==
                take n (genes $ crossover n (DnaString dna1) (DnaString dna2))
            )

        it "end of crosovered DNA is from the second mother string" $
            property ( \(PointInString n) (DnaString dna1) (DnaString dna2)  ->
                drop n dna2<commit_msg>minot: add test for Ord of DNA<commit_after>{-# OPTIONS_GHC -fno-warn-orphans #-}

module UnitTests.GenesSpec (spec, DnaString, Basis) where

import Test.Hspec
import Test.QuickCheck
import Data.List

import Genes
import ListUtils

instance Arbitrary Basis where
  arbitrary =
       elements [ G1
                , G2
                , G3
                ]

instance Arbitrary DnaString where
     arbitrary = DnaString <$> vector 10

newtype PointInString = PointInString Int deriving Show
instance Arbitrary PointInString  where
     arbitrary = PointInString <$> elements [0..11]

newtype IndexInString = IndexInString Int deriving Show
instance Arbitrary IndexInString  where
     arbitrary = IndexInString <$> elements [0..9]

spec :: Spec
spec = parallel $
    describe "Genes" $ do

        it "show DNA string looks like '[12213]'" $
            show (DnaString [G1, G2, G2, G1, G3]) `shouldBe` "[12213]"

        it "show DNA strings are lexicographicaly ordered" $
            DnaString [G1, G2, G2, G1, G3] `compare` DnaString [G1, G2, G3, G1, G3]
                `shouldBe`
            LT

        it "length of crosovered dna is the same as the mother dnas" $
            property ( \(DnaString dna1) (DnaString dna2)  ->
                length dna1
                    ==
                length (genes $ crossover 4 (DnaString dna1) (DnaString dna2))
            )

        it "beginning of crosovered DNA is from the first mother string" $
            property ( \(PointInString n) (DnaString dna1) (DnaString dna2)  ->
                take n dna1
                    ==
                take n (genes $ crossover n (DnaString dna1) (DnaString dna2))
            )

        it "end of crosovered DNA is from the second mother string" $
            property ( \(PointInString n) (DnaString dna1) (DnaString dna2)  ->
                drop n dna2
{'fraction_non_alphanumeric': 0.08088863571632014, 'fraction_numerical': 0.025064084306465395, 'mean_word_length': 2.061900610287707, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3858', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1051, 'n_words': 357}