Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
tests for aggregate method
Browse files Browse the repository at this point in the history
  • Loading branch information
friedo committed Dec 11, 2012
1 parent 2bc64db commit 4a2971c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion t/collection.t
Expand Up @@ -25,7 +25,7 @@ if ($@) {
plan skip_all => $@;
}
else {
plan tests => 137;
plan tests => 140;
}

my $db = $conn->get_database('test_database');
Expand Down Expand Up @@ -576,6 +576,24 @@ SKIP: {
$coll->drop;
}

# aggregate
{
$coll->batch_insert( [ { wanted => 1, score => 56 },
{ wanted => 1, score => 72 },
{ wanted => 1, score => 96 },
{ wanted => 1, score => 32 },
{ wanted => 1, score => 61 },
{ wanted => 1, score => 33 },
{ wanted => 0, score => 1000 } ] );

my $res = $coll->aggregate( [ { '$match' => { wanted => 1 } },
{ '$group' => { _id => 1, 'avgScore' => { '$avg' => '$score' } } } ] );

is( ref( $res ), ref [ ] );
ok $res->[0]{avgScore} < 59;
ok $res->[0]{avgScore} > 57;

}

END {
if ($conn) {
Expand Down

0 comments on commit 4a2971c

Please sign in to comment.