当前位置: 首页>>代码示例>>Python>>正文


Python RangeSet.RangeSetND类代码示例

本文整理汇总了Python中ClusterShell.RangeSet.RangeSetND的典型用法代码示例。如果您正苦于以下问题:Python RangeSetND类的具体用法?Python RangeSetND怎么用?Python RangeSetND使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RangeSetND类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_intersection

 def test_intersection(self):
     rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"], ["8-9", "12-15"]])
     self.assertEqual(len(rn1), 13)
     self.assertEqual(str(rn1), "8-9; 12-15\n10; 9-13\n")
     rn2 = RangeSetND([["10", "10"], ["9", "12-15"]])
     self.assertEqual(len(rn2), 5)
     self.assertEqual(str(rn2), "9; 12-15\n10; 10\n")
     rni = rn1.intersection(rn2)
     self.assertEqual(len(rni), 5)
     self.assertEqual(str(rni), "9; 12-15\n10; 10\n")
     self.assertEqual(len(rn1), 13)
     self.assertEqual(str(rn1), "8-9; 12-15\n10; 9-13\n")
     self.assertEqual(len(rn2), 5)
     self.assertEqual(str(rn2), "9; 12-15\n10; 10\n")
     # test __and__
     rni2 = rn1 & rn2
     self.assertEqual(len(rni2), 5)
     self.assertEqual(str(rni2), "9; 12-15\n10; 10\n")
     self.assertEqual(len(rn1), 13)
     self.assertEqual(str(rn1), "8-9; 12-15\n10; 9-13\n")
     self.assertEqual(len(rn2), 5)
     self.assertEqual(str(rn2), "9; 12-15\n10; 10\n")
     self.assertEqual(rni, rni2) # btw test __eq__
     try:
         dummy = rn1 & "foobar"
         self.assertFalse("TypeError not raised")
     except TypeError:
         pass
开发者ID:LaHaine,项目名称:ohpc,代码行数:28,代码来源:RangeSetNDTest.py

示例2: test_contiguous

 def test_contiguous(self):
     rn0 = RangeSetND()
     self.assertEqual([], [str(ns) for ns in rn0.contiguous()])
     rn1 = RangeSetND([["10", "10-13,15"], ["0-3,5-6", "1-2"]])
     self.assertEqual(str(rn1), "0-3,5-6; 1-2\n10; 10-13,15\n")
     self.assertEqual(['0-3; 1-2\n', '5-6; 1-2\n', '10; 10-13\n', '10; 15\n'], [str(ns) for ns in rn1.contiguous()])
     self.assertEqual(str(rn1), "0-3,5-6; 1-2\n10; 10-13,15\n")
开发者ID:LaHaine,项目名称:ohpc,代码行数:7,代码来源:RangeSetNDTest.py

示例3: test_union

 def test_union(self):
     rn1 = RangeSetND([["10-100", "1-3"], ["1100-1300", "2-3"]])
     self.assertEqual(str(rn1), "1100-1300; 2-3\n10-100; 1-3\n")
     self.assertEqual(len(rn1), 675)
     rn2 = RangeSetND([["1100-1200", "1"], ["10-49", "1,3"]])
     self.assertEqual(str(rn2), "1100-1200; 1\n10-49; 1,3\n")
     self.assertEqual(len(rn2), 181)
     rnu = rn1.union(rn2)
     self.assertEqual(str(rnu), "1100-1300; 2-3\n10-100; 1-3\n1100-1200; 1\n")
     self.assertEqual(len(rnu), 776)
     rnu2 = rn1 | rn2
     self.assertEqual(str(rnu2), "1100-1300; 2-3\n10-100; 1-3\n1100-1200; 1\n")
     self.assertEqual(len(rnu2), 776)
     self.assertEqual(rnu, rnu2) # btw test __eq__
     self.assertNotEqual(rnu, rn1) # btw test __eq__
     self.assertNotEqual(rnu, rn2) # btw test __eq__
     try:
         dummy = rn1 | "foobar"
         self.assertFalse("TypeError not raised")
     except TypeError:
         pass
     # binary error
     if sys.version_info >= (2, 5, 0):
         rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"]])
         rn2 = RangeSetND([["1100-1200", "1"], ["10-49", "1,3"]])
         rn1 |= rn2
         self.assertEqual(str(rn2), "1100-1200; 1\n10-49; 1,3\n")
         self.assertEqual(len(rn2), 181)
         rn2 = set([3, 5])
         self.assertRaises(TypeError, rn1.__ior__, rn2)
开发者ID:LaHaine,项目名称:ohpc,代码行数:30,代码来源:RangeSetNDTest.py

