def test_Equality(self): test = btk.btkMetaDataInfo(1.435) test2 = btk.btkMetaDataInfo(1.435) self.assertTrue(test == test2) test2.SetValues('Allo') self.assertTrue(test != test2) test2.SetValues(1.435) self.assertTrue(test == test2) test2.SetValues(2.5) self.assertTrue(test != test2) test.SetValues(btk.btkIntArray(5,5)) test2.SetValues(btk.btkIntArray(5,5)) self.assertTrue(test == test2) test2.SetValue(0, 15) self.assertTrue(test != test2)
def test_SetDimensionForChar(self): test = btk.btkMetaDataInfo(btk.btkIntArray(2,5), btk.btkStringArray(5, 'test ')) test.SetDimension(0, 2) self.assertEqual(len(test.GetDimensions()), 2) self.assertEqual(test.GetValueNumber(), 5) for i in range(0,5): self.assertEqual(test.ToString(i), 'te')
def test_ResizeDimensionsFrom3To1Float(self): dim = btk.btkIntArray(3, 3) val = btk.btkDoubleArray(27, 1.950) test = btk.btkMetaDataInfo(dim, val) test.ResizeDimensions(1) self.assertEqual(len(test.GetDimensions()), 1) self.assertEqual(test.GetValueNumber(), 3)
def test_SetValueDoubleInInt8(self): test = btk.btkMetaDataInfo(5) test.SetFormat(btk.btkMetaDataInfo.Byte) test.SetValue(0, 1.23456789) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Byte) self.assertEqual(len(test.GetDimensions()), 0) self.assertEqual(test.ToInt(0), 1)
def test_SetValueCharInInt8_Number(self): test = btk.btkMetaDataInfo(5) test.SetFormat(btk.btkMetaDataInfo.Byte) test.SetValue(0, '45') self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Byte) self.assertEqual(len(test.GetDimensions()), 0) self.assertEqual(test.ToInt(0), 45)
def test_ConstructorVectorCharResizeEmptyDim2(self): test = btk.btkMetaDataInfo([5,5],btk.btkStringArray()) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(test.GetDimensions()), 2) self.assertEqual(test.GetValueNumber(), 5) for i in range(0,5): self.assertEqual(test.ToString(i), ' ')
def test_resize_upper(self): i = btk.btkMetaDataInfo([5], ['test', 'test', 'test', 'test']) self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(i.GetDimensions()), 1) self.assertEqual(i.GetDimensionsProduct(), 5) self.assertEqual(len(i.ToInt()), 1) self.assertEqual(i.ToString(0), 'test ')
def test_Integer2Byte(self): test = btk.btkMetaDataInfo(btk.btkIntArray(5, 379)) test.SetFormat(btk.btkMetaDataInfo.Byte) val = test.ToInt() self.assertEqual(len(val), 5) for i in range(0,5): self.assertEqual(val[i], 123)
def test_SetValueIntInInt8(self): # Modified as this value is casted to a float and then loss in precision test = btk.btkMetaDataInfo(5) test.SetFormat(btk.btkMetaDataInfo.Byte) test.SetValue(0, 1234567) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Byte) self.assertEqual(len(test.GetDimensions()), 0) # self.assertEqual(test.ToInt(0), 135) # Python seems use another cycling roudning (opposite?) self.assertEqual(test.ToInt(0), -121)
def test_Clone(self): test = btk.btkMetaDataInfo(1.435) test2 = test.Clone() test2.SetValues('test') self.assertAlmostEqual(test.ToDouble(0), 1.435, 5) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Real) self.assertEqual(test2.ToString(0), 'test') self.assertEqual(test2.GetFormat(), btk.btkMetaDataInfo.Char)
def test_SetValueInt16InInt8(self): test = btk.btkMetaDataInfo(5) test.SetFormat(btk.btkMetaDataInfo.Byte) test.SetValue(0, 12456) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Byte) self.assertEqual(len(test.GetDimensions()), 0) #self.assertEqual(test.ToInt(0), 168) # Python seems use another cycling rounging (opposite?) self.assertEqual(test.ToInt(0), -88)
def test_ConstructorVectorCharResizeLowerDim2(self): dim = [2,2] val = ['test','test','test','test'] test = btk.btkMetaDataInfo(dim,val) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(test.GetDimensions()), 2) self.assertEqual(test.GetValueNumber(), 2) self.assertEqual(test.ToString(0), 'te') self.assertEqual(test.ToString(1), 'te')
def test_SetFormatFloat2CharDim1(self): test = btk.btkMetaDataInfo([], [1.95]) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Real) test.SetFormat(btk.btkMetaDataInfo.Char) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(test.GetDimensions()), 1) self.assertEqual(test.GetDimensions()[0], 4) self.assertEqual(test.GetValueNumber(), 1) self.assertEqual(test.ToString(0), '1.95')
def test_ConstructorVectorCharResizeUpperDim2(self): dim = [5,5] val = ['test','test','test','test'] test = btk.btkMetaDataInfo(dim,val) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(test.GetDimensions()), 2) self.assertEqual(test.GetValueNumber(), 5) for i in range(0,4): self.assertEqual(test.ToString(i), 'test ') self.assertEqual(test.ToString(4), ' ')
def test_SetFormatFloat2Integer(self): dim = btk.btkIntArray(2, 5) val = btk.btkDoubleArray(25, 1.950) test = btk.btkMetaDataInfo(dim, val) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Real) test.SetFormat(btk.btkMetaDataInfo.Integer) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Integer) self.assertEqual(len(test.GetDimensions()), 2) self.assertEqual(test.GetValueNumber(), 25) for i in range(0,25): self.assertEqual(test.ToInt(i), 1)
def test_SetFormatChar2Integer(self): # dim = btk.btkIntArray(2, 5) # val = btk.btkStringArray(4, 'test') # test = btk.btkMetaDataInfo(dim, val) test = btk.btkMetaDataInfo([5,5], ['test','test','test','test']) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Char) test.SetFormat(btk.btkMetaDataInfo.Integer) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Integer) self.assertEqual(len(test.GetDimensions()), 1) self.assertEqual(test.GetValueNumber(), 5) for i in range(0,5): self.assertEqual(test.ToInt(i), 0)
def test_SetValuesFromVectorString(self): test = btk.btkMetaDataInfo(['NAME', 'CALIBRATION', 'FULL_DESCRIPTION', 'SETUP', 'DATE']) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(test.GetDimensions()), 2) self.assertEqual(test.GetDimension(0), 16) self.assertEqual(test.GetDimension(1), 5) self.assertEqual(test.GetValueNumber(), 5) self.assertEqual(test.ToString(0), 'NAME ') self.assertEqual(test.ToString(1), 'CALIBRATION ') self.assertEqual(test.ToString(2), 'FULL_DESCRIPTION') self.assertEqual(test.ToString(3), 'SETUP ') self.assertEqual(test.ToString(4), 'DATE ')
def test_SetDimensionForFloat(self): dim = [5,5] val = btk.btkDoubleArray(25, 1.950) test = btk.btkMetaDataInfo(dim, val) test.SetDimension(0, 6) self.assertEqual(len(test.GetDimensions()), 2) self.assertEqual(test.GetValueNumber(), 30) for i in range(0,5): self.assertEqual(test.ToDouble(i*6+5), 0.0) test.SetDimension(1, 6) self.assertEqual(test.GetValueNumber(), 36) for i in range(30,35): self.assertEqual(test.ToDouble(i), 0.0)
def test_SetFormatFloat2CharDim2(self): dim = [5,5] val = btk.btkDoubleArray(25, 1.95) test = btk.btkMetaDataInfo(dim, val) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Real) test.SetFormat(btk.btkMetaDataInfo.Char) self.assertEqual(test.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(test.GetDimensions()), 3) self.assertEqual(test.GetDimensions()[0], 4) self.assertEqual(test.GetDimensions()[1], 5) self.assertEqual(test.GetDimensions()[2], 5) self.assertEqual(test.GetValueNumber(), 25) for i in range(0,25): self.assertEqual(test.ToString(i), '1.95')
def test_ctor_int(self): i = btk.btkMetaDataInfo(5) self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Integer) self.assertEqual(len(i.GetDimensions()), 0) self.assertEqual(i.GetDimensionsProduct(), 1) self.assertEqual(i.ToInt(0), 5) self.assertEqual(i.ToDouble(0), 5.0) self.assertEqual(i.ToString(0), '5') v = i.ToInt() self.assertEqual(len(v), 1) self.assertEqual(v[0], 5) v = i.ToDouble() self.assertEqual(len(v), 1) self.assertEqual(v[0], 5.0) v = i.ToString() self.assertEqual(len(v), 1) self.assertEqual(v[0], '5')
def test_ctor_string_bis(self): i = btk.btkMetaDataInfo('45.25') self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(i.GetDimensions()), 1) self.assertEqual(i.GetDimension(0), 5) self.assertEqual(i.GetDimensionsProduct(), 5) self.assertEqual(i.ToInt(0), 45) self.assertEqual(i.ToDouble(0), 45.25) self.assertEqual(i.ToString(0), '45.25') v = i.ToInt() self.assertEqual(len(v), 1) self.assertEqual(v[0], 45) v = i.ToDouble() self.assertEqual(len(v), 1) self.assertEqual(v[0], 45.25) v = i.ToString() self.assertEqual(len(v), 1) self.assertEqual(v[0], '45.25')
def test_ctor_double_vector1D(self): i = btk.btkMetaDataInfo([1.5,2.5,3.5,4.5]) self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Real) self.assertEqual(len(i.GetDimensions()), 1) self.assertEqual(i.GetDimension(0), 4) self.assertEqual(i.GetDimensionsProduct(), 4) v1 = i.ToInt() v2 = i.ToDouble() v3 = i.ToString() self.assertEqual(len(v1), 4) self.assertEqual(len(v2), 4) self.assertEqual(len(v3), 4) for j in range(0,4): self.assertEqual(i.ToInt(j), j + 1) self.assertEqual(i.ToDouble(j), float(j + 1.5)) self.assertEqual(i.ToString(j), str(j + 1.5)) self.assertEqual(v1[j], j + 1) self.assertEqual(v2[j], float(j + 1.5)) self.assertEqual(v3[j], str(j + 1.5))
def test_setFormat_charToByte(self): i = btk.btkMetaDataInfo('Hello') self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Char) i.SetFormat(btk.btkMetaDataInfo.Byte) self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Byte) self.assertEqual(len(i.GetDimensions()), 0) self.assertEqual(i.GetDimensionsProduct(), 1) v1 = i.ToInt() v2 = i.ToDouble() v3 = i.ToString() self.assertEqual(len(v1), 1) self.assertEqual(len(v2), 1) self.assertEqual(len(v3), 1) self.assertEqual(i.ToInt(0), 0) self.assertEqual(i.ToDouble(0), 0.0) self.assertEqual(i.ToString(0), '0') self.assertEqual(v1[0], 0) self.assertEqual(v2[0], 0.0) self.assertEqual(v3[0], '0')
def test_setFormat_charToReal(self): i = btk.btkMetaDataInfo('45.45') self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Char) i.SetFormat(btk.btkMetaDataInfo.Real) self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Real) self.assertEqual(len(i.GetDimensions()), 0) self.assertEqual(i.GetDimensionsProduct(), 1) v1 = i.ToInt() v2 = i.ToDouble() v3 = i.ToString() self.assertEqual(len(v1), 1) self.assertEqual(len(v2), 1) self.assertEqual(len(v3), 1) self.assertEqual(i.ToInt(0), 45) self.assertAlmostEqual(i.ToDouble(0), 45.45, 5) self.assertEqual(i.ToString(0), '45.45') self.assertEqual(v1[0], 45) self.assertAlmostEqual(v2[0], 45.45, 5) self.assertEqual(v3[0], '45.45')
def test_Real2String2Real_Number(self): test = btk.btkMetaDataInfo(btk.btkDoubleArray(5, 1.2345)) self.assertEqual(len(test.GetDimensions()), 1) self.assertEqual(test.GetDimensions()[0], 5) test.SetFormat(btk.btkMetaDataInfo.Char) self.assertEqual(len(test.GetDimensions()), 2) self.assertEqual(test.GetDimensions()[0], 6) self.assertEqual(test.GetDimensions()[1], 5) val = test.ToString() self.assertEqual(len(val), 5) for i in range(0,5): self.assertEqual(val[i], '1.2345') test.SetFormat(btk.btkMetaDataInfo.Real) self.assertEqual(len(test.GetDimensions()), 1) self.assertEqual(test.GetDimensions()[0], 5) val2 = test.ToDouble() self.assertEqual(len(val2), 5) for i in range(0,5): self.assertAlmostEqual(val2[i], 1.2345, 5)
def test_ctor_int_vector2D(self): i = btk.btkMetaDataInfo([2,2], [1,2,3,4]) self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Integer) self.assertEqual(len(i.GetDimensions()), 2) self.assertEqual(i.GetDimension(0), 2) self.assertEqual(i.GetDimension(1), 2) self.assertEqual(i.GetDimensionsProduct(), 4) v1 = i.ToInt() v2 = i.ToDouble() v3 = i.ToString() self.assertEqual(len(v1), 4) self.assertEqual(len(v2), 4) self.assertEqual(len(v3), 4) for j in range(0,4): self.assertEqual(i.ToInt(j), j + 1) self.assertEqual(i.ToDouble(j), float(j + 1)) self.assertEqual(i.ToString(j), str(j + 1)) self.assertEqual(v1[j], j + 1) self.assertEqual(v2[j], float(j + 1)) self.assertEqual(v3[j], str(j + 1))
def test_ctor_string_vector1D(self): i = btk.btkMetaDataInfo(['FOO', 'BAR', 'FOOBAR']) self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(i.GetDimensions()), 2) self.assertEqual(i.GetDimension(0), 6) self.assertEqual(i.GetDimension(1), 3) self.assertEqual(i.GetDimensionsProduct(), 18) v1 = i.ToInt() v2 = i.ToDouble() v3 = i.ToString() self.assertEqual(len(v1), 3) self.assertEqual(len(v2), 3) self.assertEqual(len(v3), 3) for j in range(0, 3): self.assertEqual(i.ToInt(j), 0) self.assertEqual(i.ToDouble(j), 0) self.assertEqual(v1[j], 0) self.assertEqual(v2[j], 0) self.assertEqual(i.ToString(0), 'FOO ') self.assertEqual(v3[0], 'FOO ') self.assertEqual(i.ToString(1), 'BAR ') self.assertEqual(v3[1], 'BAR ') self.assertEqual(i.ToString(2), 'FOOBAR') self.assertEqual(v3[2], 'FOOBAR')
def test_ctor_string_vector1D(self): i = btk.btkMetaDataInfo(['FOO', 'BAR', 'FOOBAR']) self.assertEqual(i.GetFormat(), btk.btkMetaDataInfo.Char) self.assertEqual(len(i.GetDimensions()), 2) self.assertEqual(i.GetDimension(0), 6) self.assertEqual(i.GetDimension(1), 3) self.assertEqual(i.GetDimensionsProduct(), 18) v1 = i.ToInt() v2 = i.ToDouble() v3 = i.ToString() self.assertEqual(len(v1), 3) self.assertEqual(len(v2), 3) self.assertEqual(len(v3), 3) for j in range(0,3): self.assertEqual(i.ToInt(j), 0) self.assertEqual(i.ToDouble(j), 0) self.assertEqual(v1[j], 0) self.assertEqual(v2[j], 0) self.assertEqual(i.ToString(0), 'FOO ') self.assertEqual(v3[0], 'FOO ') self.assertEqual(i.ToString(1), 'BAR ') self.assertEqual(v3[1], 'BAR ') self.assertEqual(i.ToString(2), 'FOOBAR') self.assertEqual(v3[2], 'FOOBAR')
def test_String2Integer_Number(self): test = btk.btkMetaDataInfo(btk.btkStringArray(5, '12345')) val = test.ToInt() self.assertEqual(len(val), 5) for i in range(0,5): self.assertEqual(val[i], 12345)
def test_SetInfo(self): test = btk.btkMetaData('Channel') test.SetInfo(btk.btkMetaDataInfo(8)) self.assertEqual(test.HasInfo(), True) self.assertEqual(test.GetInfo().ToInt(0), 8)
def test_String2Real_Number(self): test = btk.btkMetaDataInfo(btk.btkStringArray(5, '1.2345')) val = test.ToDouble() self.assertEqual(len(val), 5) for i in range(0,5): self.assertEqual(val[i], 1.2345)