<commit_before>require('babel/register');

var rx = require('rx');
var _ = require('underscore-plus');
var assert = require('chai').assert;

var Card = require('../src/card');
var TexasHoldem = require('../src/texas-holdem');

describe('TexasHoldem', function() {
  var game;
  var slack, messages, channel, players, scheduler;

  beforeEach(function() {
    slack = {
      token: 0xDEADBEEF,
      openDM: function() { },
      getDMByName: function() {
        return { send: function() { } };
      }
    };
    
    messages = new rx.Subject();
    channel = {
      send: function(message) {
        console.log(message);
        return { updateMessage: function() { } };
      }
    };
    
    scheduler = new rx.HistoricalScheduler();
    players = [
      { id: 1, name: '<NAME>' },
      { id: 2, name: '<NAME>' },
      { id: 3, name: '<NAME>' },
      { id: 4, name: '<NAME>' },
      { id: 5, name: '<NAME>' }
    ];

    game = new TexasHoldem(slack, messages, channel, players, scheduler);

    // We don't want to create any images during tests, so just have this
    // function write to the console.
    game.postBoard = function(round) {
      console.log("Dealing the " + round + ": " + game.board.toString());
      return rx.Observable.return(true);
    };

    // Improves the appearance of player status in the console.
    game.tableFormatter = "\n";
  });
  
  it('should handle multiple rounds with all-ins', function() {
    game.start(0);
    
    players[0].chips = 200;
    players[1].chips = 149;
    players[2].chips = 98;
    players[3].chips = 75;
    players[4].chips = 50;
    scheduler.advanceBy(5000);
    
    messages.onNext({user: 4, text: "Fold"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 5, text: "Call"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 1, text: "Call"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 2, text: "Call"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 3, text: "Raise 8"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 5, text: "Raise 50"});
    scheduler.advanceBy(5000);
    assert(game.potManager.getTotalChips() === 62);
    
    messages.onNext({user: 1, text: "Call"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 2, text: "Call"});<commit_msg>Write a spec that reproduces #23.<commit_after>require('babel/register');

var rx = require('rx');
var _ = require('underscore-plus');
var assert = require('chai').assert;

var Card = require('../src/card');
var TexasHoldem = require('../src/texas-holdem');

describe('TexasHoldem', function() {
  var game;
  var slack, messages, channel, players, scheduler;

  beforeEach(function() {
    slack = {
      token: 0xDEAD<PASSWORD>,
      openDM: function() { },
      getDMByName: function() {
        return { send: function() { } };
      }
    };
    
    messages = new rx.Subject();
    channel = {
      send: function(message) {
        console.log(message);
        return { updateMessage: function() { } };
      }
    };
    
    scheduler = new rx.HistoricalScheduler();
    players = [
      { id: 1, name: '<NAME>' },
      { id: 2, name: '<NAME>' },
      { id: 3, name: '<NAME>' },
      { id: 4, name: '<NAME>' },
      { id: 5, name: '<NAME>' }
    ];

    game = new TexasHoldem(slack, messages, channel, players, scheduler);

    // We don't want to create any images during tests, so just have this
    // function write to the console.
    game.postBoard = function(round) {
      console.log("Dealing the " + round + ": " + game.board.toString());
      return rx.Observable.return(true);
    };

    // Improves the appearance of player status in the console.
    game.tableFormatter = "\n";
  });
  
  it('should award the pot to an all-in player if everyone else folds', function() {
    game.start(0);
    scheduler.advanceBy(5000);

    messages.onNext({user: 4, text: "Fold"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 5, text: "Raise 200"});
    scheduler.advanceBy(5000);

    messages.onNext({user: 1, text: "Fold"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 2, text: "Fold"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 3, text: "Fold"});
    scheduler.advanceBy(5000);
    
    assert(players[4].chips === 203);
  });
  
  it('should handle multiple rounds with all-ins', function() {
    game.start(0);
    
    players[0].chips = 200;
    players[1].chips = 149;
    players[2].chips = 98;
    players[3].chips = 75;
    players[4].chips = 50;
    scheduler.advanceBy(5000);
    
    messages.onNext({user: 4, text: "Fold"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 5, text: "Call"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 1, text: "Call"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 2, text: "Call"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 3, text: "Raise 8"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 5, text: "Raise 50"});
    scheduler.advanceBy(5000);
    assert(game.potManager.getTotalChips() === 62);
    
    messages.onNext({user: 1, text: "Call"});
    scheduler.advanceBy(5000);
    messages.onNext({user: 2, text: "Call"});
{'fraction_non_alphanumeric': 0.17302165165740563, 'fraction_numerical': 0.03391454301590343, 'mean_word_length': 2.945578231292517, 'pattern_counts': {'":': 2, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7190912', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1732, 'n_words': 399}