示例4: test_pads

 def test_pads(self):
     rn0 = RangeSetND()
     self.assertEqual(str(rn0), "")
     self.assertEqual(len(rn0), 0)
     self.assertEqual(rn0.pads(), ())
     rn1 = RangeSetND([['01-02', '003'], ['01-02', '004'], ['02-06', '006-009,411']])
     self.assertEqual(str(rn1), "02-06; 006-009,411\n01-02; 003-004\n")
     self.assertEqual(len(rn1), 29)
     self.assertEqual(rn1.pads(), (2, 3))
开发者ID:LaHaine,项目名称:ohpc,代码行数:9,代码来源:RangeSetNDTest.py

示例5: test_mutability_2

    def test_mutability_2(self):
        rs0 = RangeSet("2-5")
        rs1 = RangeSet("0-1")
        rn0 = RangeSetND([[rs0, rs1]]) #, copy_rangeset=False)
        self.assertEqual(str(rn0), "2-5; 0-1\n")

        rs2 = RangeSet("6-7")
        rs3 = RangeSet("2-3")
        rn0.update([[rs2, rs3]])
        self.assertEqual(str(rn0), "2-5; 0-1\n6-7; 2-3\n")

        rs3.add(4)
        self.assertEqual(str(rs3), "2-4")
        self.assertEqual(str(rn0), "2-5; 0-1\n6-7; 2-3\n")
开发者ID:LaHaine,项目名称:ohpc,代码行数:14,代码来源:RangeSetNDTest.py

示例6: test_mutability_1

    def test_mutability_1(self):
        rs0 = RangeSet("2-5")
        rs1 = RangeSet("0-1")
        rn0 = RangeSetND([[rs0, rs1]]) #, copy_rangeset=False)
        self.assertEqual(str(rn0), "2-5; 0-1\n")

        rs2 = RangeSet("6-7")
        rs3 = RangeSet("2-3")
        rn1 = RangeSetND([[rs2, rs3]]) #, copy_rangeset=False)
        rn0.update(rn1)
        self.assertEqual(str(rn0), "2-5; 0-1\n6-7; 2-3\n")

        # check mutability safety
        self.assertEqual(str(rs0), "2-5")
        self.assertEqual(str(rs1), "0-1")
        self.assertEqual(str(rs2), "6-7")
        self.assertEqual(str(rs3), "2-3")

        # reverse check
        rs1.add(2)
        self.assertEqual(str(rs1), "0-2")
        rs3.add(4)
        self.assertEqual(str(rs3), "2-4")
        self.assertEqual(str(rn0), "2-5; 0-1\n6-7; 2-3\n")

        self.assertEqual(str(rn1), "6-7; 2-3\n")
        rn1.update([[rs2, rs3]])
        self.assertEqual(str(rn1), "6-7; 2-4\n")

        self.assertEqual(str(rn0), "2-5; 0-1\n6-7; 2-3\n")
开发者ID:LaHaine,项目名称:ohpc,代码行数:30,代码来源:RangeSetNDTest.py

示例7: test_xor

 def test_xor(self):
     rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"]])
     rn2 = RangeSetND([["10", "10"]])
     rnx = rn1.symmetric_difference(rn2)
     self.assertEqual(len(rnx), 4)
     self.assertEqual(str(rnx), "10; 9,11-13\n")
     rnx2 = rn1 ^ rn2
     self.assertEqual(len(rnx2), 4)
     self.assertEqual(str(rnx2), "10; 9,11-13\n")
     self.assertEqual(rnx, rnx2)
     try:
         dummy = rn1 ^ "foobar"
         self.assertFalse("TypeError not raised")
     except TypeError:
         pass
     # binary error
     if sys.version_info >= (2, 5, 0):
         rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"]])
         rn2 = RangeSetND([["10", "10"]])
         rn1 ^= rn2
         self.assertEqual(len(rnx), 4)
         self.assertEqual(str(rnx), "10; 9,11-13\n")
         rn2 = set([3, 5])
         self.assertRaises(TypeError, rn1.__ixor__, rn2)
开发者ID:LaHaine,项目名称:ohpc,代码行数:24,代码来源:RangeSetNDTest.py

示例8: test_pads

 def test_pads(self):
     rn0 = RangeSetND()
     self.assertEqual(str(rn0), "")
     self.assertEqual(len(rn0), 0)
     self.assertEqual(rn0.pads(), ())
     rn1 = RangeSetND([['01-02', '003'], ['01-02', '004'], ['02-06', '006-009,411']])
     self.assertEqual(str(rn1), "02-06; 006-009,411\n01-02; 003-004\n")
     self.assertEqual(len(rn1), 29)
     self.assertEqual(rn1.pads(), (2, 3))
     # Note: padding mismatch is NOT supported by ClusterShell
     # We just track any regressions here (MAY CHANGE!)
     rn1 = RangeSetND([['01-02', '003'], ['01-02', '0101'], ['02-06', '006-009,411']])
     # here 0101 padding is changed to 101
     self.assertEqual(str(rn1), '02-06; 006-009,411\n01-02; 003,101\n')
     self.assertEqual(len(rn1), 29)
     self.assertEqual(rn1.pads(), (2, 3))
     rn1 = RangeSetND([['01-02', '0003'], ['01-02', '004'], ['02-06', '006-009,411']])
     # here 004 padding is changed to 0004
     self.assertEqual(str(rn1), '02-06; 006-009,411\n01-02; 0003-0004\n')
     self.assertEqual(len(rn1), 29)
     self.assertEqual(rn1.pads(), (2, 4)) # pads() returns max padding length by axis
