Example #1
0
 public function testUnprogrammedKeyMissingEnabledUsingConstructor()
 {
     $graph = Graph::getInstance(true);
     $nodes = $graph->getNodes();
     $this->assertNotNull($nodes[ord('')]);
     $expected = array('Up' => '8', 'Right' => ' ', 'Down' => 'I', 'Left' => '>');
     $this->assertEquals($expected, $nodes[ord('')]);
 }
 public function __construct($sentence, $enableUnProgrammedKeyForTraversal = false)
 {
     if (!is_string($sentence)) {
         throw new InvalidArgumentException("Sentence should be string");
     }
     if (empty($sentence)) {
         throw new InvalidArgumentException("Sentence should not be empty");
     }
     $this->sentence = $sentence;
     $graph = Graph::getInstance($enableUnProgrammedKeyForTraversal);
     $this->nodes = $graph->getNodes();
     $this->fullPath = array();
 }
 /**
  * @depends testProcessWithComplicatedStringWithSentenceGenerationFromSequence
  */
 public function testProcessWithComplicatedStringWithTraversal()
 {
     $sentence = 'AA qu!c7 br0wn (fox) {jumps} ov:e> a la,zy_[dog].';
     $generator = new KeySequenceGenerator($sentence);
     $generator->process();
     $sequence = $generator->printSequences(true, true);
     $this->assertEquals(2659, strlen($sequence));
     $sequenceTokens = explode(PHP_EOL, $sequence);
     $graph = Graph::getInstance();
     $nodes = $graph->getNodes();
     $node = $nodes[ord($sequenceTokens[0])];
     for ($i = 1; $i < count($sequenceTokens); $i++) {
         if ($sequenceTokens[$i] === KeyPress::ENTER) {
             continue;
         }
         if (in_array($sequenceTokens[$i], array(KeyPress::UP, KeyPress::RIGHT, KeyPress::DOWN, KeyPress::LEFT))) {
             $next = $i + 1;
             $this->assertEquals($node[$sequenceTokens[$i]], $sequenceTokens[$next]);
             $node = $nodes[ord($sequenceTokens[$next])];
         }
     }
 }