Skip to content

Commit 07e7aa6

Browse files
committed
Added more tests other tasks in Strings
1 parent 7b097a8 commit 07e7aa6

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

Strings/Basic string methods/tests/test_task.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ def test_out_len(self):
1616

1717
def test_string(self):
1818
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().")

Strings/F-strings/tests/test_task.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,17 @@ def test_age(self):
2828
def test_string(self):
2929
self.assertIsNotNone(re.match(correct_string, result_str), msg='The result string does not match the expected one.')
3030

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+
3143

3244

Strings/In operator/tests/test_task.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ def test_true(self):
99

1010
except ImportError:
1111
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.")

Strings/String length/tests/test_task.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ def test_index_type(self):
1313
def test_index(self):
1414
self.assertEqual(int(len(phrase) / 2), index_to_slice, msg="You got a wrong slicing index.")
1515

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+
1635

1736
except ImportError:
1837
class TestCase(unittest.TestCase):

Strings/String negative indexing/tests/test_task.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ def test_add(self):
99

1010
except ImportError:
1111
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.")

Strings/String slicing/tests/test_task.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@ def test_string(self):
1010
def test_space(self):
1111
self.assertFalse(' ' in python, msg="Do not include the space in the result string.")
1212

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+
1325
except ImportError:
1426
class TestCase(unittest.TestCase):
1527
def test_fail(self):
1628
self.assertTrue(False, msg="Do not rename any variables.")
29+

0 commit comments

Comments
 (0)