Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
ensembl-gh-mirror
ensembl
Commits
8fe132b5
Commit
8fe132b5
authored
14 years ago
by
Graham Ritchie
Browse files
Options
Downloads
Patches
Plain Diff
adding tests for Iterators
parent
f9cf86fd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/t/iterator.t
+95
-0
95 additions, 0 deletions
modules/t/iterator.t
with
95 additions
and
0 deletions
modules/t/iterator.t
0 → 100644
+
95
−
0
View file @
8fe132b5
use
strict
;
use
warnings
;
use
Test::
More
;
BEGIN
{
use_ok
('
Bio::EnsEMBL::Utils::Iterator
');
}
sub
it_from_list
{
my
@list
=
@_
;
return
Bio::EnsEMBL::Utils::
Iterator
->
new
(
sub
{
return
shift
@list
;
});
}
my
(
$it
,
$num
,
$i
);
$it
=
it_from_list
(
1
,
2
,
3
);
ok
(
$it
->
has_next
,
'
iterator still has elements
');
$i
=
0
;
while
(
$num
=
$it
->
next
)
{
is
(
$num
,
++
$i
,
'
got right element
');
}
is
(
$i
,
3
,
'
got right number of elements
');
# test empty iterator
my
$empty_it
=
Bio::EnsEMBL::Utils::
Iterator
->
new
;
ok
(
!
$empty_it
->
has_next
,
'
empty iterator has no elements
');
# test grepping and mapping
$it
=
it_from_list
(
1
,
2
,
3
,
4
);
my
$even_it
=
$it
->
grep
(
sub
{
$_
%
2
==
0
});
$i
=
0
;
while
(
$num
=
$even_it
->
next
)
{
$i
++
;
ok
(
$num
%
2
==
0
,
"
$num
is even
");
}
is
(
$i
,
2
,
'
got right number of grepped elements back
');
$it
=
it_from_list
(
1
,
2
,
3
);
my
$doubled_it
=
$it
->
map
(
sub
{
$_
*
2
});
$i
=
0
;
while
(
$num
=
$doubled_it
->
next
)
{
is
(
$num
,
++
$i
*
2
,
"
$num
=
$i
* 2
");
}
is
(
$i
,
3
,
'
got right number of mapped elements back
');
# test combining iterators
$it
=
it_from_list
(
1
,
2
,
3
);
$empty_it
=
Bio::EnsEMBL::Utils::
Iterator
->
new
;
my
$it2
=
it_from_list
(
4
,
5
,
6
);
my
$combined_it
=
$it
->
append
(
$empty_it
,
$it2
);
$i
=
0
;
while
(
$num
=
$combined_it
->
next
)
{
$i
++
;
}
is
(
$i
,
6
,
'
got right number of elements from combined iterators
');
$it
=
it_from_list
(
1
,
2
,
3
);
my
$el
=
$it
->
peek
;
is
(
$el
,
$it
->
next
,
'
peek did not remove element
');
# test converting iterator to an arrayref
$it
=
it_from_list
(
1
,
2
,
3
);
is_deeply
(
$it
->
to_arrayref
,
[
1
,
2
,
3
],
'
got correct array back
');
done_testing
();
This diff is collapsed.
Click to expand it.
Preview
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!
Save comment
Cancel
Please
register
or
sign in
to comment