diff options
author | emkael <emkael@tlen.pl> | 2013-09-14 18:33:19 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2013-09-14 18:33:19 +0200 |
commit | 62e228801c814dc9bc73ff8e11fbe2a400198e83 (patch) | |
tree | 35195c79fce7738962e20aaf0d37b4b26d8dcdea | |
parent | 77673cdb197d2d98ae9f154d129b880de3755ce1 (diff) |
* testy jednostkowe dla parsera wejścia (ręki)
-rw-r--r-- | tests/OsikaEvaluatorTest.php | 0 | ||||
-rw-r--r-- | tests/OsikaParserTest.php | 106 |
2 files changed, 106 insertions, 0 deletions
diff --git a/tests/OsikaEvaluatorTest.php b/tests/OsikaEvaluatorTest.php new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/OsikaEvaluatorTest.php 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 @@ +<?php + +class OsikaParserTest extends PHPUnit_Framework_TestCase { + + private $_parser; + + public function setUp() { + require_once('../bin/lib/OsikaParser.php'); + $this->_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 |