Merge "Chinese Conversion Table Update 2017-6"
[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 use MediaWikiCoversValidator;
9
10 /**
11 * @covers HashRing
12 */
13 public function testHashRing() {
14 $ring = new HashRing( [ 's1' => 1, 's2' => 1, 's3' => 2, 's4' => 2, 's5' => 2, 's6' => 3 ] );
15
16 $locations = [];
17 for ( $i = 0; $i < 20; $i++ ) {
18 $locations[ "hello$i"] = $ring->getLocation( "hello$i" );
19 }
20 $expectedLocations = [
21 "hello0" => "s5",
22 "hello1" => "s6",
23 "hello2" => "s2",
24 "hello3" => "s5",
25 "hello4" => "s6",
26 "hello5" => "s4",
27 "hello6" => "s5",
28 "hello7" => "s4",
29 "hello8" => "s5",
30 "hello9" => "s5",
31 "hello10" => "s3",
32 "hello11" => "s6",
33 "hello12" => "s1",
34 "hello13" => "s3",
35 "hello14" => "s3",
36 "hello15" => "s5",
37 "hello16" => "s4",
38 "hello17" => "s6",
39 "hello18" => "s6",
40 "hello19" => "s3"
41 ];
42
43 $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' );
44
45 $locations = [];
46 for ( $i = 0; $i < 5; $i++ ) {
47 $locations[ "hello$i"] = $ring->getLocations( "hello$i", 2 );
48 }
49
50 $expectedLocations = [
51 "hello0" => [ "s5", "s6" ],
52 "hello1" => [ "s6", "s4" ],
53 "hello2" => [ "s2", "s1" ],
54 "hello3" => [ "s5", "s6" ],
55 "hello4" => [ "s6", "s4" ],
56 ];
57 $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' );
58 }
59 }