开发者ID:cea-hpc,项目名称:clustershell,代码行数:21,代码来源:RangeSetNDTest.py

示例9: test_difference

    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
开发者ID:LaHaine,项目名称:ohpc,代码行数:36,代码来源:RangeSetNDTest.py

示例10: test_subset_superset

 def test_subset_superset(self):
     r1 = RangeSetND([["0-10"], ["40-60"]])
     self.assertTrue(r1.issubset(r1))
     self.assertTrue(r1.issuperset(r1))
     r2 = RangeSetND([["0-10"], ["40-60"]])
     self.assertTrue(r2.issubset(r1))
     self.assertTrue(r1.issubset(r2))
     self.assertTrue(r2.issuperset(r1))
     self.assertTrue(r1.issuperset(r2))
     r1 = RangeSetND([["0-10"], ["40-60"]])
     r2 = RangeSetND()
     self.assertTrue(r2.issubset(r1))
     self.assertFalse(r1.issubset(r2))
     self.assertTrue(r1.issuperset(r2))
     self.assertFalse(r2.issuperset(r1))
     r1 = RangeSetND([["0-10"], ["40-60"]])
     r2 = RangeSetND([["4"], ["10,40-41"]])
     self.assertFalse(r1.issubset(r2))
     self.assertFalse(r1 < r2)
     self.assertTrue(r2.issubset(r1))
     self.assertTrue(r2 < r1)
     self.assertTrue(r1.issuperset(r2))
     self.assertTrue(r1 > r2)
     self.assertFalse(r2.issuperset(r1))
     self.assertFalse(r2 > r1)
     r1 = RangeSetND([["0-10", "1-2"], ["40-60", "2-5"]])
     r2 = RangeSetND([["4-8", "1"], ["10,40-41", "2"]])
     self.assertFalse(r1.issubset(r2))
     self.assertFalse(r1 < r2)
     self.assertTrue(r2.issubset(r1))
     self.assertTrue(r2 < r1)
     self.assertTrue(r1.issuperset(r2))
     self.assertTrue(r1 > r2)
     self.assertFalse(r2.issuperset(r1))
     self.assertFalse(r2 > r1)
开发者ID:LaHaine,项目名称:ohpc,代码行数:35,代码来源:RangeSetNDTest.py

示例11: test_fold

 def test_fold(self):
     r1 = RangeSetND([["0-10", "1-2"], ["5-15,40-60", "1-3"], ["0-4", "3"]])
     r1.fold()
     self.assertEqual(str(r1._veclist), "[[0-15,40-60, 1-3]]")
     self.assertEqual(str(r1), "0-15,40-60; 1-3\n")
开发者ID:LaHaine,项目名称:ohpc,代码行数:5,代码来源:RangeSetNDTest.py

示例12: test_dim

 def test_dim(self):
     r0 = RangeSetND()
     self.assertEqual(r0.dim(), 0)
     r1 = RangeSetND([["0-10", "1-2"], ["40-60", "1-3"]])
     self.assertEqual(r1.dim(), 2)
开发者ID:LaHaine,项目名称:ohpc,代码行数:5,代码来源:RangeSetNDTest.py

示例13: test_vectors

 def test_vectors(self):
     rn = RangeSetND([["0-10", "1-2"], ["5-60", "2"]])
     # vectors() should perform automatic folding
     self.assertEqual([[RangeSet("0-60"), RangeSet("2")], [RangeSet("0-10"), RangeSet("1")]], list(rn.vectors()))
     self.assertEqual(str(rn), "0-60; 2\n0-10; 1\n")
     self.assertEqual(len(rn), 72)
开发者ID:LaHaine,项目名称:ohpc,代码行数:6,代码来源:RangeSetNDTest.py

