ii-vision/transcoder/opcodes_test.py

48 lines
1.4 KiB
Python
Raw Normal View History

2019-03-21 16:42:47 +00:00
"""Tests for the opcodes module."""
import unittest
import opcodes
class TestOpcodes(unittest.TestCase):
def test_equality(self):
op1 = opcodes.Terminate()
op2 = opcodes.Terminate()
self.assertEqual(op1, op2)
2019-03-23 22:05:36 +00:00
op1 = opcodes.Nop()
op2 = opcodes.Nop()
self.assertEqual(op1, op2)
2019-03-23 22:05:36 +00:00
op1 = opcodes.Ack()
op2 = opcodes.Ack()
self.assertEqual(op1, op2)
op1 = opcodes.Ack()
op2 = opcodes.Nop()
self.assertNotEqual(op1, op2)
2019-03-23 22:05:36 +00:00
op1 = opcodes.TICK_OPCODES[(4, 32)](0xff, [0x01, 0x02, 0x03, 0x04])
op2 = opcodes.TICK_OPCODES[(4, 32)](0xff, [0x01, 0x02, 0x03, 0x04])
self.assertEqual(op1, op2)
# op2 has same payload but different opcode
op1 = opcodes.TICK_OPCODES[(4, 32)](0xff, [0x01, 0x02, 0x03, 0x04])
op2 = opcodes.TICK_OPCODES[(6, 32)](0xff, [0x01, 0x02, 0x03, 0x04])
self.assertNotEqual(op1, op2)
# op2 has different content byte
op1 = opcodes.TICK_OPCODES[(4, 32)](0xff, [0x01, 0x02, 0x03, 0x04])
op2 = opcodes.TICK_OPCODES[(4, 32)](0xfe, [0x01, 0x02, 0x03, 0x04])
self.assertNotEqual(op1, op2)
# op2 has different offsets
op1 = opcodes.TICK_OPCODES[(4, 32)](0xff, [0x01, 0x02, 0x03, 0x04])
op2 = opcodes.TICK_OPCODES[(4, 32)](0xff, [0x01, 0x02, 0x03, 0x05])
self.assertNotEqual(op1, op2)
if __name__ == '__main__':
unittest.main()