5
5
6
6
class TestStringManipulation (TestCase ):
7
7
def setUp (self ) -> None :
8
- self .long_string = """ Hi! This is a long string for testing some algorithms of string manipulation. I have to
9
- test everything. So this text should contain multiple numbers like: 1, 2, 5. """
8
+ self .long_string = """ Hi! This is a long string for testing some
9
+ algorithms of string manipulation. I have to test everything. So this
10
+ text should contain multiple numbers like: 1, 2, 5. """
10
11
self .empty_string = ""
11
- self .one_word = "Alireza "
12
+ self .one_word = "Alirezaa "
12
13
13
14
def test_get_number_of_vowels (self ):
14
- self .assertEqual (45 , StringManipulation .get_number_of_vowels (self .long_string ))
15
- self .assertEqual (0 , StringManipulation .get_number_of_vowels (self .empty_string ))
16
- self .assertEqual (4 , StringManipulation .get_number_of_vowels (self .one_word ))
15
+ function = StringManipulation .get_number_of_vowels
16
+ self .assertEqual (45 , function (self .long_string ))
17
+ self .assertEqual (0 , function (self .empty_string ))
18
+ self .assertEqual (5 , function (self .one_word ))
17
19
18
20
def test_reverse (self ):
19
- self .assertEqual (self .long_string [::- 1 ], StringManipulation .reverse (self .long_string ))
20
- self .assertEqual ("" , StringManipulation .reverse (self .empty_string ))
21
- self .assertEqual (self .one_word [::- 1 ], StringManipulation .reverse (self .one_word ))
21
+ function = StringManipulation .reverse
22
+ self .assertEqual (self .long_string [::- 1 ], function (self .long_string ))
23
+ self .assertEqual ("" , function (self .empty_string ))
24
+ self .assertEqual (self .one_word [::- 1 ], function (self .one_word ))
22
25
23
26
def test_reverse_word_orders (self ):
24
- print (StringManipulation .reverse_word_orders (self .long_string ))
25
- self .assertEqual (self .empty_string , StringManipulation .reverse_word_orders (self .empty_string ))
26
- self .assertEqual (self .one_word , StringManipulation .reverse_word_orders (self .one_word ))
27
+ function = StringManipulation .reverse_word_orders
28
+ print (function (self .long_string ))
29
+ self .assertEqual (self .empty_string , function (self .empty_string ))
30
+ self .assertEqual (self .one_word , function (self .one_word ))
27
31
28
32
def base_test_is_rotation (self , function ):
29
33
self .assertTrue (function ("ABCDE" , "BCDEA" ))
@@ -38,3 +42,47 @@ def test_is_rotation(self):
38
42
39
43
def test_is_rotation_2 (self ):
40
44
self .base_test_is_rotation (StringManipulation .is_rotation_2 )
45
+
46
+ def test_remove_duplicates (self ):
47
+ function = StringManipulation .remove_duplicates
48
+ self .assertEqual (
49
+ 'Hi! Thsalongtrfem\n pu.IvySxdcbk:1,25' ,
50
+ function (self .long_string )
51
+ )
52
+ self .assertEqual (self .empty_string , function (self .empty_string ))
53
+ self .assertEqual ('Alireza' , function (self .one_word ))
54
+
55
+ def test_get_most_repeated_character (self ):
56
+ function = StringManipulation .get_most_repeated_character
57
+ self .assertEqual (" " , function (self .long_string ))
58
+ with self .assertRaises (ValueError ) as error :
59
+ function (self .empty_string )
60
+ self .assertEqual (
61
+ error .exception ,
62
+ "The string doesn't have any characters!"
63
+ )
64
+ self .assertEqual ("a" , function (self .one_word ))
65
+
66
+ def test_capitalize_first_letters (self ):
67
+ function = StringManipulation .capitalize_first_letters
68
+ print (function (self .long_string ))
69
+ self .assertEqual ("" , function (self .empty_string ))
70
+ self .assertEqual (self .one_word , function (self .one_word ))
71
+
72
+ def test_is_anagram (self ):
73
+ function = StringManipulation .is_anagram
74
+ self .assertTrue (function ("ABCD" , "BCDA" ))
75
+ self .assertFalse (function ("ABCD" , "ABCE" ))
76
+ self .assertTrue (function ("ABCD" , "ABCD" ))
77
+ self .assertTrue (function ("" , "" ))
78
+ self .assertFalse (function ("" , "B" ))
79
+ self .assertTrue (function ("A" , "A" ))
80
+
81
+ def test_is_palindrome (self ):
82
+ function = StringManipulation .is_palindrome
83
+ self .assertTrue (function ("ABbA" ))
84
+ self .assertFalse (function ("ABC" ))
85
+ self .assertTrue (function ("Was it a cat I saw?" ))
86
+ self .assertTrue (function ("" ))
87
+ self .assertFalse (function ("Ab" ))
88
+ self .assertTrue (function ("A!" ))
0 commit comments