<commit_before>module Data.Hash.SL2.Test where

import Data.Word
import Data.Hash.SL2.Internal
import qualified Data.ByteString as B

import Foreign.ForeignPtr
import Foreign.Storable

import Test.QuickCheck
import Test.QuickCheck.All
import Test.QuickCheck.Property.Monoid

import Distribution.TestSuite.QuickCheck

import Data.Monoid

instance Arbitrary B.ByteString where
  arbitrary = fmap B.pack arbitrary

instance Arbitrary Hash where
  arbitrary = fmap fromBytes $ mapM choose (take 64 $ cycle $ replicate 15 (0, 255) ++ [(0, 127)])

tests :: IO [Test]
tests = return

  [ testProperty "Monoid" $
      eq $ prop_Monoid (T :: T Hash)

  , testGroup "append"

    [ testGroup "single string" $

      [ testProperty "equal to ((. hash) . (<>))" $
          \a b -> ((. hash) . (<>)) a b == a <+ b
      ]

    , testGroup "multiple strings" $

      [ testProperty "equal to (foldl (<+))" $
          \a b -> (foldl (<+)) a b == a <| b
      ]

    ]

  , testGroup "prepend"

    [ testGroup "single string" $

      [ testProperty "equal to ((<>) . hash)" $<commit_msg>add distributive test<commit_after>module Data.Hash.SL2.Test where

import Data.Word
import Data.Hash.SL2.Internal
import qualified Data.ByteString as B

import Foreign.ForeignPtr
import Foreign.Storable

import Test.QuickCheck
import Test.QuickCheck.All
import Test.QuickCheck.Property.Monoid

import Distribution.TestSuite.QuickCheck

import Data.Monoid

instance Arbitrary B.ByteString where
  arbitrary = fmap B.pack arbitrary

instance Arbitrary Hash where
  arbitrary = fmap fromBytes $ mapM choose (take 64 $ cycle $ replicate 15 (0, 255) ++ [(0, 127)])

tests :: IO [Test]
tests = return

  [ testGroup "composition"

    [ testProperty "forms a monoid" $
        eq $ prop_Monoid (T :: T Hash)

    , testProperty "is distributive" $
        \a b -> hash (a <> b) == hash a <> hash b

    ]

  , testGroup "append"

    [ testGroup "single string" $

      [ testProperty "equal to ((. hash) . (<>))" $
          \a b -> ((. hash) . (<>)) a b == a <+ b
      ]

    , testGroup "multiple strings" $

      [ testProperty "equal to (foldl (<+))" $
          \a b -> (foldl (<+)) a b == a <| b
      ]

    ]

  , testGroup "prepend"

    [ testGroup "single string" $

      [ testProperty "equal to ((<>) . hash)" $
{'fraction_non_alphanumeric': 0.13075586446568202, 'fraction_numerical': 0.01216333622936577, 'mean_word_length': 2.7878289473684212, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 16, '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': '2852124', 'n_tokens_mistral': 782, 'n_tokens_neox': 726, 'n_words': 224}