SubsetTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. class FormalTheory_RegularExpression_Tests_SubsetTest extends PHPUnit_Framework_TestCase
  3. {
  4. function dataProviderForTestSubset()
  5. {
  6. return array(
  7. array( "", "", TRUE ),
  8. array( "$^", "", TRUE ),
  9. array( "$^", "^$", TRUE ),
  10. array( "^$", "", TRUE ),
  11. array( "^(0000)*$", "^(00)*$", TRUE ),
  12. array( "^(000)*$", "^(00)*$", FALSE ),
  13. array( "^(00)*$", "^(00)*$", TRUE ),
  14. array( "^0*$", "^(0|1)*$", TRUE ),
  15. array( "^(0|1)*$", "^0*$", FALSE ),
  16. array( "^1{0,5}$", "^1+$", FALSE ),
  17. array( "^a+$", "^(a*[bc])*$", FALSE )
  18. );
  19. }
  20. /**
  21. * @dataProvider dataProviderForTestSubset
  22. */
  23. function testSubset( $regex_string1, $regex_string2, $expected_result )
  24. {
  25. $lexer = new FormalTheory_RegularExpression_Lexer();
  26. $nfa1 = $lexer->lex( $regex_string1 )->getNFA();
  27. $nfa2 = $lexer->lex( $regex_string2 )->getNFA();
  28. $this->assertSame( $nfa1->isSubsetOf( $nfa2 ), $expected_result );
  29. }
  30. function dataProviderForTestProperSubset()
  31. {
  32. return array(
  33. array( "", "", FALSE ),
  34. array( "$^", "", TRUE ),
  35. array( "$^", "^$", TRUE ),
  36. array( "^$", "", TRUE ),
  37. array( "^(0000)*$", "^(00)*$", TRUE ),
  38. array( "^(000)*$", "^(00)*$", FALSE ),
  39. array( "^(00)*$", "^(00)*$", FALSE ),
  40. array( "^0*$", "^(0|1)*$", TRUE ),
  41. array( "^(0|1)*$", "^0*$", FALSE ),
  42. array( "^1{0,5}$", "^1+$", FALSE ),
  43. );
  44. }
  45. /**
  46. * @dataProvider dataProviderForTestProperSubset
  47. */
  48. function testProperSubset( $regex_string1, $regex_string2, $expected_result )
  49. {
  50. $lexer = new FormalTheory_RegularExpression_Lexer();
  51. $nfa1 = $lexer->lex( $regex_string1 )->getNFA();
  52. $nfa2 = $lexer->lex( $regex_string2 )->getNFA();
  53. $this->assertSame( $nfa1->isProperSubsetOf( $nfa2 ), $expected_result );
  54. }
  55. }
  56. ?>