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,}")
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
def test_two_two_bug():
	assert mult.parse("a{2}") * multiplier.parse("{2}") == mult.parse("a{4}")
Exemple #7
0
def test_pattern_multiplication():
	assert pattern.parse("ab?|ba?") * multiplier.parse("{2,3}") == mult.parse("(ab?|ba?){2,3}")
Exemple #8
0
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,}")
Exemple #9
0
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,}")
Exemple #10
0
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
Exemple #11
0
def test_pattern_multiplication():
	assert pattern.parse("ab?|ba?") * multiplier.parse("{2,3}") == mult.parse("(ab?|ba?){2,3}")
Exemple #12
0
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,}")
Exemple #13
0
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,}")