Skip to content

Commit

Permalink
Merge pull request #45 from WincAcademy/main
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
Chrisztiaan authored May 4, 2023
2 parents 8a1d129 + fb62805 commit dca4bd5
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.6
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 3 additions & 1 deletion wincpy/checks/00a4ab32f1024f5da525307a1959958e.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
"nationality": "Belgium",
}

# did you use name, date_of_birth, place_of_birth, height and nationality as arguments?


def check_create_passport(student_module):
StandardChecks.n_params(student_module.create_passport, n_params=5)

passport = student_module.create_passport(**TEST_DATA)
assert passport == TEST_DATA, "The returned dict is not as we expected it to be."
assert passport == TEST_DATA, "create_passport did not create a correct dictionary"


def check_add_stamp(student_module):
Expand Down
6 changes: 4 additions & 2 deletions wincpy/checks/04da020dedb24d42adf41382a231b1ed.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def check_player_introduce(student_module):
"""The `Player.introduce` method is implemented correctly"""
StandardChecks.n_params(student_module.Player, n_params=4)

player = student_module.Player("Super Bob", 0.3, 0.5, 0.5)
assert player.introduce() == "Hello everyone, my name is Super Bob."
player = student_module.Player("Mister Secret Name", 0.3, 0.5, 0.5)
assert (
player.introduce() == "Hello everyone, my name is Mister Secret Name."
), "Try using an f-string combined with self.name"


def check_player_strength(student_module):
Expand Down
4 changes: 4 additions & 0 deletions wincpy/checks/25596924dffe436da9034d43d0af6791.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def check_farm_action(student_module):
(("windy", "night", True, "cowshed", "winter", True, True), "milk cows"),
(("bowling", "night", False, "cowshed", "winter", False, True), "wait"),
(("sunny", "night", True, "cowshed", "summer", False, True), "milk cows"),
(
("rainy", "night", False, "pasture", "winter", False, False),
"take cows to cowshed",
),
]

for args, return_val in cases:
Expand Down
55 changes: 35 additions & 20 deletions wincpy/checks/286787689e9849969c326ee41d8c53c4.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ def check_cheapest_dish(student_module):
StandardChecks.n_params(student_module.models.Dish.select, n_params=1)

dish = student_module.cheapest_dish()
assert dish == (
expected_dish = (
student_module.models.Dish.select()
.order_by(student_module.models.Dish.price_in_cents)
.first()
), f"Expected the cheapest dish to be {dish}"
)
print(f"{dish} and {expected_dish}")
assert dish == expected_dish, f"Expected the cheapest dish to be {expected_dish}."
assert type(dish) == type(
expected_dish
), f"Expected the cheapest dish to be {expected_dish}."


def check_vegetarian_dishes(student_module):
Expand All @@ -28,21 +33,24 @@ def check_vegetarian_dishes(student_module):
StandardChecks.n_params(student_module.models.Dish.select, n_params=1)

dishes = student_module.vegetarian_dishes()
assert set(dishes) == set(
expected_dishes = set(
[
dish
for dish in student_module.models.Dish.select()
if all([i.is_vegetarian for i in dish.ingredients])
]
), f"Expected the set of vegetarian dishes to be {set(dishes)}"
)
assert (
set(dishes) == expected_dishes
), f"Expected vegetarian dishes to be {expected_dishes}"


def check_best_restaurant(student_module):
"""`best_average_rating` is implemented correctly"""
StandardChecks.n_params(student_module.best_average_rating, n_params=0)

restaurant = student_module.best_average_rating()
assert restaurant == (
expected_restaurant = (
student_module.models.Restaurant.select(
student_module.models.Restaurant,
peewee.fn.AVG(student_module.models.Rating.rating).alias("average"),
Expand All @@ -51,7 +59,13 @@ def check_best_restaurant(student_module):
.group_by(student_module.models.Restaurant)
.order_by(peewee.fn.AVG(student_module.models.Rating.rating).desc())
.first()
), f"Expected the restaurant with the best average rating to be {restaurant}"
)
assert (
restaurant == expected_restaurant
), f"Expected the best restaurant to be {expected_restaurant}"
assert type(restaurant) == type(
expected_restaurant
), f"Expected the best restaurant to be {expected_restaurant}"


def check_add_rating(student_module):
Expand All @@ -63,28 +77,29 @@ def check_add_rating(student_module):
new_rating_count = student_module.models.Rating.select().count()
assert (
current_rating_count < new_rating_count
), f"Expected number of ratings to go from {current_rating_count} to {new_rating_count}"
), f"Expected number of ratings to go from {current_rating_count} to {current_rating_count + 1}"


