File tree 6 files changed +80
-0
lines changed
Basic string methods/tests
String negative indexing/tests
6 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -16,3 +16,15 @@ def test_out_len(self):
16
16
17
17
def test_string (self ):
18
18
self .assertEqual (correct_string , result_str , msg = 'Wrong result string.' )
19
+
20
+ def test_0_code_len (self ):
21
+ with open ("string_methods.py" , "r" ) as taskfile :
22
+ lines = taskfile .readlines ()
23
+ self .assertTrue (len (lines ) == 6 , msg = "Please do not add or remove any lines from the code file." )
24
+
25
+ def test_statement_1 (self ):
26
+ with open ("string_methods.py" , "r" ) as taskfile :
27
+ lines = taskfile .readlines ()
28
+ code = lines [- 1 ]
29
+ if not (".upper()" in code ):
30
+ self .fail (msg = "Your solution should use the function .upper()." )
Original file line number Diff line number Diff line change @@ -28,5 +28,17 @@ def test_age(self):
28
28
def test_string (self ):
29
29
self .assertIsNotNone (re .match (correct_string , result_str ), msg = 'The result string does not match the expected one.' )
30
30
31
+ def test_0_code_len (self ):
32
+ with open ("f_strings.py" , "r" ) as taskfile :
33
+ lines = taskfile .readlines ()
34
+ self .assertTrue (len (lines ) == 3 , msg = "Please do not add or remove any lines from the code file." )
35
+
36
+ def test_statement_1 (self ):
37
+ with open ("f_strings.py" , "r" ) as taskfile :
38
+ lines = taskfile .readlines ()
39
+ code = lines [- 1 ]
40
+ if not ("{name}" in code and "{age}" in code ):
41
+ self .fail (msg = "Your solution should use f-string syntax." )
42
+
31
43
32
44
Original file line number Diff line number Diff line change @@ -9,3 +9,15 @@ def test_true(self):
9
9
10
10
except ImportError :
11
11
self .assertTrue (False , msg = "Do not rename any variables." )
12
+
13
+ def test_0_code_len (self ):
14
+ with open ("in_operator.py" , "r" ) as taskfile :
15
+ lines = taskfile .readlines ()
16
+ self .assertTrue (len (lines ) == 5 , msg = "Please do not add or remove any lines from the code file." )
17
+
18
+ def test_statement_1 (self ):
19
+ with open ("in_operator.py" , "r" ) as taskfile :
20
+ lines = taskfile .readlines ()
21
+ code = lines [- 2 ]
22
+ if not ("in" in code ):
23
+ self .fail (msg = "Your solution does not use the in operator." )
Original file line number Diff line number Diff line change @@ -13,6 +13,25 @@ def test_index_type(self):
13
13
def test_index (self ):
14
14
self .assertEqual (int (len (phrase ) / 2 ), index_to_slice , msg = "You got a wrong slicing index." )
15
15
16
+ def test_0_code_len (self ):
17
+ with open ("len_function.py" , "r" ) as taskfile :
18
+ lines = taskfile .readlines ()
19
+ self .assertTrue (len (lines ) == 8 , msg = "Please do not add or remove any lines from the code file." )
20
+
21
+ def test_statement_1 (self ):
22
+ with open ("len_function.py" , "r" ) as taskfile :
23
+ lines = taskfile .readlines ()
24
+ code = lines [- 2 ]
25
+ if not ("phrase[" in code ):
26
+ self .fail (msg = "Your solution should use slicing to get half of the string." )
27
+
28
+ def test_statement_2 (self ):
29
+ with open ("len_function.py" , "r" ) as taskfile :
30
+ lines = taskfile .readlines ()
31
+ code = lines [- 3 ]
32
+ if not ("len(phrase)" in code ):
33
+ self .fail (msg = "Your solution should use the len() function to find the middle point." )
34
+
16
35
17
36
except ImportError :
18
37
class TestCase (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -9,3 +9,15 @@ def test_add(self):
9
9
10
10
except ImportError :
11
11
self .assertTrue (False , msg = "Do not rename any variables." )
12
+
13
+ def test_0_code_len (self ):
14
+ with open ("negative_indexing.py" , "r" ) as taskfile :
15
+ lines = taskfile .readlines ()
16
+ self .assertTrue (len (lines ) == 3 , msg = "Please do not add or remove any lines from the code file." )
17
+
18
+ def test_statement_1 (self ):
19
+ with open ("negative_indexing.py" , "r" ) as taskfile :
20
+ lines = taskfile .readlines ()
21
+ code = lines [- 2 ]
22
+ if not ("[-1]" in code ):
23
+ self .fail (msg = "Your solution does not use string indexing." )
Original file line number Diff line number Diff line change @@ -10,7 +10,20 @@ def test_string(self):
10
10
def test_space (self ):
11
11
self .assertFalse (' ' in python , msg = "Do not include the space in the result string." )
12
12
13
+ def test_0_code_len (self ):
14
+ with open ("slicing.py" , "r" ) as taskfile :
15
+ lines = taskfile .readlines ()
16
+ self .assertTrue (len (lines ) == 6 , msg = "Please do not add or remove any lines from the code file." )
17
+
18
+ def test_statement_1 (self ):
19
+ with open ("slicing.py" , "r" ) as taskfile :
20
+ lines = taskfile .readlines ()
21
+ code = lines [- 2 ]
22
+ if not ("[6:]" in code ):
23
+ self .fail (msg = "Your solution does not use string slicing." )
24
+
13
25
except ImportError :
14
26
class TestCase (unittest .TestCase ):
15
27
def test_fail (self ):
16
28
self .assertTrue (False , msg = "Do not rename any variables." )
29
+
You can’t perform that action at this time.
0 commit comments