CountTest.php 760 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. class FormalTheory_RegularExpression_Tests_CountTest extends PHPUnit_Framework_TestCase
  3. {
  4. function dataProviderForTestSimpleCount()
  5. {
  6. return array(
  7. array( "", NULL ),
  8. array( "$^", 0 ),
  9. array( "^$", 1 ),
  10. array( "^1*$", NULL ),
  11. array( "^1?$", 2 ),
  12. array( "^1{0,2}$", 3 ),
  13. array( "^1{0,9}$", 10 ),
  14. array( "^(1{1,3}){1,3}$", 9 ),
  15. array( "^(0|1){5}$", 32 ),
  16. array( "^(0|1){4,5}$", 16 + 32 ),
  17. );
  18. }
  19. /**
  20. * @dataProvider dataProviderForTestSimpleCount
  21. */
  22. function testSimpleCount( $regex_string, $expected_solution_count )
  23. {
  24. $lexer = new FormalTheory_RegularExpression_Lexer();
  25. $dfa = $lexer->lex( $regex_string )->getDFA();
  26. $this->assertSame( $dfa->countSolutions(), $expected_solution_count );
  27. }
  28. }
  29. ?>