-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
module Test.QuickCheck.Data.AlphaNumString where | ||
|
||
import Prelude | ||
|
||
import Data.Int (fromNumber, toNumber) | ||
import Data.String (fromCharArray, length) | ||
import Data.String (fromCharArray, toCharArray, length) | ||
import Data.String.Unsafe (charAt) | ||
import Math (round) | ||
import Test.QuickCheck.Gen | ||
import Test.QuickCheck.Arbitrary | ||
|
||
-- | A newtype for `String` whose `Arbitrary` instance generated random | ||
-- | alphanumeric strings. | ||
newtype AlphaNumString = AlphaNumString String | ||
|
||
runAlphaNumString :: AlphaNumString -> String | ||
runAlphaNumString (AlphaNumString s) = s | ||
|
||
instance arbAlphaNumString :: Arbitrary AlphaNumString where | ||
arbitrary = do | ||
arrNum <- arbitrary | ||
return $ AlphaNumString <<< fromCharArray $ lookup <$> arrNum | ||
arbitrary = AlphaNumString <<< fromCharArray <$> arrayOf anyChar | ||
where | ||
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
lookup x = let index = fromNumber $ x * (toNumber (length chars) - 1) | ||
in charAt index chars | ||
|
||
rest :: Array Char | ||
rest = toCharArray "bcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
|
||
anyChar :: Gen Char | ||
anyChar = oneOf (pure 'a') (map pure rest) | ||
|
||
instance coarbAlphaNumString :: Coarbitrary AlphaNumString where | ||
coarbitrary (AlphaNumString s) = coarbitrary s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* global exports */ | ||
"use strict"; | ||
|
||
// module Test.QuickCheck.Gen | ||
|
||
exports.float32ToInt32 = function(n) { | ||
var arr = new ArrayBuffer(4); | ||
var fv = new Float32Array(arr); | ||
var iv = new Int32Array(arr); | ||
fv[0] = n; | ||
return iv[0]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.