# coding=UTF-8
#
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division, absolute_import, unicode_literals

import unittest

from glyphsLib.util import bin_to_int_list, int_list_to_bin


class UtilTest(unittest.TestCase):
    def test_bin_to_int_list(self):
        self.assertEqual([], bin_to_int_list(0))
        self.assertEqual([0], bin_to_int_list(1))
        self.assertEqual([1], bin_to_int_list(2))
        self.assertEqual([0, 1], bin_to_int_list(3))
        self.assertEqual([2], bin_to_int_list(4))
        self.assertEqual([7, 30], bin_to_int_list((1 << 7) + (1 << 30)))

    def test_int_list_to_bin(self):
        self.assertEqual(int_list_to_bin([]), 0)
        self.assertEqual(int_list_to_bin([0]), 1)
        self.assertEqual(int_list_to_bin([1]), 2)
        self.assertEqual(int_list_to_bin([0, 1]), 3)
        self.assertEqual(int_list_to_bin([2]), 4)
        self.assertEqual(int_list_to_bin([7, 30]), (1 << 7) + (1 << 30))
