Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
Packages
text
Commits
74f55aa9
Commit
74f55aa9
authored
Dec 12, 2014
by
bos
Browse files
Further generalise the formatRealFloat tests (gh-105)
parent
5902ed0d
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/Tests/Properties.hs
View file @
74f55aa9
...
...
@@ -24,7 +24,7 @@ import Data.Text.Internal.Search (indices)
import
Data.Text.Lazy.Read
as
TL
import
Data.Text.Read
as
T
import
Data.Word
(
Word
,
Word8
,
Word16
,
Word32
,
Word64
)
import
Numeric
(
showGFloat
,
showHex
)
import
Numeric
(
showEFloat
,
showFFloat
,
showGFloat
,
showHex
)
import
Prelude
hiding
(
replicate
)
import
Test.Framework
(
Test
,
testGroup
)
import
Test.Framework.Providers.QuickCheck2
(
testProperty
)
...
...
@@ -779,14 +779,19 @@ tb_realfloat = (TB.toLazyText . TB.realFloat) `eq` (TL.pack . show)
tb_realfloat_float
(
a
::
Float
)
=
tb_realfloat
a
tb_realfloat_double
(
a
::
Double
)
=
tb_realfloat
a
tb_formatRealFloat_G
::
(
RealFloat
a
,
Show
a
)
=>
a
->
Precision
a
->
Property
tb_formatRealFloat_G
a
prec
=
TB
.
formatRealFloat
TB
.
Generic
p
a
===
TB
.
fromString
(
showGFloat
p
a
""
)
showFloat
::
(
RealFloat
a
)
=>
TB
.
FPFormat
->
Maybe
Int
->
a
->
ShowS
showFloat
TB
.
Exponent
=
showEFloat
showFloat
TB
.
Fixed
=
showFFloat
showFloat
TB
.
Generic
=
showGFloat
tb_formatRealFloat
::
(
RealFloat
a
,
Show
a
)
=>
a
->
TB
.
FPFormat
->
Precision
a
->
Property
tb_formatRealFloat
a
fmt
prec
=
TB
.
formatRealFloat
fmt
p
a
===
TB
.
fromString
(
showFloat
fmt
p
a
""
)
where
p
=
precision
a
prec
tb_formatRealFloat_
G_
float
(
a
::
Float
)
=
tb_formatRealFloat
_G
a
tb_formatRealFloat_
G_
double
(
a
::
Double
)
=
tb_formatRealFloat
_G
a
tb_formatRealFloat_float
(
a
::
Float
)
=
tb_formatRealFloat
a
tb_formatRealFloat_double
(
a
::
Double
)
=
tb_formatRealFloat
a
-- Reading.
...
...
@@ -1294,8 +1299,8 @@ tests =
testGroup
"realfloat"
[
testProperty
"tb_realfloat_double"
tb_realfloat_double
,
testProperty
"tb_realfloat_float"
tb_realfloat_float
,
testProperty
"tb_formatRealFloat_
G_
float"
tb_formatRealFloat_
G_
float
,
testProperty
"tb_formatRealFloat_
G_
double"
tb_formatRealFloat_
G_
double
testProperty
"tb_formatRealFloat_float"
tb_formatRealFloat_float
,
testProperty
"tb_formatRealFloat_double"
tb_formatRealFloat_double
],
testProperty
"tb_fromText"
tb_fromText
,
testProperty
"tb_singleton"
tb_singleton
...
...
tests/Tests/QuickCheckUtils.hs
View file @
74f55aa9
...
...
@@ -40,10 +40,11 @@ import Control.DeepSeq (NFData (..), deepseq)
import
Control.Exception
(
bracket
)
import
Data.String
(
IsString
,
fromString
)
import
Data.Text.Foreign
(
I16
)
import
Data.Text.Lazy.Builder.RealFloat
(
FPFormat
(
..
))
import
Data.Word
(
Word8
,
Word16
)
import
Debug.Trace
(
trace
)
import
System.Random
(
Random
(
..
),
RandomGen
)
import
Test.QuickCheck
hiding
(
Small
(
..
),
(
.&.
))
import
Test.QuickCheck
hiding
(
Fixed
(
..
),
Small
(
..
),
(
.&.
))
import
Test.QuickCheck.Monadic
(
assert
,
monadicIO
,
run
)
import
Test.QuickCheck.Unicode
(
string
)
import
Tests.Utils
...
...
@@ -266,6 +267,9 @@ eqP f g s w = eql "orig" (f s) (g t) &&
|
a
=^=
b
=
True
|
otherwise
=
trace
(
d
++
": "
++
show
a
++
" /= "
++
show
b
)
False
instance
Arbitrary
FPFormat
where
arbitrary
=
elements
[
Exponent
,
Fixed
,
Generic
]
newtype
Precision
a
=
Precision
(
Maybe
Int
)
deriving
(
Eq
,
Show
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment