Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sofia/fix some tests #137

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions Condition expressions/Boolean operators order/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ boolean operators: `not` is evaluated first, `and` is evaluated next, and `or` i

Write an expression that evaluates to `True` if `name` is either `"John"` or `"Jane"` who are `16` or older, but younger than `25`.

Please do not add any extra lines to the code.

<div class='hint'>Combine the <code>and</code> and <code>or</code> keywords.</div>
31 changes: 18 additions & 13 deletions Condition expressions/Boolean operators order/tests/test_task.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import unittest
import contextlib
import io

f = io.StringIO()
with contextlib.redirect_stdout(f):
import boolean_order
output = f.getvalue().split('\n')
result = output[2]


class TestCase(unittest.TestCase):
def test_out_len(self):
self.assertEqual(4, len(output), msg='Please do not remove or add any print statements.')
def test_0_code_len(self):
with open("boolean_order.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 8, msg="Please do not add or remove any lines from the code file.")

def test_statement_0(self):
name = "John"
age = 17
with open("boolean_order.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-1][6:-2]
self.assertTrue(eval(code), msg="Your expression does not evaluate to True")

def test_out_str(self):
self.assertEqual('True', result, msg='Your expression does not seem to produce the correct result.')
def test_statement_1(self):
with open("boolean_order.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-1][6:-2]
if not ("Jane" in code and "John" in code and "age" in code and "name" in code):
self.fail(msg="Your expression does not check the values of the variables")
2 changes: 2 additions & 0 deletions Condition expressions/Boolean operators/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ of `or` is `True`. The boolean operator `not` inverts the boolean expression it
Write an expression that evaluates to `True` if `name` is equal to `"John"` and
he is `16` or older.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like too strict instruction.
Maybe something like "...do not add any print statements not related to the task?"


<div class='hint'>Use the <code>and</code> keyword and the <code>>=</code> operator.</div>
15 changes: 14 additions & 1 deletion Condition expressions/Boolean operators/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ def test_out_len(self):
self.assertEqual(3, len(output), msg='Please do not remove or add any print statements.')

def test_out_str(self):
self.assertEqual('True', result, msg='Your expression does not seem to produce the correct result.')
self.assertEqual('True', result, msg='Your expression does not seem to produce the correct result.')


def test_0_code_len(self):
with open("boolean_operators.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 6, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("boolean_operators.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-1]
if not ('==' in code and "and" in code and ">=" in code):
self.fail(msg="Your solution should evaluate the variables name and age.")
2 changes: 2 additions & 0 deletions Data structures/Dictionaries/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ Add Jared's (`"Jared"`) number `570` to the phone book.
Remove Gerard's number from the phone book.
Print Jane's phone number from the `phone_book`.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, let's think of a less restrictive wording


<div class='hint'>Use dictionary indexing, e.g., <code>dct[key]</code></div>
11 changes: 11 additions & 0 deletions Data structures/Dictionaries/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ def test_dict(self):
self.assertEqual({'Jane': 234, 'Jill': 345, 'Jared': 570}, phone_book,
msg="Your resulting dictionary seems to be off.")

def test_0_code_len(self):
with open("dicts.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 18, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("dicts.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-6]
if not ('phone_book["Jared"]' in code or "phone_book['Jared']" in code):
self.fail(msg="Your solution should use dictionary indexing to get Jared's phone.")
1 change: 1 addition & 0 deletions Data structures/In keyword/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ item. You can apply `in` to lists or dictionaries the same way you did it with s
2) Check if the dictionary contains `"basil"`.

Please complete the task in the specified order.
Please do not add or remove any lines from the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well

<div class="hint">Use the <code>in</code> keyword.</div>

Expand Down
18 changes: 18 additions & 0 deletions Data structures/In keyword/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@ def test_basil(self):
self.assertTrue(result_2 == 'False', msg="Are you sure that grocery_dict contains basil? It should not...")


def test_0_code_len(self):
with open("in_keyword.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 8, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("in_keyword.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-1]
if not ('in' in code):
self.fail(msg="Your solution should use the in keyword.")

def test_statement_2(self):
with open("in_keyword.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-2]
if not ('in' in code):
self.fail(msg="Your solution should use the in keyword.")
2 changes: 2 additions & 0 deletions Data structures/Join method/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ Assign a value to the `joined` variable such that the `print` statement prints
I like apples and I like bananas and I like peaches and I like grapes
```

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class="hint">Look closely at the examples and simply do the same!</div>
<div class="hint"><code>fruits</code> is your iterable here, and <code>separator</code> is the separator string.</div>
12 changes: 12 additions & 0 deletions Data structures/Join method/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ def test_out_str(self):
def test_joined(self):
self.assertEqual(joined, separator.join(fruits), msg='Your `joined` string appears incorrect.')

def test_0_code_len(self):
with open("join_method.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 4, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("join_method.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-2]
if not ("separator.join(" in code):
self.fail(msg="Your solution should use the join() method.")

2 changes: 2 additions & 0 deletions Data structures/List items/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ animals[:] = []

Make all `animals` elephants by replacing the last two items.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class='hint'>Use assignment to a slice as in examples.</div>
11 changes: 11 additions & 0 deletions Data structures/List items/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ def test_list(self):
self.assertEqual(['elephant', 'elephant', 'elephant'], animals,
msg='The resulting list does not match the expected one. It should contain three elephants.')

def test_0_code_len(self):
with open("list_items.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 11, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("list_items.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-2]
if not ("animals[1:3]" in code):
self.fail(msg="Your solution should use assignment to a slice.")
2 changes: 2 additions & 0 deletions Data structures/Lists introduction/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ You can explore lists in more detail by reading <a href="https://docs.python.org

Use list slicing to print `[4, 9, 16]`.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class='hint'>List slicing syntax looks just like that for strings: <code>lst[index1:index2]</code>.
Don't forget that the element with the index <code>index2</code> is not included!</div>
11 changes: 11 additions & 0 deletions Data structures/Lists introduction/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ class TestCase(unittest.TestCase):
def test_slice(self):
self.assertEqual(correct_string, result_str, msg='The resulting slice does not match the expected one.')

def test_0_code_len(self):
with open("lists.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 4, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("lists.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-1]
if not ("squares[1:4]" in code):
self.fail(msg="Your solution should use slicing.")
3 changes: 3 additions & 0 deletions Data structures/Lists operations/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ squares
Find out about many other useful list methods on <a href="https://docs.python.org/3/tutorial/datastructures.html#more-on-lists">this page</a>.

Replace `"dino"` with `"dinosaur"` in the `animals` list.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class='hint'>Use list indexing operation and value assignment.</div>
14 changes: 13 additions & 1 deletion Data structures/Lists operations/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ def test_dinosaur(self):
self.assertTrue(animals[-1] == animals[6] == 'dinosaur', msg='The 7th (and the last) element'
'has to be "dinosaur".')
except IndexError:
self.assertTrue(False, msg='The list appears to be too short.')
self.assertTrue(False, msg='The list appears to be too short.')

def test_0_code_len(self):
with open("list_operations.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 11, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("list_operations.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-2]
if not ("[" in code and "]" in code):
self.fail(msg="Your solution should use indexing.")
2 changes: 2 additions & 0 deletions Data structures/Nested Lists/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ Output:
```
In the code editor, use indexing to access and print elements `9` and `10` from of the nested list `my_list`.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class="hint">If you're stuck, review the examples in the task description again.</div>
19 changes: 19 additions & 0 deletions Data structures/Nested Lists/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,22 @@ class TestCase(unittest.TestCase):
def test_list(self):
self.assertEqual('9', output[0], msg='The second printed element should be 9.')
self.assertEqual('10', output[1], msg='The second printed element should be 10.')

def test_0_code_len(self):
with open("task.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 4, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("task.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-2]
if not ("my_list[2][2]" in code):
self.fail(msg="Your solution should use indexing.")

def test_statement_2(self):
with open("task.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-1]
if not ("my_list[3]" in code):
self.fail(msg="Your solution should use indexing.")
1 change: 1 addition & 0 deletions Loops/List Comprehension/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ In the code editor, use list comprehension to build `my_efficient_list` from the
by adding $10$ to each of them. For example, the first element of `my_inefficient_list` is $1 + 10 = 11$,
so the first element of `my_efficient_list` should be $11 + 10 = 21$, and so on.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class="hint">

Expand Down
12 changes: 12 additions & 0 deletions Loops/List Comprehension/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ def test_add(self):
test_list = [i + 10 for i in my_inefficient_list]
self.assertEqual(test_list, my_efficient_list,
msg="Each element of `my_efficient_list` should equal a corresponding element of `my_inefficient_list` plus 10.")

def test_0_code_len(self):
with open("task.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 11, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("task.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-2]
if not (' for ' in code and " in " in code):
self.fail(msg="Your solution should use list comprehension.")
2 changes: 2 additions & 0 deletions Strings/Basic string methods/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ Detailed information about all string methods can be found <a href="https://docs

Print `monty_python` in upper case using an appropriate string method.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class='hint'>Pay attention to how the <code>lower()</code> method is used in our code.</div>
12 changes: 12 additions & 0 deletions Strings/Basic string methods/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ def test_out_len(self):

def test_string(self):
self.assertEqual(correct_string, result_str, msg='Wrong result string.')

def test_0_code_len(self):
with open("string_methods.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 6, msg="Please do not add or remove any lines from the code file.")

def test_statement_1(self):
with open("string_methods.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-1]
if not (".upper()" in code):
self.fail(msg="Your solution should use the function .upper().")
2 changes: 2 additions & 0 deletions Strings/Concatenation/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ Combining two strings using the `+` symbol is called concatenation.

Use the `hello` and `world` variables to get a string `"Hello World"`.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class='hint'>Use chained concatenation and a single-space string <code>" "</code>.</div>
10 changes: 10 additions & 0 deletions Strings/Concatenation/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ def test_import_hello(self):
except ImportError:
self.assertTrue(False, msg="Do not rename any variables.")

def test_0_code_len(self):
with open("concatenation.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 5, msg="Please do not add or remove any lines from the code file.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


def test_statement_1(self):
with open("concatenation.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-2]
if not ("+" in code):
self.fail(msg="Your solution does not use string concatenation.")
2 changes: 2 additions & 0 deletions Strings/F-strings/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ For more information about formatted string literals you can refer to <a href="h

Try creating an f-string yourself. Also try running the code to see what it prints.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class="hint">The value assigned to the <code>name</code> variable has to be a string, so it needs to be in quotes,
like so: <code>'Max'</code>.</div>

12 changes: 12 additions & 0 deletions Strings/F-strings/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,17 @@ def test_age(self):
def test_string(self):
self.assertIsNotNone(re.match(correct_string, result_str), msg='The result string does not match the expected one.')

def test_0_code_len(self):
with open("f_strings.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 3, msg="Please do not add or remove any lines from the code file.")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well

def test_statement_1(self):
with open("f_strings.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-1]
if not ("{name}" in code and "{age}" in code):
self.fail(msg="Your solution should use f-string syntax.")



2 changes: 2 additions & 0 deletions Strings/In operator/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ you can use the `in` keyword.

Check if there is `"ice"` in `"ice cream"` and assign the result to the variable `contains`.

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class="hint">Use the <code>in</code> operator.</div>
12 changes: 12 additions & 0 deletions Strings/In operator/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ def test_true(self):

except ImportError:
self.assertTrue(False, msg="Do not rename any variables.")

def test_0_code_len(self):
with open("in_operator.py", "r") as taskfile:
lines = taskfile.readlines()
self.assertTrue(len(lines) == 5, msg="Please do not add or remove any lines from the code file.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


def test_statement_1(self):
with open("in_operator.py", "r") as taskfile:
lines = taskfile.readlines()
code = lines[-2]
if not ("in" in code):
self.fail(msg="Your solution does not use the in operator.")
2 changes: 2 additions & 0 deletions Strings/String indexing/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ Note that since `-0` is the same as `0` , negative indices start from `-1`.

Use the index operator to get the letter `"P"` from `"Python"` .

Please do not add or remove any lines from the code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a less restrictive wording as well


<div class="hint">Note that indices start with 0.</div>
Loading