Improved portability between Python 2 and Python 3. Beginnings of code for writing SEG Y.

This commit is contained in:
Robert Smallshire
2014-10-21 14:54:49 +02:00
parent 1abff28a40
commit ee228e2dc9
9 changed files with 274 additions and 23 deletions
+50
View File
@@ -0,0 +1,50 @@
import unittest
from ibm_float import ieee2ibm, ibm2ieee
class Ibm2Ieee(unittest.TestCase):
def test_zero(self):
self.assertEqual(ibm2ieee(b'\0\0\0\0'), 0.0)
def test_positive_half(self):
self.assertEqual(ibm2ieee((0b11000000, 0x80, 0x00, 0x00)), -0.5)
def test_negative_half(self):
self.assertEqual(ibm2ieee((0b01000000, 0x80, 0x00, 0x00)), 0.5)
def test_one(self):
self.assertEqual(ibm2ieee(b'\x41\x10\x00\x00'), 1.0)
def test_negative_118_625(self):
# Example taken from Wikipedia http://en.wikipedia.org/wiki/IBM_Floating_Point_Architecture
self.assertEqual(ibm2ieee((0b11000010, 0b01110110, 0b10100000, 0b00000000)), -118.625)
class Ieee2Ibm(unittest.TestCase):
def test_zero(self):
self.assertEqual(ieee2ibm(0.0), b'\0\0\0\0')
def test_positive_half(self):
self.assertEqual(ieee2ibm(-0.5), bytes((0b11000000, 0x80, 0x00, 0x00)))
def test_negative_half(self):
self.assertEqual(ieee2ibm(0.5), bytes((0b01000000, 0x80, 0x00, 0x00)))
def test_one(self):
self.assertEqual(ieee2ibm(1.0), b'\x41\x10\x00\x00')
def test_negative_118_625(self):
# Example taken from Wikipedia http://en.wikipedia.org/wiki/IBM_Floating_Point_Architecture
self.assertEqual(ieee2ibm(-118.625), bytes((0b11000010, 0b01110110, 0b10100000, 0b00000000)))
def test_0_1(self):
# Note, this is different from the Wikipedia example, but I'll stick my neck out and say
# Wikipedia is wrong.
self.assertEqual(ieee2ibm(0.1), bytes((0b01000000, 0b00011001, 0b10011001, 0b10011001)))
if __name__ == '__main__':
unittest.main()