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