def check_dinner_date_possible(student_module):
"""`dinner_date_possible` is implemented correctly"""
StandardChecks.n_params(student_module.dinner_date_possible, n_params=0)

date_restaurants = student_module.dinner_date_possible()
expected_date_restaurants = [
restaurant
for restaurant in student_module.models.Restaurant.select()
.where(student_module.models.Restaurant.opening_time <= "19:00")
.where(student_module.models.Restaurant.closing_time >= "19:00")
if any(
[
all([i.is_vegan for i in dish.ingredients])
for dish in restaurant.dish_set.select()
]
)
]
assert set(date_restaurants) == set(
[
restaurant
for restaurant in student_module.models.Restaurant.select()
.where(student_module.models.Restaurant.opening_time <= "19:00")
.where(student_module.models.Restaurant.closing_time >= "19:00")
if any(
[
all([i.is_vegan for i in dish.ingredients])
for dish in restaurant.dish_set.select()
]
)
]
), f"Expected dinner date restaurants to be {date_restaurants}"
expected_date_restaurants
), f"Expected dinner date restaurants to be {expected_date_restaurants}"


def check_add_dish_to_menu(student_module):
Expand Down
7 changes: 4 additions & 3 deletions wincpy/checks/499e67d5cb54448e93cee7465be2c866.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def check_state(student_module):
def check_output(student_module):
"""The output is as expected."""
output, _ = utils.exec_main(student_module)

split_output = output.split("\n")
last_print = split_output[-1]
assert (
float(output.strip()) == 73.5
), f"We expected your program's output to be `73.5`, but it was `{output}`"
float(last_print) == 73.5
), f"We expected your program's last print to be `73.5`, but it was `{last_print}`"
21 changes: 13 additions & 8 deletions wincpy/checks/534d85ea1ab14924a91f9eccf6f3f30d.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,19 @@ def check_get_item_from_list(student_module):


def strip_comments(src):
single_line_comment = re.compile(r"#.*\n")
multiline_comment = re.compile(r'""".*"""')
cleaned_src = re.sub(r"#.*\n", "", src)
return cleaned_src

cleaned_src = src
for match in single_line_comment.finditer(src):
cleaned_src = cleaned_src[: match.start()] + cleaned_src[match.end() :]

for match in multiline_comment.finditer(src):
cleaned_src = cleaned_src[: match.start()] + cleaned_src[match.end() :]
# def strip_comments(src):
# single_line_comment = re.compile(r"#.*\n")
# multiline_comment = re.compile(r'""".*"""')

return cleaned_src
# cleaned_src = src
# for match in single_line_comment.finditer(src):
# cleaned_src = cleaned_src[: match.start()] + cleaned_src[match.end() :]

# for match in multiline_comment.finditer(src):
# cleaned_src = cleaned_src[: match.start()] + cleaned_src[match.end() :]

# return cleaned_src
4 changes: 3 additions & 1 deletion wincpy/checks/63ce21059cf34d3d8ffef497ede7e317.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ def check_end_of_line_comments(student_module):
def check_single_line_comments(student_module):
"""Your `main.py` contains two single-line comments"""
src = utils.get_main_src(student_module)

count = sum([True if l.strip().find("#") == 0 else False for l in src.split("\n")])

assert (
count >= 2
count >= 4
), f"There should be at least `2` single-line comments, but there were only `{count}`"


Expand Down
6 changes: 3 additions & 3 deletions wincpy/checks/7152c06aa3ac4d5f964ca8619ecb7e8f.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def check_bool(student_module):

def check_str(student_module):
"""There's a `str` in your code"""
assert str in __get_types_in_state(
student_module
assert (
str in __get_types_in_state(student_module)[2:]
), "There's no variable with a `str` stored in it after running your code"


Expand All @@ -25,4 +25,4 @@ def check_int(student_module):


def __get_types_in_state(student_module):
return set([type(v) for v in utils.exec_main(student_module)[1].values()])
return [type(v) for v in utils.exec_main(student_module)[1].values()]
16 changes: 10 additions & 6 deletions wincpy/checks/7b9401ad7f544be2a23321292dd61cb6.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ def check_force(student_module):
round(student_module.force(50)) == 490
), "Did you use earth's gravity by default?"

assert student_module.force(10, "sun") == 2740, "'sun' is not handled correctly"
assert student_module.force(10, "pluto") == 6, "'pluto' is not handled correctly"
assert (
student_module.force(10, "saturn") == 104
), "'saturn' is not handled correctly"
assert student_module.force(10, "pluto") == 7, "'pluto' is not handled correctly"
assert student_module.force(10, "saturn") == 90, "'saturn' is not handled correctly"
assert student_module.force(10, "earth") == 98, "'earth' is not handled correctly"
assert (
student_module.force(10, "jupiter") == 231
), "'jupiter' is not handled correctly"
assert (
student_module.force(10, "neptune") == 110
), "'neptune' is not handled correctly"
assert student_module.force(10, "moon") == 16, "'moon' is not handled correctly"


