1
+ from words import sort_words_case_insensitively
2
+
3
+
4
+ def test_sort_words_case_insensitively ():
5
+ words = ("It's almost Holidays and PyBites wishes You a "
6
+ "Merry Christmas and a Happy 2019" ).split ()
7
+ actual = sort_words_case_insensitively (words )
8
+ expected = ['a' , 'a' , 'almost' , 'and' , 'and' , 'Christmas' ,
9
+ 'Happy' , 'Holidays' , "It's" , 'Merry' , 'PyBites' ,
10
+ 'wishes' , 'You' , '2019' ]
11
+ assert actual == expected
12
+
13
+
14
+ def test_sort_words_case_insensitively_another_phrase ():
15
+ words = ("Andrew Carnegie's 64-room chateau at 2 East 91st "
16
+ "Street was converted into the Cooper-Hewitt National "
17
+ "Design Museum of the Smithsonian Institution "
18
+ "in the 1970's" ).split ()
19
+ actual = sort_words_case_insensitively (words )
20
+ expected = ['Andrew' , 'at' , "Carnegie's" , 'chateau' , 'converted' ,
21
+ 'Cooper-Hewitt' , 'Design' , 'East' , 'in' , 'Institution' ,
22
+ 'into' , 'Museum' , 'National' , 'of' , 'Smithsonian' ,
23
+ 'Street' , 'the' , 'the' , 'the' , 'was' , "1970's" , '2' ,
24
+ '64-room' , '91st' ]
25
+ assert actual == expected
26
+
27
+
28
+ def test_digit_inside_word_does_not_matter ():
29
+ """We only care about the first char being a number"""
30
+ words = ("It was the twenty9th of October when it was questioned"
31
+ "the meaning of nuMbers and weather hiding a number Inside"
32
+ "tex56t should be treated as a word or another number" ).split ()
33
+ actual = sort_words_case_insensitively (words )
34
+ expected = ['a' , 'a' , 'and' , 'another' , 'as' , 'be' , 'hiding' ,
35
+ 'Insidetex56t' , 'It' , 'it' , 'meaning' , 'number' , 'number' ,
36
+ 'nuMbers' , 'October' , 'of' , 'of' , 'or' , 'questionedthe' ,
37
+ 'should' , 'the' , 'treated' , 'twenty9th' , 'was' ,
38
+ 'was' , 'weather' , 'when' , 'word' ]
39
+ assert actual == expected
40
+
41
+
42
+ def test_words_with_mixed_chars_and_digits ():
43
+ words = ("Let's see how4 this 1sorts, hope it works 4 this "
44
+ "B1te 22 55abc abc55" ).split ()
45
+ actual = sort_words_case_insensitively (words )
46
+ expected = ['abc55' , 'B1te' , 'hope' , 'how4' , 'it' , "Let's" , 'see' ,
47
+ 'this' , 'this' , 'works' , '1sorts,' , '22' , '4' , '55abc' ]
48
+ assert actual == expected
0 commit comments