Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
text
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
text
Commits
17ac55df
Commit
17ac55df
authored
11 years ago
by
bos
Browse files
Options
Downloads
Patches
Plain Diff
Improve Arbitrary instances
parent
54f61ef6
No related branches found
Branches containing commit
Tags
Version_0_1
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/Tests/QuickCheckUtils.hs
+15
-2
15 additions, 2 deletions
tests/Tests/QuickCheckUtils.hs
with
15 additions
and
2 deletions
tests/Tests/QuickCheckUtils.hs
+
15
−
2
View file @
17ac55df
...
...
@@ -58,10 +58,12 @@ instance Random I16 where
random
=
randomR
(
minBound
,
maxBound
)
instance
Arbitrary
I16
where
arbitrary
=
choose
(
minBound
,
maxBound
)
arbitrary
=
arbitrarySizedIntegral
shrink
=
shrinkIntegral
instance
Arbitrary
B
.
ByteString
where
arbitrary
=
B
.
pack
`
fmap
`
arbitrary
shrink
=
map
B
.
pack
.
shrink
.
B
.
unpack
#
if
!
MIN_VERSION_base
(
4
,
4
,
0
)
instance
Random
Word8
where
...
...
@@ -130,9 +132,11 @@ smallArbitrary = sized $ \n -> resize (smallish n) arbitrary
instance
Arbitrary
T
.
Text
where
arbitrary
=
T
.
pack
`
fmap
`
arbitrary
shrink
=
map
T
.
pack
.
shrink
.
T
.
unpack
instance
Arbitrary
TL
.
Text
where
arbitrary
=
(
TL
.
fromChunks
.
map
notEmpty
)
`
fmap
`
smallArbitrary
shrink
=
map
TL
.
pack
.
shrink
.
TL
.
unpack
newtype
NotEmpty
a
=
NotEmpty
{
notEmpty
::
a
}
deriving
(
Eq
,
Ord
)
...
...
@@ -145,15 +149,23 @@ instance Functor NotEmpty where
instance
Arbitrary
a
=>
Arbitrary
(
NotEmpty
[
a
])
where
arbitrary
=
sized
(
\
n
->
NotEmpty
`
fmap
`
(
choose
(
1
,
n
+
1
)
>>=
vector
))
shrink
=
shrinkNotEmpty
null
instance
Arbitrary
(
NotEmpty
T
.
Text
)
where
arbitrary
=
(
fmap
T
.
pack
)
`
fmap
`
arbitrary
shrink
=
shrinkNotEmpty
T
.
null
instance
Arbitrary
(
NotEmpty
TL
.
Text
)
where
arbitrary
=
(
fmap
TL
.
pack
)
`
fmap
`
arbitrary
shrink
=
shrinkNotEmpty
TL
.
null
instance
Arbitrary
(
NotEmpty
B
.
ByteString
)
where
arbitrary
=
(
fmap
B
.
pack
)
`
fmap
`
arbitrary
shrink
=
shrinkNotEmpty
B
.
null
shrinkNotEmpty
::
Arbitrary
a
=>
(
a
->
Bool
)
->
NotEmpty
a
->
[
NotEmpty
a
]
shrinkNotEmpty
isNull
(
NotEmpty
xs
)
=
[
NotEmpty
xs'
|
xs'
<-
shrink
xs
,
not
(
isNull
xs'
)
]
data
Small
=
S0
|
S1
|
S2
|
S3
|
S4
|
S5
|
S6
|
S7
|
S8
|
S9
|
S10
|
S11
|
S12
|
S13
|
S14
|
S15
...
...
@@ -194,7 +206,8 @@ instance Random Small where
random
=
randomR
(
minBound
,
maxBound
)
instance
Arbitrary
Small
where
arbitrary
=
choose
(
minBound
,
maxBound
)
arbitrary
=
arbitrarySizedIntegral
shrink
=
shrinkIntegral
integralRandomR
::
(
Integral
a
,
RandomGen
g
)
=>
(
a
,
a
)
->
g
->
(
a
,
g
)
integralRandomR
(
a
,
b
)
g
=
case
randomR
(
fromIntegral
a
::
Integer
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment