本文整理汇总了Python中pattern.Pattern.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python Pattern.is_valid方法的具体用法?Python Pattern.is_valid怎么用?Python Pattern.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pattern.Pattern
的用法示例。
在下文中一共展示了Pattern.is_valid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Pattern
# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import is_valid [as 别名]
from pattern import Pattern
#----test some known valid cases
p = Pattern([4,4,1])
if(p.is_valid() == False):
print "test_fail, pattern [4,4,1] should be a valid siteswap"
if(p.particles != 3):
print "test_fail, pattern [4,4,1] should have 3 balls"
p = Pattern([1,-1,0])
if(p.is_valid() == False):
print "test_fail, pattern [1,-1,0] should be a valid siteswap"
if(p.particles != 0):
print "test_fail, pattern [1,-1,0] should have 0 balls"
p = Pattern([2,3,3,-2,2,-2,1,1])
if(p.is_valid() == False):
print "test_fail, pattern [2,3,3,-2,2,-2,1,1] should be a valid siteswap"
if(p.particles != 1):
print "test_fail, pattern [2,3,3,-2,2,-2,1,1] should have 1 ball"
#----test some known invalid cases
#we try to construct the objects, and in case it fails and throws an error
# then we know everything went as expeced
construct_fail = False
try:
p = Pattern([2,1,0])
except ValueError as e:
construct_fail = True