forked from MIT-Emerging-Talent/ET6-practice-code-review
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 02-challenge-sponge-case
- Loading branch information
Showing
8 changed files
with
221 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,40 @@ | ||
<!-- this template is for inspiration, feel free to change it however you like! --> | ||
|
||
# Constraints | ||
|
||
Some boundaries around our project. | ||
|
||
## External | ||
|
||
<!-- | ||
constraints coming from the outside that your team has no control over: | ||
- project deadlines | ||
- number of unit tests required to pass a code review | ||
- technologies (sometimes a client will tell you what to use) | ||
- power or connectivity | ||
- ... | ||
--> | ||
- **Project Deadlines**: The project must be completed and delivered by | ||
**January 8th**. Extensions are not an option. | ||
- **Technology Requirements**: We are required to use specific technologies such | ||
as VS Code, Python, and GitHub. | ||
- **Testing Standards**: All code must pass a minimum of 90% unit test coverage | ||
and meet quality metrics defined by MIT Emerging Talent Foundations Track instructors. | ||
- **Connectivity**: Some team members might face intermittent internet connectivity. | ||
|
||
## Internal: Involuntary | ||
|
||
<!-- | ||
constraints that come from within your team, and you have no control over: | ||
- each of your individual skill levels | ||
- amount of time available to work on the project | ||
--> | ||
- **Skill Levels**: The team includes members with varying levels of expertise, | ||
with some being beginners who are still learning the required tools and technologies. | ||
- **Time Availability**: Team members have varying schedules and commitments, | ||
which can impact how much time each person can contribute. | ||
- **Learning Curve**: Beginners may require additional time to learn new tools, | ||
frameworks, or workflows, potentially slowing progress. | ||
|
||
## Internal: Voluntary | ||
|
||
<!-- | ||
constraints that your team decided on to help scope the project. they may include: | ||
- coding style & conventions | ||
- agree on a code review checklist for the project repository | ||
- the number of hours you want to spend working | ||
- only using the colors black and white | ||
--> | ||
- **Independent Work**: Each team member works independently on their assigned | ||
tasks but can seek advice or guidance from others as needed. | ||
- **Coding Standards**: The team has agreed to follow a consistent coding style | ||
guide to maintain quality and readability. | ||
- **Code Reviews**: All pull requests will be reviewed by at least two other | ||
team members to ensure quality and foster knowledge sharing. | ||
- **Collaboration Tools**: Communication tools like Slack will be used for quick | ||
questions and advice, while GitHub Discussions and Issues will handle more | ||
structured feedback. | ||
- **Documentation**: Clear and beginner-friendly comments and documentation are | ||
mandatory for all code to make it accessible to everyone on the team. | ||
- **Scope Management**: To ensure progress, the project scope is limited to core | ||
features. | ||
- **Flexibility**: Pioneers United encourages flexibility, allowing members to | ||
ask for help or advice at any point without hesitation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# **Challenge: Use of Operators** | ||
|
||
## **Instructions:** | ||
|
||
1. Create a loop to go through each element in the list called `lista_de_elementos`. | ||
2. Check the type of each element: | ||
- If the element is a number (integer or float), check if it is below the | ||
defined threshold (`umbral`). | ||
- Print **"Approved"** if the value is below the threshold. | ||
- Print **"Rejected"** otherwise. | ||
- If the element is a string (`str`), skip the comparison with the threshold. | ||
3. Implement two counters: | ||
- One to count the number of approved elements. | ||
- One to count the number of rejected elements. | ||
4. Count the elements that are of type string (`str`) and print the total | ||
at the end of the loop. | ||
5. Print the total of approved and rejected elements at the end of the code. | ||
|
||
## **Initial Parameters:** | ||
|
||
```python | ||
threshold = -10 | ||
elements_list = [ | ||
10, 3.14, "7", -5, "2.718", 42, "Python", -8.9, "Hello", 100.5, | ||
"World", -15, "GPT-3", 5.5, "AI", -20, "2023", 123, "OpenAI", | ||
-2.5, "Example" | ||
] | ||
|
||
# Development of the main code loop. | ||
# In this space, you must write the code following the | ||
# instructions from the previous cell. | ||
|
||
|
||
|
||
print("Total approved: ", approved) | ||
print("Total rejected: ", rejected) | ||
print("Total strings: ", string_count) | ||
|
||
``` | ||
|
||
### **Expected Output:** | ||
|
||
At the end of the loop, the program should print: | ||
|
||
- The total number of approved elements. | ||
- The total number of rejected elements. | ||
- The total number of strings (`str`). | ||
|
||
### Helpful Links | ||
|
||
1. **`for` loop in Python** | ||
Documentación oficial sobre cómo usar los bucles `for` en Python: | ||
[for statement - Python Docs](https://docs.python.org/3/reference/simple_stmts.html#for) | ||
|
||
2. **`if` statement in Python** | ||
Documentación oficial sobre cómo usar las sentencias `if` en Python: | ||
[if statement - Python Docs](https://docs.python.org/3/reference/compound_stmts.html#if) | ||
|
||
[Github issue](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-04/issues/04) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
A module for processing a list of elements based on a threshold. | ||
Module contents: | ||
- process_elements: Analyzes a list to count approved, rejected, | ||
and string elements. | ||
Created on 29/12/2024 | ||
Author: Ramon Colmenares | ||
""" | ||
|
||
|
||
def process_elements(elements_list: list, threshold: float) -> dict: | ||
"""Processes a list of elements to count approvals, rejections, | ||
and strings. | ||
Parameters: | ||
elements_list: list, the list of elements to process | ||
threshold: float, the value below which numbers are "approved" | ||
Returns -> dict: A dictionary with counts of approved, rejected, | ||
and string elements. | ||
Raises: | ||
TypeError: if elements_list is not a list or threshold is not a number | ||
TypeError: if elements_list contains elements not of type int, | ||
float, or str | ||
Examples: | ||
>>> process_elements([10, -5, "Python", -20], -10) | ||
{'approved': 1, 'rejected': 2, 'strings': 1} | ||
>>> process_elements([10, "lol", -15.5, 0, ":p"], 0) | ||
{'approved': 1, 'rejected': 2, 'strings': 2} | ||
>>> process_elements([":O", 100.5, -50, "Test"], -5) | ||
{'approved': 1, 'rejected': 1, 'strings': 2} | ||
""" | ||
if not isinstance(elements_list, list): | ||
raise TypeError("elements_list must be a list.") | ||
if not isinstance(threshold, (int, float)): | ||
raise TypeError("threshold must be an int or float.") | ||
|
||
approved = 0 | ||
rejected = 0 | ||
string_count = 0 | ||
|
||
for element in elements_list: | ||
if isinstance(element, (int, float)): | ||
if element < threshold: | ||
approved += 1 | ||
else: | ||
rejected += 1 | ||
elif isinstance(element, str): | ||
string_count += 1 | ||
else: | ||
raise TypeError( | ||
f"Invalid element type: {type(element)}. " | ||
f"Only int, float, and str are allowed." | ||
) | ||
|
||
approved_dict = {"approved": approved} | ||
rejected_dict = {"rejected": rejected} | ||
strings_dict = {"strings": string_count} | ||
|
||
result = {**approved_dict, **rejected_dict, **strings_dict} | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Test module for process_elements function. | ||
Created on 29/12/2024 | ||
Author: Ramon Colmenares | ||
""" | ||
|
||
import unittest | ||
|
||
from solutions.challenge_4.use_of_operators import process_elements | ||
|
||
|
||
class TestProcessElements(unittest.TestCase): | ||
"""Test suite for the process_elements function.""" | ||
|
||
def test_valid_input(self): | ||
"""Test with a valid list of mixed elements.""" | ||
elements_list = [10, -5, "Python", -20] | ||
threshold = -10 | ||
result = process_elements(elements_list, threshold) | ||
self.assertEqual(result, {"approved": 1, "rejected": 2, "strings": 1}) | ||
|
||
def test_all_numbers(self): | ||
"""Test with a list of only numbers.""" | ||
elements_list = [10, -5, -20, 15, 3] | ||
threshold = 0 | ||
result = process_elements(elements_list, threshold) | ||
self.assertEqual(result, {"approved": 2, "rejected": 3, "strings": 0}) | ||
|
||
def test_all_strings(self): | ||
"""Test with a list of only strings.""" | ||
elements_list = ["Python", "GPT-3", "AI"] | ||
threshold = 0 | ||
result = process_elements(elements_list, threshold) | ||
self.assertEqual(result, {"approved": 0, "rejected": 0, "strings": 3}) | ||
|
||
def test_mixed_with_threshold(self): | ||
"""Test with a mix of numbers and strings and a custom threshold.""" | ||
elements_list = [10, 3.14, -5, "Test", 0] | ||
threshold = 1 | ||
result = process_elements(elements_list, threshold) | ||
self.assertEqual(result, {"approved": 2, "rejected": 2, "strings": 1}) | ||
|
||
def test_invalid_elements_list(self): | ||
"""Test with an invalid elements_list type.""" | ||
with self.assertRaises(TypeError): | ||
process_elements("not a list", -10) | ||
|
||
def test_invalid_threshold(self): | ||
"""Test with an invalid threshold type.""" | ||
elements_list = [10, -5, "Python", -20] | ||
with self.assertRaises(TypeError): | ||
process_elements(elements_list, "not a number") | ||
|
||
def test_invalid_element_in_list(self): | ||
"""Test with an invalid element in the list.""" | ||
elements_list = [10, -5, ["not valid"], -20] | ||
with self.assertRaises(TypeError): | ||
process_elements(elements_list, -10) |