本文整理汇总了Python中ClusterShell.RangeSet.RangeSetND.difference方法的典型用法代码示例。如果您正苦于以下问题:Python RangeSetND.difference方法的具体用法?Python RangeSetND.difference怎么用?Python RangeSetND.difference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClusterShell.RangeSet.RangeSetND
的用法示例。
在下文中一共展示了RangeSetND.difference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_difference
# 需要导入模块: from ClusterShell.RangeSet import RangeSetND [as 别名]
# 或者: from ClusterShell.RangeSet.RangeSetND import difference [as 别名]
def test_difference(self):
rn1 = RangeSetND([["10", "10-13"], ["0-3", "1-2"]])
rn2 = RangeSetND([["10", "12"]])
self.assertEqual(len(rn1), 12)
rnres = rn1.difference(rn2)
self.assertEqual(str(rnres), "0-3; 1-2\n10; 10-11,13\n")
self.assertEqual(len(rnres), 11)
rn1 = RangeSetND([["0-2", "1-3", "4-5"]])
rn2 = RangeSetND([["0-2", "1-3", "4"]])
rnres = rn1.difference(rn2)
self.assertEqual(str(rnres), "0-2; 1-3; 5\n")
self.assertEqual(len(rnres), 9)
rn1 = RangeSetND([["0-2", "1-3", "4-5"]])
rn2 = RangeSetND([["10-40", "20-120", "0-100"]])
rnres = rn1.difference(rn2)
self.assertEqual(str(rnres), "0-2; 1-3; 4-5\n")
self.assertEqual(len(rnres), 18)
rn1 = RangeSetND([["0-2", "1-3", "4-5"]])
rn2 = RangeSetND([["10-40", "20-120", "100-200"]])
rnres = rn1.difference(rn2)
self.assertEqual(str(rnres), "0-2; 1-3; 4-5\n")
self.assertEqual(len(rnres), 18)
rnres2 = rn1 - rn2
self.assertEqual(str(rnres2), "0-2; 1-3; 4-5\n")
self.assertEqual(len(rnres2), 18)
self.assertEqual(rnres, rnres2) # btw test __eq__
try:
dummy = rn1 - "foobar"
self.assertFalse("TypeError not raised")
except TypeError:
pass