(function() {

  const gamestate = enhance({
    gameProgressiveId: 1,
    handProgressiveId: 1,
    players: [{
      id: 0,
      name: 'arale',
      status: playerStatus.active
    }, {
      id: 1,
      name: 'bender',
      status: playerStatus.active
    }, {
      id: 2,
      name: 'marvin',
      status: playerStatus.active
    }, {
      id: 3,
      name: 'wall-e',
      status: playerStatus.active
    }]
  });

  tcase([
    { description: 'handId=1, real loop', args: [ gamestate ] },
    { args: [ gamestate ] },
    { args: [ gamestate ] },
    { args: [ gamestate ] },
    { args: [ gamestate ] },
    { args: [ gamestate ] }
  ], function(gs) {

    sut(gs);

    const caseIndex = gs.handProgressiveId;
    const player = gs.players.find(player => player[hasDB]);


    gs.handProgressiveId++;

    const dbi = gs.initialDealerButtonIndex;
    const dbr = gs.dealerButtonRound;

    return dbi === 0 && player.id === (caseIndex-1)%4 && dbr === (caseIndex <= 4 ? 0 : 1);

  });

}());
tcase([
  { description: '(BLINDS_PERIOD=1)', args: [ 0 ], expectedResult: 10 },
  { args: [ 1 ], expectedResult: 20 },
  { args: [ 2 ], expectedResult: 25 },
  { args: [ 3 ], expectedResult: 50 },
  { args: [ 4 ], expectedResult: 100 },
  { args: [ 5 ], expectedResult: 125 },
  { args: [ 6 ], expectedResult: 200 },
  { args: [ 7 ], expectedResult: 250 },
  { args: [ 8 ], expectedResult: 500 },
  { args: [ 9 ], expectedResult: 750 },
  { args: [ 10 ], expectedResult: 1000 },
  { args: [ 11 ], expectedResult: 1000 },
  { args: [ 12 ], expectedResult: 1000 },
  { args: [ 42 ], expectedResult: 1000 }
], function(val) {

  // when config.BLINDS_PERIOD = 1
  // the blind should increase every time
  // the dealer button completes a loop around the table

  config.BLINDS_PERIOD = 1;
  gamestate.dealerButtonRound = val;

  sut(gamestate);

  return gamestate.sb;

});
(function() {

  const gamestate = enhance({
    gameProgressiveId: 2,
    handProgressiveId: 1,
    players: [{
      id: 0,
      name: 'arale',
      status: playerStatus.active
    }, {
      id: 1,
      name: 'bender',
      status: playerStatus.active
    }, {
      id: 2,
      name: 'marvin',
      status: playerStatus.out
    }, {
      id: 3,
      name: 'wall-e',
      status: playerStatus.active
    }]
  });

  const expectedDealerButtonId = [1,3,1,3,1,3];

  tcase([
    { description: 'handId=1, real loop, with out players', args: [ gamestate ] },
    { args: [ gamestate ] },
    { args: [ gamestate ] },
    { args: [ gamestate ] },
    { args: [ gamestate ] },
    { args: [ gamestate ] }
  ], function(gs) {

    if (gs.handProgressiveId === 2){
      gs.players[0].status = playerStatus.out;
    }

    sut(gs);

    const caseIndex = gs.handProgressiveId;
    const player = gs.players.find(player => player[hasDB]);

    gs.handProgressiveId++;

    const dbi = gs.initialDealerButtonIndex;
    const dbr = gs.dealerButtonRound;


    function getRound(val){
      if (val <= 1){
        return 0;
      }
      if (val <= 3){
        return 1;
      }
      return 2;
    }

    return dbi === 1 && player.id === expectedDealerButtonId[caseIndex-1] && dbr === getRound(caseIndex-1);

  });

}());
tcase([
  { description: 'handId=1, dealer button index changes on the basis of the gameId', args: [ 1 ] },
  { args: [ 2 ] },
  { args: [ 3 ] },
  { args: [ 4 ] },
  { args: [ 5 ] }
], function(gameId) {

  const gs = enhance({
    handProgressiveId: 1,
    gameProgressiveId: gameId,
    players: [{
      name: 'arale'
    }, {
      name: 'bender'
    }, {
      name: 'marvin'
    }, {
      name: 'wall-e'
    }]
  });

  sut(gs);

  const dbi = gs.initialDealerButtonIndex;
  const dbr = gs.dealerButtonRound;

  return dbr === 0 && dbi === (gameId-1)%4 && gs.players[dbi][hasDB];

});