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


Python Matrix.remove_col方法代码示例

本文整理汇总了Python中matrix.Matrix.remove_col方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.remove_col方法的具体用法?Python Matrix.remove_col怎么用?Python Matrix.remove_col使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matrix.Matrix的用法示例。


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

示例1: MatrixOffsetTest

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import remove_col [as 别名]
class MatrixOffsetTest(unittest.TestCase):

    def setUp(self):
        data = [
            ['One', 'Two', 'Three'],
            ['Aye', 'Bee', 'See']
        ]
        self.matrix = Matrix(default_item, data, offset=1)

    def test_getitem(self):
        self.assertEqual(self.matrix[1,2], 'Aye')
        self.assertEqual(self.matrix[3,1], 'Three')
        self.assertNotEqual(self.matrix[1,1], 'See')

    def test_setitem(self):
        newval = 'NEW!!'
        self.matrix[2,1] = newval
        self.assertEqual(self.matrix.data[0][1], newval)

    def test_has_coord(self):
        self.assertTrue(self.matrix.has_coord(1, 1))
        self.assertTrue(self.matrix.has_coord(3, 2))
        self.assertFalse(self.matrix.has_coord(5, 1))
        self.assertFalse(self.matrix.has_coord(2, 0))

    def test_add_row(self):
        newrow = [default_item()]*3
        data = [
            ['One', 'Two', 'Three'],
            newrow,
            ['Aye', 'Bee', 'See']
        ]
        self.matrix.add_row(2)
        self.assertEqual(self.matrix.data, data)
        data = [
            newrow,
            ['One', 'Two', 'Three'],
            newrow,
            ['Aye', 'Bee', 'See']
        ]
        self.matrix.add_row(1)
        self.assertEqual(self.matrix.data, data)
        data = [
            newrow,
            ['One', 'Two', 'Three'],
            newrow,
            ['Aye', 'Bee', 'See'],
            newrow
        ]
        self.matrix.add_row()
        self.assertEqual(self.matrix.data, data)

    def test_add_col(self):
        data = [
            ['One', default_item(), 'Two', 'Three'],
            ['Aye', default_item(), 'Bee', 'See']
        ]
        self.matrix.add_col(2)
        self.assertEqual(self.matrix.data, data)
        data = [
            [default_item(), 'One', default_item(), 'Two', 'Three'],
            [default_item(), 'Aye', default_item(), 'Bee', 'See']
        ]
        self.matrix.add_col(1)
        self.assertEqual(self.matrix.data, data)
        data = [
            [default_item(), 'One', default_item(), 'Two', 'Three', default_item()],
            [default_item(), 'Aye', default_item(), 'Bee', 'See', default_item()]
        ]
        self.matrix.add_col()
        self.assertEqual(self.matrix.data, data)

    def test_remove_row(self):
        data = [
            ['One', 'Two', 'Three']
        ]
        self.matrix.remove_row(2)
        self.assertEqual(self.matrix.data, data)

    def test_remove_col(self):
        data = [
            ['One', 'Two'],
            ['Aye', 'Bee']
        ]
        self.matrix.remove_col(3)
        self.assertEqual(self.matrix.data, data)

    def test_copy_row_down(self):
        data = [
            ['One', 'Two', 'Three'],
            ['Aye', 'Bee', 'See'],
            ['One', 'Two', 'Three']
        ]
        self.matrix.copy_row(1,3)
        self.assertEqual(self.matrix.data, data)

    def test_copy_row_up(self):
        data = [
            ['Aye', 'Bee', 'See'],
            ['One', 'Two', 'Three'],
#.........这里部分代码省略.........
开发者ID:nycz,项目名称:libsyntyche,代码行数:103,代码来源:test_matrix.py

示例2: MatrixGenericTest

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import remove_col [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(self.matrix.count_rows(), 2)

    def test_count_cols(self):
        self.assertEqual(self.matrix.count_cols(), 3)

    def test_add_row(self):
        newrow = [default_item()]*3
        data = [
            ['One', 'Two', 'Three'],
            newrow,
            ['Aye', 'Bee', 'See']
        ]
        self.matrix.add_row(1)
        self.assertEqual(self.matrix.data, data)
        data = [
            newrow,
            ['One', 'Two', 'Three'],
            newrow,
            ['Aye', 'Bee', 'See']
        ]
        self.matrix.add_row(0)
        self.assertEqual(self.matrix.data, data)
        data = [
            newrow,
            ['One', 'Two', 'Three'],
            newrow,
            ['Aye', 'Bee', 'See'],
            newrow
        ]
        self.matrix.add_row()
        self.assertEqual(self.matrix.data, data)

    def test_add_col(self):
        data = [
            ['One', default_item(), 'Two', 'Three'],
            ['Aye', default_item(), 'Bee', 'See']
        ]
        self.matrix.add_col(1)
        self.assertEqual(self.matrix.data, data)
        data = [
            [default_item(), 'One', default_item(), 'Two', 'Three'],
            [default_item(), 'Aye', default_item(), 'Bee', 'See']
        ]
        self.matrix.add_col(0)
        self.assertEqual(self.matrix.data, data)
        data = [
            [default_item(), 'One', default_item(), 'Two', 'Three', default_item()],
            [default_item(), 'Aye', default_item(), 'Bee', 'See', default_item()]
        ]
        self.matrix.add_col()
        self.assertEqual(self.matrix.data, data)

    def test_remove_row(self):
        data = [
            ['One', 'Two', 'Three']
        ]
        self.matrix.remove_row(1)
        self.assertEqual(self.matrix.data, data)

    def test_remove_col(self):
        data = [
            ['One', 'Two'],
            ['Aye', 'Bee']
        ]
        self.matrix.remove_col(2)
        self.assertEqual(self.matrix.data, data)

    def test_copy_row_down(self):
        data = [
            ['One', 'Two', 'Three'],
            ['Aye', 'Bee', 'See'],
            ['One', 'Two', 'Three']
        ]
        self.matrix.copy_row(0,2)
        self.assertEqual(self.matrix.data, data)

    def test_copy_row_up(self):
        data = [
            ['Aye', 'Bee', 'See'],
            ['One', 'Two', 'Three'],
            ['Aye', 'Bee', 'See']
        ]
        self.matrix.copy_row(1,0)
        self.assertEqual(self.matrix.data, data)

    def test_copy_col_left(self):
        data = [
            ['One', 'Three', 'Two', 'Three'],
            ['Aye', 'See', 'Bee', 'See'],
        ]
        self.matrix.copy_col(2,1)
        self.assertEqual(self.matrix.data, data)

    def test_copy_col_right(self):
        data = [
            ['One', 'Two', 'Three', 'One'],
            ['Aye', 'Bee', 'See', 'Aye'],
        ]
        self.matrix.copy_col(0,3)
        self.assertEqual(self.matrix.data, data)
开发者ID:nycz,项目名称:libsyntyche,代码行数:104,代码来源:test_matrix.py

示例3: Scene

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import remove_col [as 别名]

#.........这里部分代码省略.........
        if self.do_row(arg):
            if (0,oldpos) not in self.grid:
                self.error('Invalid row')
                return
            self.add_undo('mr', (oldpos, newpos))
            self.grid.move_row(foldpos, fnewpos)
        else:
            if (oldpos,0) not in self.grid:
                self.error('Invalid column')
                return
            self.add_undo('mc', (oldpos, newpos))
            self.grid.move_col(foldpos, fnewpos)
        self.draw_scene()

    # ======== REMOVE ========================================================
    def remove_plotline(self, pos):
        self._remove(pos, 'p')

    def remove_timeslot(self, pos):
        self._remove(pos, 't')

    def _remove(self, pos, arg):
        if self.do_row(arg):
            if (0,pos) not in self.grid:
                self.error('Invalid row')
                return
            self.add_undo('rr', (pos, self.grid.row(pos)))
            self.grid.remove_row(pos)
        else:
            if (pos,0) not in self.grid:
                self.error('Invalid column')
                return
            self.add_undo('rc', (pos, self.grid.col(pos)))
            self.grid.remove_col(pos)
        self.draw_scene()

    # ======== CELLS =========================================================
    def move_cell(self, x1, y1, x2, y2):
        if not ((x1,y1) in self.grid and (x2,y2) in self.grid):
            self.error('Invalid coordinates')
            return
        self.add_undo('mi', ((x1, y1, self.grid[x1,y1]), (x2, y2, self.grid[x2,y2])))
        self.grid[x2,y2] = self.grid[x1,y1]
        self.grid[x1,y1] = None
        self.draw_scene()

    def edit_cell(self, x, y, text):
        if (x,y) not in self.grid:
            self.error('Invalid coordinate')
            return
        if not text:
            self.prompt('e{} {} {}'.format(x, y, self.grid[x,y][0]))
            return
        self.add_undo('e', (x, y, self.grid[x,y]))
        self.set_cell(x, y, text)
        self.draw_scene()

    def clear_cell(self, x, y):
        if (x,y) not in self.grid:
            self.error('Invalid coordinate')
            return
        self.add_undo('e', (x, y, self.grid[x,y]))
        self.grid[x,y] = None
        self.draw_scene()

    def set_cell(self, x, y, name):
开发者ID:nycz,项目名称:urd,代码行数:70,代码来源:scene.py


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