本文整理汇总了Python中memory.Memory.setByte方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.setByte方法的具体用法?Python Memory.setByte怎么用?Python Memory.setByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类memory.Memory
的用法示例。
在下文中一共展示了Memory.setByte方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MemoryTest
# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import setByte [as 别名]
class MemoryTest(unittest.TestCase):
MEM_SIZE = 4096
MEM_VALUE = 0xFF
MEM_ADDRESS = 0x10
MEM_ADDRESS_WRONG_LOW = -1
MEM_ADDRESS_WRONG_HIGH = 4906
def setUp(self):
self.memory = Memory(self.MEM_SIZE)
def tearDown(self):
pass
def testShouldReadCorrectBytes(self):
self.memory.setByte(self.MEM_ADDRESS, self.MEM_VALUE)
byte = self.memory.getByte(self.MEM_ADDRESS)
self.assertEqual(byte, self.MEM_VALUE)
def testShouldWriteCorrectBytes(self):
self.memory.setByte(self.MEM_ADDRESS, self.MEM_VALUE)
byte = self.memory.getByte(self.MEM_ADDRESS)
self.assertEqual(byte, self.MEM_VALUE)
def testShouldRaiseErrorOnIllegalMemoryAddressWrite(self):
with self.assertRaises(IndexError):
self.memory.setByte(self.MEM_ADDRESS_WRONG_LOW, self.MEM_VALUE)
with self.assertRaises(IndexError):
self.memory.setByte(self.MEM_ADDRESS_WRONG_HIGH, self.MEM_VALUE)
def testShouldRaiseErrorOnIllegalMemoryAddressRead(self):
with self.assertRaises(IndexError):
self.memory.getByte(self.MEM_ADDRESS_WRONG_LOW)
with self.assertRaises(IndexError):
self.memory.getByte(self.MEM_ADDRESS_WRONG_HIGH)
def testShouldReserveEnoughMemory(self):
self.assertEqual(len(self.memory.memory), self.MEM_SIZE)