Пример #1
0
from src import ComparableFarsiWord

if __name__ == '__main__':
    # 'پ' is the third character of the Farsi Alphabet, but it has a Unicode
    # value of U+067E. 'ق' is the twenty-fourth character of the Farsi
    # alphabet, and it has a unicode value of U+0642.
    #
    # Therefore, Unicode incorrectly places 'پ' AFTER 'ق'.
    #
    # Therefore, relying on Unicode to compare the words 'پارچ', ("parch", the
    # Farsi word for "jar") and'قارچ' ("gharch", the Farsi word for "mushroom")
    # will produce the incorrect result that parch comes after gharch.
    #
    # Only by using this library can a correct result be attained.

    word1 = 'پارچ'  # "parch", the Farsi word for "jar"
    word2 = 'قارچ'  # "gharch", the Farsi word

    try:
        assert word1 < word2
    except AssertionError:
        print("As expected, Unicode incorrectly thinks '%s' is " % word1 +
              "lexicographically greater than '%s'..." % word2)

    assert ComparableFarsiWord(word1) < ComparableFarsiWord(word2)
    print("Success! ComparableFarsiWords correctly determined that '%s' " %
          word1 + "is lexicographically less than '%s'." % word2)
Пример #2
0
    def test_accents_equal(self):
        word1 = ComparableFarsiWord("بودَن")
        word2 = ComparableFarsiWord("بودن")

        self.assertEqual(word1, word2)
Пример #3
0
    def test_accents_different(self):
        word1 = ComparableFarsiWord("مَرسی")
        word2 = ComparableFarsiWord("آرسی")

        self.assertGreater(word1, word2)
Пример #4
0
    def test_first_string_empty(self):
        word1 = ComparableFarsiWord("")
        word2 = ComparableFarsiWord("بودن")

        self.assertLess(word1, word2)
Пример #5
0
    def test_equal_words(self):
        word1 = ComparableFarsiWord("سنجیده بودید")
        word2 = ComparableFarsiWord("سنجیده بودید")

        self.assertEqual(word1, word2)
Пример #6
0
    def test_different_length_words(self):
        word1 = ComparableFarsiWord("تخلف کرد")
        word2 = ComparableFarsiWord("تخلف کردیم")

        self.assertLess(word1, word2)
Пример #7
0
    def test_same_length_first_char_different_2(self):
        word1 = ComparableFarsiWord("ارسی")
        word2 = ComparableFarsiWord("مرسی")

        self.assertLess(word1, word2)
Пример #8
0
    def test_same_length_last_char_different_2(self):
        word1 = ComparableFarsiWord("سنجیده بودیم")
        word2 = ComparableFarsiWord("سنجیده بودید")

        self.assertGreater(word1, word2)
Пример #9
0
    def test_both_strings_empty(self):
        word1 = ComparableFarsiWord("")
        word2 = ComparableFarsiWord("")

        self.assertEqual(word1, word2)
Пример #10
0
    def test_second_string_empty(self):
        word1 = ComparableFarsiWord("بودن")
        word2 = ComparableFarsiWord("")

        self.assertGreater(word1, word2)