def test__setitem__(self): """ Tests :meth:`colour.utilities.data_structures.\ ArbitraryPrecisionMapping.__setitem__` method. """ data = {0.1999999998: 'Nemo', 0.2000000000: 'John'} mapping = ArbitraryPrecisionMapping(data, key_decimals=10) self.assertEqual(mapping, data) mapping = ArbitraryPrecisionMapping(data, key_decimals=7) self.assertListEqual(list(mapping.keys()), [0.2])
def test__len__(self): """ Tests :meth:`colour.utilities.data_structures.\ ArbitraryPrecisionMapping.__len__` method. """ data = {0.1999999998: 'Nemo', 0.2000000000: 'John'} mapping = ArbitraryPrecisionMapping(data, key_decimals=10) self.assertEqual(len(mapping), 2) mapping = ArbitraryPrecisionMapping(data, key_decimals=7) self.assertEqual(len(mapping), 1)
def test__iter__(self): """ Tests :meth:`colour.utilities.data_structures.\ ArbitraryPrecisionMapping.__iter__` method. """ data = {0.1999999998: 'Nemo', 0.2000000000: 'John'} mapping = ArbitraryPrecisionMapping(data, key_decimals=10) self.assertListEqual(sorted([item for item in mapping]), [0.1999999998, 0.2]) mapping = ArbitraryPrecisionMapping(data, key_decimals=7) self.assertListEqual(sorted([item for item in mapping]), [0.2])
def test__contains__(self): """ Tests :meth:`colour.utilities.data_structures.\ ArbitraryPrecisionMapping.__contains__` method. """ data = {0.1999999998: 'Nemo', 0.2000000000: 'John'} mapping = ArbitraryPrecisionMapping(data, key_decimals=10) self.assertIn(0.2, mapping) self.assertIn(0.1999999998, mapping) mapping = ArbitraryPrecisionMapping(data, key_decimals=7) self.assertIn(0.2, mapping) self.assertNotIn(0.1999999, mapping)
def test__delitem__(self): """ Tests :meth:`colour.utilities.data_structures.\ ArbitraryPrecisionMapping.__delitem__` method. """ data = {0.1999999998: 'Nemo', 0.2000000000: 'John'} mapping = ArbitraryPrecisionMapping(data, key_decimals=10) del mapping[0.2] self.assertNotIn(0.2, mapping) del mapping[0.1999999998] self.assertNotIn(0.1999999998, mapping) mapping = ArbitraryPrecisionMapping(data, key_decimals=7) del mapping[0.2] self.assertEqual(mapping, {})