<commit_before>{-# Language TypeSynonymInstances #-}
{-# Language FlexibleInstances #-}
{-# Language OverloadedStrings #-}
module Unison.Test.Index where

import Control.Concurrent.STM (atomically)
import Data.ByteString.Char8
import System.Random
import Test.QuickCheck
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.QuickCheck
import Unison.Runtime.Address
import Unison.Test.BlockStore (makeRandomAddress)
import qualified Control.Concurrent.MVar as MVar
import qualified Data.ByteString as B
import qualified Unison.BlockStore as BS
import qualified Unison.BlockStore.MemBlockStore as MBS
import qualified Unison.Cryptography as C
import qualified Unison.Runtime.Index as Index

instance Arbitrary Index.Identifier where
  arbitrary = do
    a <- (BS.Series . B.pack) <$> vectorOf 64 arbitrary
    b <- (BS.Series . B.pack) <$> vectorOf 64 arbitrary
    pure (a, b)

makeRandomId :: IO (BS.Series, BS.Series)
makeRandomId = do
  cp <- BS.Series <$> C.randomBytes C.noop 64
  ud <- BS.Series <$> C.randomBytes C.noop 64
  pure (cp, ud)

roundTrip :: BS.BlockStore Address -> Assertion
roundTrip bs = do
  ident <- makeRandomId
  db <- Index.load bs ident
  atomically (Index.insert "keyhash" ("key", "value") db) >>= atomically
  db2 <- Index.load bs ident<commit_msg>clean up Arbitrary instances for testing<commit_after>{-# Language TypeSynonymInstances #-}
{-# Language OverloadedStrings #-}
module Unison.Test.Index where

import Control.Concurrent.STM (atomically)
import Data.ByteString.Char8
import System.Random
import Test.QuickCheck
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.QuickCheck
import Unison.Runtime.Address
import Unison.Test.BlockStore (makeRandomAddress)
import qualified Control.Concurrent.MVar as MVar
import qualified Data.ByteString as B
import qualified Unison.BlockStore as BS
import qualified Unison.BlockStore.MemBlockStore as MBS
import qualified Unison.Cryptography as C
import qualified Unison.Runtime.Index as Index

instance Arbitrary BS.Series where
    arbitrary =(BS.Series . B.pack) <$> vectorOf 64 arbitrary

makeRandomId :: IO (BS.Series, BS.Series)
makeRandomId = do
  cp <- BS.Series <$> C.randomBytes C.noop 64
  ud <- BS.Series <$> C.randomBytes C.noop 64
  pure (cp, ud)

roundTrip :: BS.BlockStore Address -> Assertion
roundTrip bs = do
  ident <- makeRandomId
  db <- Index.load bs ident
  atomically (Index.insert "keyhash" ("key", "value") db) >>= atomically
  db2 <- Index.load bs ident
{'fraction_non_alphanumeric': 0.09838056680161944, 'fraction_numerical': 0.0072874493927125505, 'mean_word_length': 4.527964205816555, 'pattern_counts': {'":': 0, '<': 22, '<?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': '5275494', 'n_tokens_mistral': 797, 'n_tokens_neox': 754, 'n_words': 239}