本文整理汇总了Python中field.Field.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Field.copy方法的具体用法?Python Field.copy怎么用?Python Field.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field.Field
的用法示例。
在下文中一共展示了Field.copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Regression
# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import copy [as 别名]
#.........这里部分代码省略.........
for i, b_data in enumerate(self.raw_data):
b = Block(b_data["type"], b_data["conns"], b_data["name"], b_data["groups"])
b.rotate(b_data["rot"])
b.mirror(set_to=b_data["mir"])
self.field.add_block(b, b_data["pos"])
self.assertEqual(len(self.field), len(self.raw_data))
def test_block_move(self):
self.test_add_blocks()
blk = filter(lambda a: a.name == "m3", self.field.get_blocks())
self.assertEqual(len(blk), 1)
blk = blk[0]
pos = (6, 0)
self.assertTrue(self.field.move(blk, pos))
self.assertEqual(self.field.get_block_pos(blk), pos)
def test_block_swap(self):
self.test_add_blocks()
name2blk = dict((b.name, b) for b in self.field.get_blocks())
self.assertTrue(
self.field.swap(name2blk["m1"], name2blk["m2"])
)
def test_field_copy_roundtrip(self):
self.test_add_blocks()
f1 = self.field.copy()
self.test_add_blocks()
f2 = self.field.copy()
list_props = lambda blks, prop: tuple(sorted(getattr(blk, prop) for blk in blks))
bl1 = f1.get_blocks()
bl2 = f2.get_blocks()
for pname in ["name", "groups", "type"]:
self.assertSequenceEqual(list_props(bl1, pname), list_props(bl2, pname))
self.assertEqual(f1.ny, f2.ny)
self.assertEqual(f1.nx, f2.nx)
self.assertEqual(len(f1.block2xy), len(f2.block2xy))
self.assertEqual(len(f1.block2yx), len(f2.block2yx))
self.assertEqual(len(f1.xy2block), len(f2.xy2block))
self.assertEqual(len(f1.yx2block), len(f2.yx2block))
def test_field_finalization(self):
self.test_add_blocks()
self.field.optimize_size()
# no error is good at this point
self.assertTrue(True)
def test_expansion(self):
self.test_field_finalization()
nx, ny = self.field.nx, self.field.ny