Test suite: added ZUNION.

This commit is contained in:
Daniele Alessandri
2010-04-24 10:21:29 +02:00
parent fa039fe500
commit a1c8568ccf
+52
View File
@@ -1188,6 +1188,58 @@ class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
});
}
function testZsetUnion() {
$zsetA = RC::zsetAddAndReturn($this->redis, 'zseta', array('a' => 1, 'b' => 2, 'c' => 3));
$zsetB = RC::zsetAddAndReturn($this->redis, 'zsetb', array('b' => 1, 'c' => 2, 'd' => 3));
// basic ZUNION
$this->assertEquals(4, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetb'));
$this->assertEquals(
array(array('a', 1), array('b', 3), array('d', 3), array('c', 5)),
$this->redis->zrange('zsetc', 0, -1, 'withscores')
);
$this->assertEquals(3, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetbNull'));
$this->assertEquals(
array(array('a', 1), array('b', 2), array('c', 3)),
$this->redis->zrange('zsetc', 0, -1, 'withscores')
);
$this->assertEquals(3, $this->redis->zunion('zsetc', 2, 'zsetaNull', 'zsetb'));
$this->assertEquals(
array(array('b', 1), array('c', 2), array('d', 3)),
$this->redis->zrange('zsetc', 0, -1, 'withscores')
);
$this->assertEquals(0, $this->redis->zunion('zsetc', 2, 'zsetaNull', 'zsetbNull'));
// with WEIGHTS
$this->assertEquals(4, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetb', 'WEIGHTS', 2, 3));
$this->assertEquals(
array(array('a', 2), array('b', 7), array('d', 9), array('c', 12)),
$this->redis->zrange('zsetc', 0, -1, 'withscores')
);
// with AGGREGATE (min)
$this->assertEquals(4, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetb', 'AGGREGATE', 'MIN'));
$this->assertEquals(
array(array('a', 1), array('b', 1), array('c', 2), array('d', 3)),
$this->redis->zrange('zsetc', 0, -1, 'withscores')
);
// with AGGREGATE (max)
$this->assertEquals(4, $this->redis->zunion('zsetc', 2, 'zseta', 'zsetb', 'AGGREGATE', 'MAX'));
$this->assertEquals(
array(array('a', 1), array('b', 2), array('c', 3), array('d', 3)),
$this->redis->zrange('zsetc', 0, -1, 'withscores')
);
RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function($test) {
$test->redis->set('zsetFake', 'fake');
$test->redis->zunion('zsetc', 2, 'zseta', 'zsetFake');
});
}
function testZsetCount() {
$zset = RC::zsetAddAndReturn($this->redis, 'zset', RC::getZSetArray());