コード例 #1
0
    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])
コード例 #2
0
    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])
コード例 #3
0
    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)
コード例 #4
0
    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])
コード例 #5
0
    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)
コード例 #6
0
    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, {})