-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: master
Are you sure you want to change the base?
Sofia/fix some tests #137
Changes from all commits
9ca5a34
72ac966
8b2b3d2
53c7b6e
7b097a8
07e7aa6
d2abe62
810f821
05cd509
c437391
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.") | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
There was a problem hiding this comment.
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?"