コード例 #1
0
ファイル: test_misc.py プロジェクト: vikrant1717/plover
def test_popcount_8():
    for n in range(256):
        assert misc.popcount_8(n) == format(n, 'b').count('1')
    with pytest.raises(AssertionError):
        misc.popcount_8(256)
    with pytest.raises(AssertionError):
        misc.popcount_8(-1)
コード例 #2
0
        def favored_modifiers(modifier_a, modifier_b):
            """0 if they are equal, 1 if a is better, -1 if b is better"""
            a_favored_over_b = 0
            modifiers_a = KeyboardLayout._modifier_dictionary(modifier_a)
            modifiers_b = KeyboardLayout._modifier_dictionary(modifier_b)
            count_a = popcount_8(modifier_a)
            count_b = popcount_8(modifier_b)

            # Favor no CAPS modifier
            if modifiers_a[CAPS] and not modifiers_b[CAPS]:
                a_favored_over_b = -1
            elif modifiers_b[CAPS] and not modifiers_a[CAPS]:
                a_favored_over_b = 1
            # Favor no command modifier
            elif modifiers_a[COMMAND] and not modifiers_b[COMMAND]:
                a_favored_over_b = -1
            elif modifiers_b[COMMAND] and not modifiers_a[COMMAND]:
                a_favored_over_b = 1
            # Favor no control modifier
            elif modifiers_a[CONTROL] and not modifiers_b[CONTROL]:
                a_favored_over_b = -1
            elif modifiers_b[CONTROL] and not modifiers_a[CONTROL]:
                a_favored_over_b = 1
            # Finally, favor fewer modifiers
            elif count_a > count_b:
                a_favored_over_b = -1
            elif count_b > count_a:
                a_favored_over_b = 1
            return a_favored_over_b
コード例 #3
0
        def favored_modifiers(modifier_a, modifier_b):
            """0 if they are equal, 1 if a is better, -1 if b is better"""
            a_favored_over_b = 0
            modifiers_a = KeyboardLayout._modifier_dictionary(modifier_a)
            modifiers_b = KeyboardLayout._modifier_dictionary(modifier_b)
            count_a = popcount_8(modifier_a)
            count_b = popcount_8(modifier_b)

            # Favor no CAPS modifier
            if modifiers_a[CAPS] and not modifiers_b[CAPS]:
                a_favored_over_b = -1
            elif modifiers_b[CAPS] and not modifiers_a[CAPS]:
                a_favored_over_b = 1
            # Favor no command modifier
            elif modifiers_a[COMMAND] and not modifiers_b[COMMAND]:
                a_favored_over_b = -1
            elif modifiers_b[COMMAND] and not modifiers_a[COMMAND]:
                a_favored_over_b = 1
            # Favor no control modifier
            elif modifiers_a[CONTROL] and not modifiers_b[CONTROL]:
                a_favored_over_b = -1
            elif modifiers_b[CONTROL] and not modifiers_a[CONTROL]:
                a_favored_over_b = 1
            # Finally, favor fewer modifiers
            elif count_a > count_b:
                a_favored_over_b = -1
            elif count_b > count_a:
                a_favored_over_b = 1
            return a_favored_over_b
コード例 #4
0
ファイル: test_misc.py プロジェクト: rajeshm20/plover
 def test_popcount_8(self):
     for n in range(256):
         self.assertEqual(misc.popcount_8(n), format(n, 'b').count('1'))
     with self.assertRaises(AssertionError):
         misc.popcount_8(256)
     with self.assertRaises(AssertionError):
         misc.popcount_8(-1)
コード例 #5
0
ファイル: test_misc.py プロジェクト: DanLanglois/plover
def test_popcount_8():
    for n in range(256):
        assert misc.popcount_8(n) == format(n, 'b').count('1')
    with pytest.raises(AssertionError):
        misc.popcount_8(256)
    with pytest.raises(AssertionError):
        misc.popcount_8(-1)
コード例 #6
0
ファイル: test_misc.py プロジェクト: davidkitfriedman/plover
 def test_popcount_8(self):
     for n in range(256):
         self.assertEqual(misc.popcount_8(n),
                          format(n, 'b').count('1'))
     with self.assertRaises(AssertionError):
         misc.popcount_8(256)
     with self.assertRaises(AssertionError):
         misc.popcount_8(-1)
コード例 #7
0
 def sort_vk_ss_list(vk_ss_list):
     # Prefer lower modifiers combo.
     return sorted(vk_ss_list, key=lambda vk_ss: popcount_8(vk_ss[1]))