示例14: test_intersection_update

    def test_intersection_update(self):
        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"]])
        self.assertEqual(len(rn1), 5)
        self.assertEqual(str(rn1), "10; 9-13\n")
        # self test:
        rn1.intersection_update(rn1)
        self.assertEqual(len(rn1), 5)
        self.assertEqual(str(rn1), "10; 9-13\n")
        #
        rn2 = RangeSetND([["10", "10"]])
        rn1.intersection_update(rn2)
        self.assertEqual(len(rn1), 1)
        self.assertEqual(str(rn1), "10; 10\n")

        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"], ["8-9", "12-15"]])
        rn2 = RangeSetND([["10", "10"], ["9", "12-15"]])
        rn1.intersection_update(rn2)
        self.assertEqual(len(rn1), 5)
        self.assertEqual(str(rn1), "9; 12-15\n10; 10\n")

        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"], ["8-9", "12-15"]])
        rn2 = RangeSetND([["10", "10"], ["9", "12-15"], ["10-12", "11-15"], ["11", "14"]])
        rn1.intersection_update(rn2)
        self.assertEqual(len(rn1), 8)
        self.assertEqual(str(rn1), "9; 12-15\n10; 10-13\n")

        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"], ["8-9", "12-15"], ["10", "10-13"], ["10", "12-16"], ["9", "13-16"]])
        rn2 = RangeSetND([["10", "10"], ["9", "12-15"], ["10-12", "11-15"], ["11", "14"]])
        rn1.intersection_update(rn2)
        self.assertEqual(len(rn1), 10)
        self.assertEqual(str(rn1), "10; 10-15\n9; 12-15\n")

        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"], ["8-9", "12-15"], ["10", "10-13"], ["10", "12-16"], ["9", "13-16"]])
        rn2 = RangeSetND([["10", "10"], ["9", "12-16"], ["10-12", "11-15"], ["11", "14"], ["8", "10-20"]])
        rn1.intersection_update(rn2)
        self.assertEqual(len(rn1), 15)
        # no pre-fold (self._veclist)
        self.assertEqual(str(rn1), "10; 10-15\n9; 12-16\n8; 12-15\n")
        # pre-fold (self.veclist)
        #self.assertEqual(str(rn1), "8-9; 12-15\n10; 10-15\n9; 16\n")

        # binary error
        if sys.version_info >= (2, 5, 0):
            rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"]])
            rn2 = RangeSetND([["10", "10"]])
            rn1 &= rn2
            self.assertEqual(len(rn1), 1)
            self.assertEqual(str(rn1), "10; 10\n")
            rn2 = set([3, 5])
            self.assertRaises(TypeError, rn1.__iand__, rn2)
开发者ID:LaHaine,项目名称:ohpc,代码行数:50,代码来源:RangeSetNDTest.py

示例15: test_difference_update

    def test_difference_update(self):
        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"]])
        rn2 = RangeSetND([["10", "10"]])
        rn1.difference_update(rn2)
        self.assertEqual(len(rn1), 4)
        self.assertEqual(str(rn1), "10; 9,11-13\n")

        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"], ["8-9", "12-15"]])
        rn2 = RangeSetND([["10", "10"], ["9", "12-15"]])
        rn1.difference_update(rn2)
        self.assertEqual(len(rn1), 8)
        self.assertEqual(str(rn1), "8; 12-15\n10; 9,11-13\n")

        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"], ["8-9", "12-15"]])
        rn2 = RangeSetND([["10", "10"], ["9", "12-15"], ["10-12", "11-15"], ["11", "14"]])
        rn1.difference_update(rn2)
        self.assertEqual(len(rn1), 5)
        self.assertEqual(str(rn1), "8; 12-15\n10; 9\n")

        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"], ["8-9", "12-15"], ["10", "10-13"], ["10", "12-16"], ["9", "13-16"]])
        rn2 = RangeSetND([["10", "10"], ["9", "12-15"], ["10-12", "11-15"], ["11", "14"]])
        rn1.difference_update(rn2)
        self.assertEqual(len(rn1), 7)
        # no pre-fold (self._veclist)
        self.assertEqual(str(rn1), "8; 12-15\n9-10; 16\n10; 9\n")
        # pre-fold (self.veclist)
        #self.assertEqual(str(rn1), "8; 12-15\n10; 9,16\n9; 16\n")

        # strict mode
        rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"], ["8-9", "12-15"]])
        rn2 = RangeSetND([["10", "10"], ["9", "12-15"], ["10-12", "11-15"], ["11", "14"]])
        self.assertRaises(KeyError, rn1.difference_update, rn2, strict=True)

        if sys.version_info >= (2, 5, 0):
            rn1 = RangeSetND([["10", "10-13"], ["10", "9-12"]])
            rn2 = RangeSetND([["10", "10"]])
            rn1 -= rn2
            self.assertEqual(str(rn1), "10; 9,11-13\n")
            self.assertEqual(len(rn1), 4)
            # binary error
            rn2 = set([3, 5])
            self.assertRaises(TypeError, rn1.__isub__, rn2)
开发者ID:LaHaine,项目名称:ohpc,代码行数:42,代码来源:RangeSetNDTest.py


注:本文中的ClusterShell.RangeSet.RangeSetND类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。