0822a8ac19d114197a04660f875149d862fcd171
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / HashRingTest.php
1 <?php
2
3 /**
4 * @group HashRing
5 */
6 class HashRingTest extends PHPUnit_Framework_TestCase {
7 /**
8 * @covers HashRing
9 */
10 public function testHashRing() {
11 $ring = new HashRing( [ 's1' => 1, 's2' => 1, 's3' => 2, 's4' => 2, 's5' => 2, 's6' => 3 ] );
12
13 $locations = [];
14 for ( $i = 0; $i < 20; $i++ ) {
15 $locations[ "hello$i"] = $ring->getLocation( "hello$i" );
16 }
17 $expectedLocations = [
18 "hello0" => "s5",
19 "hello1" => "s6",
20 "hello2" => "s2",
21 "hello3" => "s5",
22 "hello4" => "s6",
23 "hello5" => "s4",
24 "hello6" => "s5",
25 "hello7" => "s4",
26 "hello8" => "s5",
27 "hello9" => "s5",
28 "hello10" => "s3",
29 "hello11" => "s6",
30 "hello12" => "s1",
31 "hello13" => "s3",
32 "hello14" => "s3",
33 "hello15" => "s5",
34 "hello16" => "s4",
35 "hello17" => "s6",
36 "hello18" => "s6",
37 "hello19" => "s3"
38 ];
39
40 $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' );
41
42 $locations = [];
43 for ( $i = 0; $i < 5; $i++ ) {
44 $locations[ "hello$i"] = $ring->getLocations( "hello$i", 2 );
45 }
46
47 $expectedLocations = [
48 "hello0" => [ "s5", "s6" ],
49 "hello1" => [ "s6", "s4" ],
50 "hello2" => [ "s2", "s1" ],
51 "hello3" => [ "s5", "s6" ],
52 "hello4" => [ "s6", "s4" ],
53 ];
54 $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' );
55 }
56 }