Skip to content
GitLab
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
eff6caba
Commit
eff6caba
authored
Mar 08, 2019
by
Hans-Peter Deifel
Browse files
tests: Add tests for SumBag
parent
9627b877
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
copar.cabal
View file @
eff6caba
...
...
@@ -136,6 +136,7 @@ test-suite spec
, Data.OpenUnionSpec
, Data.List.UtilsSpec
, Data.Float.UtilsSpec
, Data.SumBagSpec
, Copar.Functors.PowersetSpec
, Copar.Functors.GroupValuedSpec
, Copar.Functors.BagSpec
...
...
tests/Data/SumBagSpec.hs
0 → 100644
View file @
eff6caba
module
Data.SumBagSpec
(
spec
)
where
import
Test.Hspec
import
Data.Monoid
(
Sum
(
..
)
)
import
Data.Coerce
import
qualified
Data.SumBag
as
SumBag
spec
::
Spec
spec
=
do
insertSpec
deleteSpec
sumSpec
insertSpec
::
Spec
insertSpec
=
describe
"insert"
$
do
it
"works with one element"
$
do
SumBag
.
elem
(
si
1
)
(
SumBag
.
insert
(
si
1
)
SumBag
.
empty
)
`
shouldBe
`
True
it
"can handle 100 elements in order"
$
let
bag
=
foldr
SumBag
.
insert
SumBag
.
empty
(
map
si
[
1
..
100
])
in
and
(
map
(
flip
SumBag
.
elem
bag
)
(
coerce
@
[
Int
]
[
1
..
100
]))
`
shouldBe
`
True
it
"can handle 100 elements in reverse order"
$
let
bag
=
foldr
SumBag
.
insert
SumBag
.
empty
(
reverse
$
map
si
[
1
..
100
])
in
and
(
map
(
flip
SumBag
.
elem
bag
)
(
coerce
@
[
Int
]
[
1
..
100
]))
`
shouldBe
`
True
it
"can handle 100 elements in strange order"
$
let
bag
=
foldr
SumBag
.
insert
SumBag
.
empty
(
map
si
([
1
..
50
]
++
[
100
,
99
..
51
]))
in
and
(
map
(
flip
SumBag
.
elem
bag
)
(
coerce
@
[
Int
]
[
1
..
100
]))
`
shouldBe
`
True
it
"works with duplicate elements"
$
let
bag
=
iterate
(
SumBag
.
insert
(
si
1
))
SumBag
.
empty
!!
10
in
SumBag
.
toAscList
bag
`
shouldBe
`
(
replicate
10
(
si
1
))
deleteSpec
::
Spec
deleteSpec
=
describe
"delete"
$
do
it
"does nothing on the empty List"
$
SumBag
.
delete
(
si
1
)
SumBag
.
empty
`
shouldBe
`
SumBag
.
empty
it
"does nothing when the element is not there"
$
let
bag
=
SumBag
.
fromList
(
coerce
@
[
Int
]
[
2
..
10
])
in
SumBag
.
delete
(
si
1
)
bag
`
shouldBe
`
bag
it
"deletes a single element"
$
SumBag
.
delete
(
si
1
)
(
SumBag
.
singleton
(
si
1
))
`
shouldBe
`
SumBag
.
empty
it
"deletes multiple different elements"
$
let
bag
=
SumBag
.
fromList
(
coerce
@
[
Int
]
[
1
..
100
])
in
foldr
SumBag
.
delete
bag
(
map
si
[
1
..
50
])
`
shouldBe
`
SumBag
.
fromList
(
map
si
[
51
..
100
])
it
"deletes multiple equal elements"
$
let
bag
=
SumBag
.
fromList
(
replicate
100
(
si
1
))
in
foldr
SumBag
.
delete
bag
(
replicate
50
(
si
1
))
`
shouldBe
`
SumBag
.
fromList
(
replicate
50
(
si
1
))
sumSpec
::
Spec
sumSpec
=
describe
"sum"
$
do
it
"sums the empty bag to mempty"
$
SumBag
.
sum
@
(
Sum
Int
)
(
SumBag
.
empty
)
`
shouldBe
`
mempty
it
"computes the correct sum of [1..100]"
$
SumBag
.
sum
(
SumBag
.
fromList
(
map
si
[
1
..
100
]))
`
shouldBe
`
Sum
5050
it
"computes the correct sum of one hunderd twos"
$
SumBag
.
sum
(
SumBag
.
fromList
(
replicate
100
(
si
2
)))
`
shouldBe
`
Sum
200
si
::
Int
->
Sum
Int
si
=
Sum
@
Int
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment