示例#1
0
 public function testFind()
 {
     $map = m(["one" => "a", "two" => "b", "three" => "c", "four" => "d", "five" => "e"]);
     // Using the default comparator.
     $found = $map->find("c");
     $this->assertTrue($found);
     $foundUnderKey;
     $found = $map->find("d", CComparator::EQUALITY, $foundUnderKey);
     $this->assertTrue($found);
     $this->assertTrue($foundUnderKey->equals("four"));
     $found = $map->find("C");
     $this->assertFalse($found);
     $found = $map->find("f");
     $this->assertFalse($found);
     // Using a custom comparator.
     $comparator = function ($string0, $string1) {
         return $string0->toLowerCase()->equals($string1->toLowerCase());
     };
     $foundUnderKey;
     $found = $map->find(u("C"), $comparator, $foundUnderKey);
     $this->assertTrue($found);
     $this->assertTrue($foundUnderKey->equals("three"));
     // Special case.
     $map = new CMapObject();
     $found = $map->find("a");
     $this->assertFalse($found);
 }