From 62e228801c814dc9bc73ff8e11fbe2a400198e83 Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 14 Sep 2013 18:33:19 +0200 Subject: * testy jednostkowe dla parsera wejścia (ręki) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/OsikaEvaluatorTest.php | 0 tests/OsikaParserTest.php | 106 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 tests/OsikaEvaluatorTest.php create mode 100644 tests/OsikaParserTest.php diff --git a/tests/OsikaEvaluatorTest.php b/tests/OsikaEvaluatorTest.php new file mode 100644 index 0000000..e69de29 diff --git a/tests/OsikaParserTest.php b/tests/OsikaParserTest.php new file mode 100644 index 0000000..4ba5143 --- /dev/null +++ b/tests/OsikaParserTest.php @@ -0,0 +1,106 @@ +_parser = new OsikaParser(); + } + + /** + * @expectedException OsikaParserException + * @expectedExceptionCode 1 + **/ + public function testEmpty() { + $this->_parser->parse(); + } + + public function testLowerCase() { + $this->_parser->setHand('xxx|xxxx|xxx|xxx'); + $this->assertEquals(['xxx','xxxx','xxx','xxx'], $this->_parser->parse()); + $this->_parser->setHand('XXX|XXXX|XXX|XXX'); + $this->assertEquals(['xxx','xxxx','xxx','xxx'], $this->_parser->parse()); + $this->_parser->setHand('XXX|xxxx|XXX|XXX'); + $this->assertEquals(['xxx','xxxx','xxx','xxx'], $this->_parser->parse()); + $this->_parser->setHand('XXX|XXXX|Xxx|XXX'); + $this->assertEquals(['xxx','xxxx','xxx','xxx'], $this->_parser->parse()); + $this->_parser->setHand('XXx|XXXx|xXX|XxX'); + $this->assertEquals(['xxx','xxxx','xxx','xxx'], $this->_parser->parse()); + } + + public function testHonorSubstitution() { + $this->_parser = new OsikaParser(); + $this->_parser->setHand('AKQJT|xxx|xxx|xx'); + $this->assertEquals(['akqjt','xxx','xxx','xx'], $this->_parser->parse()); + $this->_parser->setHand('AKDW10|xxx|xxx|xx'); + $this->assertEquals(['akqjt','xxx','xxx','xx'], $this->_parser->parse()); + $this->_parser->setHand('AKdJT|xxx|xxx|xx'); + $this->assertEquals(['akqjt','xxx','xxx','xx'], $this->_parser->parse()); + $this->_parser->setHand('AKQwT|xxx|xxx|xx'); + $this->assertEquals(['akqjt','xxx','xxx','xx'], $this->_parser->parse()); + } + + public function testSpacesStrip() { + $this->_parser->setHand("\x09\x0A\x0C\x0D\x20xxx|xx\x09\x0A\x0C\x0D\x20xx|x\x09\x0A\x0C\x0D\x20xx|xxx\x09\x0A\x0C\x0D\x20\x09\x0A\x0C\x0D\x20"); + $this->assertEquals(['xxx','xxxx','xxx','xxx'], $this->_parser->parse()); + } + + /** + * @expectedException OsikaParserException + * @expectedExceptionCode 2 + **/ + public function testNotEnoughSuits() { + $this->_parser->setHand('xxxxxxx|xxxxxx|'); + $this->_parser->parse(); + } + + /** + * @expectedException OsikaParserException + * @expectedExceptionCode 2 + **/ + public function testTooManySuits() { + $this->_parser->setHand('xxx|xxxx|xxx|xxx|'); + $this->_parser->parse(); + } + + /** + * @expectedException OsikaParserException + * @expectedExceptionCode 3 + **/ + public function testInvalidCharacters() { + $this->_parser->setHand('a||a|akdjz98xxx0'); + $this->_parser->parse(); + } + + /** + * @expectedException OsikaParserException + * @expectedExceptionCode 4 + **/ + public function testDuplicateCard() { + $this->_parser->setHand('akdw|akdw|akd|t10'); + $this->_parser->parse(); + } + + public function testCardSort() { + $this->_parser->setHand('akdj|akw|a|a9xxx'); + $this->assertEquals(['akqj','akj','a','a9xxx'], $this->_parser->parse()); + $this->_parser->setHand('kajd|twa|a|9axxx'); + $this->assertEquals(['akqj','ajt','a','a9xxx'], $this->_parser->parse()); + $this->_parser->setHand('akdj|akw|a|ax89x'); + $this->assertEquals(['akqj','akj','a','a9x8x'], $this->_parser->parse()); + } + + /** + * @expectedException OsikaParserException + * @expectedExceptionCode 5 + **/ + public function testInvalidCardCount() { + $this->_parser->setHand('xxx|xxx|xxx|xxx'); + $this->_parser->parse(); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3