Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Informatik 8
CoPaR
Commits
83deb7b6
Commit
83deb7b6
authored
Oct 20, 2018
by
Hans-Peter Deifel
Browse files
Clean up code in MonoidValuedSpec
parent
cbcde80a
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/MA/Functors/MonoidValuedSpec.hs
View file @
83deb7b6
...
...
@@ -5,83 +5,74 @@ import Test.Hspec.Megaparsec
import
Data.Complex
import
qualified
Data.Vector
as
V
import
Data.Text
(
Text
)
import
qualified
Data.Vector
as
V
import
Data.Text
(
Text
)
import
MA.Functors.MonoidValued
import
Data.MorphismEncoding
(
Encoding
)
import
qualified
Data.MorphismEncoding
as
Encoding
import
Data.MorphismEncoding
(
Encoding
)
import
qualified
Data.MorphismEncoding
as
Encoding
import
MA.Coalgebra.Parser
import
MA.FunctorExpression.Type
import
MA.FunctorExpression.Sorts
(
Sorted
(
..
))
import
MA.FunctorExpression.Sorts
(
Sorted
(
..
)
)
import
Data.AFloat
import
MA.Parser.Types
import
MA.Coalgebra.RefinementTypes
spec
::
Spec
spec
=
do
parseMorphismPointIntSpec
parseMorphismPointDoubleSpec
parseMorphismPointComplexSpec
parseMorphismPointIntSpec
::
Spec
parseMorphismPointIntSpec
=
describe
"parseMorphismPoint (Int)"
$
do
it
"parses an empty successor list"
$
(
snd
<$>
parseMorphisms
(
Functor
1
(
MonoidValued
@
Int
Variable
))
""
"x: {}"
)
`
shouldParse
`
(
encoding
[(
Sorted
1
0
)]
[]
)
let
p
=
fmap
snd
.
parseMorphisms
(
Functor
1
(
MonoidValued
@
Int
Variable
))
""
it
"parses an empty successor list"
$
p
"x: {}"
`
shouldParse
`
encoding
[(
Sorted
1
0
)]
[]
it
"parses a simple example"
$
(
snd
<$>
parseMorphisms
(
Functor
1
(
MonoidValued
@
Int
Variable
))
""
"x: {x: 2, y: 3}
\n
y: {}"
)
`
shouldParse
`
(
encoding
[(
Sorted
1
5
),
(
Sorted
1
0
)]
[(
0
,
(
Sorted
1
2
),
0
),
(
0
,
(
Sorted
1
3
),
1
)])
it
"parses a simple example"
$
p
"x: {x: 2, y: 3}
\n
y: {}"
`
shouldParse
`
encoding
[(
Sorted
1
5
),
(
Sorted
1
0
)]
[(
0
,
(
Sorted
1
2
),
0
),
(
0
,
(
Sorted
1
3
),
1
)]
it
"fails on duplicate edges"
$
parseMorphisms
(
Functor
1
(
MonoidValued
@
Int
Variable
))
""
`
shouldFailOn
`
"x: {x: 2, x: 3}"
it
"fails on duplicate edges"
$
p
`
shouldFailOn
`
"x: {x: 2, x: 3}"
it
"works with negative numbers"
$
p
`
shouldSucceedOn
`
"x: {x: -2}"
it
"works with negative numbers"
$
parseMorphisms
(
Functor
1
(
MonoidValued
@
Int
Variable
))
""
`
shouldSucceedOn
`
"x: {x: -2}"
parseMorphismPointDoubleSpec
::
Spec
parseMorphismPointDoubleSpec
=
describe
"parseMorphismPoint (Double)"
$
do
it
"parses an empty successor list"
$
(
snd
<$>
parseMorphisms
(
Functor
1
(
MonoidValued
@
ADouble
Variable
))
""
"x: {}"
)
`
shouldParse
`
(
encoding
[(
Sorted
1
0
)]
[]
)
let
p
=
fmap
snd
.
parseMorphisms
(
Functor
1
(
MonoidValued
@
ADouble
Variable
))
""
it
"parses a simple example"
$
(
snd
<$>
parseMorphisms
(
Functor
1
(
MonoidValued
@
ADouble
Variable
))
""
"x: {x: 0.5, y: 3.7}
\n
y: {}"
)
`
shouldParse
`
(
encoding
[(
Sorted
1
4.2
),
(
Sorted
1
0
)]
[(
0
,
(
Sorted
1
0.5
),
0
),
(
0
,
(
Sorted
1
3.7
),
1
)])
it
"parses an empty successor list"
$
p
"x: {}"
`
shouldParse
`
encoding
[(
Sorted
1
0
)]
[]
it
"parses a simple example"
$
p
"x: {x: 0.5, y: 3.7}
\n
y: {}"
`
shouldParse
`
encoding
[(
Sorted
1
4.2
),
(
Sorted
1
0
)]
[(
0
,
(
Sorted
1
0.5
),
0
),
(
0
,
(
Sorted
1
3.7
),
1
)]
it
"fails on duplicate edges"
$
parseMorphisms
(
Functor
1
(
MonoidValued
@
ADouble
Variable
))
""
`
shouldFailOn
`
"x: {x: 0.5, x: 3.7}"
it
"fails on duplicate edges"
$
p
`
shouldFailOn
`
"x: {x: 0.5, x: 3.7}"
it
"works with negative numbers"
$
parseMorphisms
(
Functor
1
(
MonoidValued
@
ADouble
Variable
))
""
`
shouldSucceedOn
`
"x: {x: -2.3}"
it
"works with negative numbers"
$
p
`
shouldSucceedOn
`
"x: {x: -2.3}"
parseMorphismPointComplexSpec
::
Spec
parseMorphismPointComplexSpec
=
describe
"parseMorphismPoint (Complex)"
$
do
let
p
::
Text
->
Either
ParseErr
(
Encoding
(
Sorted
OrderedComplex
)
(
Sorted
OrderedComplex
))
p
=
fmap
snd
.
parseMorphisms
let
p
=
fmap
snd
.
parseMorphisms
(
Functor
1
(
MonoidValued
@
OrderedComplex
Variable
))
""
it
"parses an empty successor list"
$
p
"x: {}"
`
shouldParse
`
(
encoding
[(
Sorted
1
0
)]
[]
)
`
shouldParse
`
encoding
[(
Sorted
1
0
)]
[]
it
"parses a simple example with only real parts"
$
p
"x: {x: 0.5, y: 3.7}
\n
y: {}"
...
...
@@ -116,5 +107,4 @@ parseMorphismPointComplexSpec = describe "parseMorphismPoint (Complex)" $ do
-- FIXME: Remove duplicate definition of this function
encoding
::
[
h1
]
->
[(
Int
,
l
,
Int
)]
->
Encoding
l
h1
encoding
h1
es
=
Encoding
.
new
(
V
.
fromList
h1
)
(
V
.
fromList
(
map
toEdge
es
))
where
toEdge
(
from
,
lab
,
to
)
=
Encoding
.
Edge
from
lab
to
where
toEdge
(
from
,
lab
,
to
)
=
Encoding
.
Edge
from
lab
to
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