DIR : /home/kozerus/public_html/dgs/scripts/tests/PoolSlicerTest.php

/home/kozerus/public_html/dgs/scripts/tests

<?php
/*
Dragon Go Server
Copyright (C) 2001-  Erik Ouchterlony, Jens-Uwe Gaspar

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/* Author: Jens-Uwe Gaspar */

require_once 'DgsUnitTest.php';
require_once 'tournaments/include/tournament_pool_classes.php';

define('TST_POOL_COUNT', 4);
define('TST_POOL_SIZE', 5);
define('TST_CNT_TP',  17);


/**
 * Test class for distribute user into pools with different slice-modes.
 */
class PoolSlicerTest extends DgsUnitTest {

   public function test_pool_slicer_snake() {
      $pc = new PoolSlicer( TROUND_SLICE_SNAKE, TST_POOL_COUNT, TST_POOL_SIZE );

      $chk = $this->_seed_pools( $pc );
      $this->assertEquals( '1,2,3,4,4,3,2,1,1,2,3,4,4,3,2,1,1', join(',', $chk));
      $this->assertEquals( TST_POOL_COUNT, $pc->count_visited_pools());
   }

   public function test_pool_slicer_round_robin() {
      $pc = new PoolSlicer( TROUND_SLICE_ROUND_ROBIN, TST_POOL_COUNT, TST_POOL_SIZE );

      $chk = $this->_seed_pools( $pc );
      $this->assertEquals( '1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1', join(',', $chk));
      $this->assertEquals( TST_POOL_COUNT, $pc->count_visited_pools());
   }

   public function test_pool_fillup_pools() {
      $pc = new PoolSlicer( TROUND_SLICE_FILLUP_POOLS, TST_POOL_COUNT, TST_POOL_SIZE );

      $chk = $this->_seed_pools( $pc );
      $this->assertEquals( '1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4', join(',', $chk));
      $this->assertEquals( TST_POOL_COUNT, $pc->count_visited_pools());
   }

   public function test_pool_slicer_manual() {
      $pc = new PoolSlicer( TROUND_SLICE_MANUAL, TST_POOL_COUNT, TST_POOL_SIZE );

      $chk = $this->_seed_pools( $pc );
      $this->assertEquals( '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0', join(',', $chk));
      $this->assertEquals( 1, $pc->count_visited_pools());
   }

   public function test_pool_count_visited_pools() {
      $pc = new PoolSlicer( TROUND_SLICE_FILLUP_POOLS, TST_POOL_COUNT, TST_POOL_SIZE );

      $chk = $this->_seed_pools( $pc, TST_POOL_SIZE + 2 );
      $this->assertEquals( '1,1,1,1,1,2,2', join(',', $chk));
      $this->assertEquals( 2, $pc->count_visited_pools());
   }

   private function _seed_pools( PoolSlicer &$pc, $cnt=TST_CNT_TP )
   {
      $result = array();
      for ($i=0; $i < $cnt; $i++)
         $result[] = $pc->next_pool();
      return $result;
   }

}

?>
//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer