def test_mult_multiplication(): # a{2,3} * 1 = a{2,3} assert mult.parse("a{2,3}") * one == mult.parse("a{2,3}") # a{2,3} * {4,5} = a{8,15} assert mult.parse("a{2,3}") * multiplier.parse("{4,5}") == mult.parse("a{8,15}") # a{2,} * {2,} = a{4,} assert mult.parse("a{2,}") * multiplier.parse("{2,}") == mult.parse("a{4,}")
def test_charclass_multiplication(): # a * 1 = a assert charclass("a") * one == charclass("a") # a * {1,3} = a{1,3} assert charclass("a") * multiplier.parse("{1,3}") == mult.parse("a{1,3}") # a * {4,} = a{4,} assert charclass("a") * multiplier.parse("{4,}") == mult.parse("a{4,}")
def test_mult_reduction_easy(): assert mult.parse("a").reduce() == charclass.parse("a") assert mult.parse("a").reduce() == charclass("a") assert mult.parse("a?").reduce() == mult(charclass("a"), qm) assert mult.parse("a{0}").reduce() == emptystring assert mult.parse("[]").reduce() == nothing assert mult.parse("[]?").reduce() == emptystring assert mult.parse("[]{0}").reduce() == emptystring assert mult.parse("[]{0,5}").reduce() == emptystring assert mult(pattern(), one).reduce() == nothing assert mult(pattern(), qm).reduce() == emptystring assert mult(pattern(), zero).reduce() == emptystring assert mult(pattern(), multiplier.parse("{0,5}")).reduce() == emptystring
def test_multiplier_subtraction(): # a{3,4}, a{2,5} -> a{2,3} (with a{1,1}, a{0,2} left over) assert multiplier.parse("{3,4}").common(multiplier.parse("{2,5}")) == multiplier.parse("{2,3}") assert multiplier.parse("{3,4}") - multiplier.parse("{2,3}") == one assert multiplier.parse("{2,5}") - multiplier.parse("{2,3}") == multiplier.parse("{0,2}") # a{2,}, a{1,5} -> a{1,5} (with a{1,}, a{0,0} left over) assert multiplier.parse("{2,}").common(multiplier.parse("{1,5}")) == multiplier.parse("{1,5}") assert multiplier.parse("{2,}") - multiplier.parse("{1,5}") == plus assert multiplier.parse("{1,5}") - multiplier.parse("{1,5}") == zero # a{3,}, a{2,} -> a{2,} (with a, epsilon left over) assert multiplier.parse("{3,}").common(multiplier.parse("{2,}")) == multiplier.parse("{2,}") assert multiplier.parse("{3,}") - multiplier.parse("{2,}") == one assert multiplier.parse("{2,}") - multiplier.parse("{2,}") == zero # a{3,}, a{3,} -> a{3,} (with zero, zero left over) assert multiplier.parse("{3,}").common(multiplier.parse("{3,}")) == multiplier.parse("{3,}") assert multiplier.parse("{3,}") - multiplier.parse("{3,}") == zero
def test_two_two_bug(): assert mult.parse("a{2}") * multiplier.parse("{2}") == mult.parse("a{4}")
def test_pattern_multiplication(): assert pattern.parse("ab?|ba?") * multiplier.parse("{2,3}") == mult.parse("(ab?|ba?){2,3}")
def test_mult_multiplication(): assert mult.parse("a{2,3}") * one == mult.parse("a{2,3}") assert mult.parse("a{2,3}") * multiplier.parse("{4,5}") == mult.parse("a{8,15}") assert mult.parse("a{2,}") * multiplier.parse("{2,}") == mult.parse("a{4,}")
def test_charclass_multiplication(): assert charclass("a") * one == charclass("a") assert charclass("a") * multiplier.parse("{1,3}") == mult.parse("a{1,3}") assert charclass("a") * multiplier.parse("{4,}") == mult.parse("a{4,}")