<commit_before><?php

include_once(__DIR__ . '/../underscore.php');

class UnderscoreUtilityTest extends PHPUnit_Framework_TestCase {
  
  public function testIdentity() {
    // from js
    $moe = array('name'=>'moe');
    $moe_obj = (object) $moe;
    $this->assertEquals($moe, _::identity($moe));
    $this->assertEquals($moe_obj, _::identity($moe_obj));
    
    // extra
    $this->assertEquals($moe, _($moe)->identity());
    $this->assertEquals($moe_obj, _($moe_obj)->identity());
  }
  
  public function testUniqueId() {
    // from js
    $ids = array();
    while($i++ < 100) array_push($ids, _::uniqueId());
    $this->assertEquals(count($ids), count(_::uniq($ids)));
    
    // extra
    $this->assertEquals('stooges', join('', (_::first(_::uniqueId('stooges'), 7))), 'prefix assignment works');
    $this->assertEquals('stooges', join('', _(_('stooges')->uniqueId())->first(7)), 'prefix assignment works in OO-style call');
    
    while($i++ < 100) array_push($ids, _()->uniqueId());
    $this->assertEquals(count($ids), count(_()->uniq($ids)));
  }
  
  public function testTimes() {
    $vals = array();
    _::times(3, function($i) use (&$vals) { $vals[] = $i; });
    $this->assertEquals(array(0,1,2), $vals, 'is 0 indexed');
    
    // @todo
    /*
    vals = [];
    _(3).times(function (i) { vals.push(i); });
    ok(_.isEqual(vals, [0,1,2]), "works as a wrapper");
    */
  }
  
  public function testMixin() {
    _::mixin(array(
      'myReverse' => function($string) {
        $chars = str_split($string);
        krsort($chars);
        return join('', $chars);
      }
    ));
    $this->assertEquals('aecanap', _::myReverse('panacea'), 'mixed in a function to _');<commit_msg>Test - Added OO test for times()<commit_after><?php

include_once(__DIR__ . '/../underscore.php');

class UnderscoreUtilityTest extends PHPUnit_Framework_TestCase {
  
  public function testIdentity() {
    // from js
    $moe = array('name'=>'moe');
    $moe_obj = (object) $moe;
    $this->assertEquals($moe, _::identity($moe));
    $this->assertEquals($moe_obj, _::identity($moe_obj));
    
    // extra
    $this->assertEquals($moe, _($moe)->identity());
    $this->assertEquals($moe_obj, _($moe_obj)->identity());
  }
  
  public function testUniqueId() {
    // from js
    $ids = array();
    while($i++ < 100) array_push($ids, _::uniqueId());
    $this->assertEquals(count($ids), count(_::uniq($ids)));
    
    // extra
    $this->assertEquals('stooges', join('', (_::first(_::uniqueId('stooges'), 7))), 'prefix assignment works');
    $this->assertEquals('stooges', join('', _(_('stooges')->uniqueId())->first(7)), 'prefix assignment works in OO-style call');
    
    while($i++ < 100) array_push($ids, _()->uniqueId());
    $this->assertEquals(count($ids), count(_()->uniq($ids)));
  }
  
  public function testTimes() {
    // from js
    $vals = array();
    _::times(3, function($i) use (&$vals) { $vals[] = $i; });
    $this->assertEquals(array(0,1,2), $vals, 'is 0 indexed');
    
    $vals = array();
    _(3)->times(function($i) use (&$vals) { $vals[] = $i; });
    $this->assertEquals(array(0,1,2), $vals, 'works as a wrapper in OO-style call');
  }
  
  public function testMixin() {
    _::mixin(array(
      'myReverse' => function($string) {
        $chars = str_split($string);
        krsort($chars);
        return join('', $chars);
      }
    ));
    $this->assertEquals('aecanap', _::myReverse('panacea'), 'mixed in a function to _');
{'fraction_non_alphanumeric': 0.22091013824884792, 'fraction_numerical': 0.009792626728110598, 'mean_word_length': 3.551769331585845, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, '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': '3266300', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1179, 'n_words': 228}