def check_pull(student_module):
StandardChecks.n_params(student_module.pull, n_params=3)
assert student_module.pull(1, 2, 3) is not None
assert round(student_module.pull(800, 1500, 3), 10) == 8.8987e-06
assert (
round(student_module.pull(0.1, 5.972 * 10 ** 4, 6.371 * 10 ** 6), 30)
round(student_module.pull(0.1, 5.972 * 10**4, 6.371 * 10**6), 30)
== 9.819532033e-21
)
7 changes: 7 additions & 0 deletions wincpy/checks/c0dc6e00dfac46aab88296601c32669f.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def check_unique_koala_fact(student_module):
StandardChecks.n_params(student_module.unique_koala_facts, n_params=1)
facts = __get_all_facts(student_module)

assert (
len(set(student_module.unique_koala_facts(0))) != 29
), "When asking for 0 facts, all the facts are returned"

for n in range(15):
assert (
len(set(student_module.unique_koala_facts(n))) == n
Expand All @@ -34,6 +38,9 @@ def check_unique_koala_fact(student_module):

def check_num_joey_facts(student_module):
StandardChecks.n_params(student_module.num_joey_facts, n_params=0)
assert (
type(student_module.num_joey_facts()) == int
), "`num_joey_facts` returned a `str` but it should be an `int`"
assert (
student_module.num_joey_facts() == 2
), "`num_joey_facts` did not return the right number"
Expand Down
11 changes: 9 additions & 2 deletions wincpy/checks/c545bc87620d4ced81cbddb8a90b4a51.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,22 @@ def check_most_vowels(student_module):
"South Georgia and the South Sandwich Islands",
"Micronesia, Federated States of",
"United States Minor Outlying Islands",
}, "Your top 3 is not correct."
}, "Your top 3 is not correct. Did you think about capital letters?"


def check_alphabet_set(student_module):
StandardChecks.n_params(student_module.alphabet_set, n_params=1)

countries = student_module.get_countries()
student_output = student_module.alphabet_set(countries)

alpha = {chr(i) for i in range(97, 123)}
provided = set("".join([x.lower() for x in student_module.alphabet_set(countries)]))
provided = set("".join([x.lower() for x in student_output]))

assert (
len(student_output) <= 14
), f"The amount of countries returned should be 14 or less, yours was {len(student_output)}"

assert provided.issuperset(
alpha
), f"Your set of countries does not provide these letters: {alpha - provided}"
5 changes: 3 additions & 2 deletions wincpy/solutions/00a4ab32f1024f5da525307a1959958e/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
import os


def get_countries():
module_path = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
data_fp = open(os.path.join(module_path, 'countries.json'), 'r')
return json.load(data_fp)['countries']
data_fp = open(os.path.join(module_path, "countries.json"), "r")
return json.load(data_fp)["countries"]
2 changes: 1 addition & 1 deletion wincpy/solutions/00a4ab32f1024f5da525307a1959958e/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def add_stamp(passport, country):
if "stamps" not in passport:
passport["stamps"] = []

if country not in passport["stamps"]:
if country not in passport["stamps"] and country is not passport["nationality"]:
passport["stamps"].append(country)

return passport
Expand Down
3 changes: 3 additions & 0 deletions wincpy/solutions/25596924dffe436da9034d43d0af6791/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ def farm_action(
actions += "wait\n"

return actions[:-1]


print(farm_action("rainy", "night", False, "pasture", "winter", False, False))
44 changes: 44 additions & 0 deletions wincpy/solutions/7b9401ad7f544be2a23321292dd61cb6/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Do not modify these lines
__winc_id__ = "7b9401ad7f544be2a23321292dd61cb6"
__human_name__ = "arguments"

# Add your code after this line

# 1


def greet(name, greeting="Hello, <name>!"):
new_greeting = greeting.replace("<name>", name)
return new_greeting


# 2


def force(mass, body="earth"):
bodies = {
"jupiter": 23.1,
"neptune": 11.0,
"saturn": 9.0,
"earth": 9.8,
"uranus": 8.7,
"venus": 8.9,
"mars": 3.7,
"mercury": 3.7,
"moon": 1.6,
"pluto": 0.7,
}

force = mass * bodies[body]
return force


print(force(10, "moon"))


# 3


def pull(m1, m2, d):
G = 6.674 * 10**-11
return G * ((m1 * m2) / d**2)
Loading

0 comments on commit dca4bd5

Please sign in to comment.