|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
| 3 | +from test.helper import check_evaluation |
3 | 4 |
|
4 | 5 | from mathics.core.expression import Expression |
5 | 6 | from mathics.core.symbols import Symbol, SymbolPlus, SymbolTimes |
6 | 7 |
|
7 | 8 |
|
| 9 | +def test_sort_wma(): |
| 10 | + """Test the alphabetic order in WMA for Strings and Symbols""" |
| 11 | + # In Python, str are ordered as tuples of |
| 12 | + # ascii codes of the characters. So, |
| 13 | + # |
| 14 | + # "Abeja" <"Ave"<"aVe"<"abeja" |
| 15 | + # |
| 16 | + # In WMA, strings and symbols are sorted in alphabetical order, with |
| 17 | + # lowercaps characters coming before than the corresponding upper case. |
| 18 | + # Then, the same words are sorted in WMA as |
| 19 | + # |
| 20 | + # "abeja"< "Abeja"<"aVe"<"Ave" |
| 21 | + # |
| 22 | + # Such order is equivalent to use |
| 23 | + # `lambda s: (s.lower(), s.swapcaps(),)` as sort key. |
| 24 | + # |
| 25 | + # Finally, String atoms comes before than Symbols. The following test |
| 26 | + # reinforce this order. |
| 27 | + str_expr = ( |
| 28 | + '{"Ave", "aVe", "abeja", AVe, ave, aVe, "Abeja", "ABEJA", ' |
| 29 | + '"AVe", "ave del paraíso", "Ave del paraíso", ' |
| 30 | + '"Ave del Paraíso"} // Sort // InputForm' |
| 31 | + ) |
| 32 | + str_expected = ( |
| 33 | + '{"abeja", "Abeja", "ABEJA", "aVe", "Ave", "AVe", ' |
| 34 | + '"ave del paraíso", "Ave del paraíso", "Ave del Paraíso", ' |
| 35 | + "ave, aVe, AVe}//InputForm" |
| 36 | + ) |
| 37 | + check_evaluation( |
| 38 | + str_expr, |
| 39 | + str_expected, |
| 40 | + # to_string_expr=True, |
| 41 | + # to_string_expected=True, |
| 42 | + # hold_expected=True, |
| 43 | + failure_message="WMA order", |
| 44 | + ) |
| 45 | + |
| 46 | + |
8 | 47 | def test_Expression_sameQ(): |
9 | 48 | """ |
10 | 49 | Test Expression.SameQ |
|
0 commit comments