From dbc274543286cd2b6f892096ae59d401e369fb6d Mon Sep 17 00:00:00 2001 From: reunicorn1 <138371895+reunicorn1@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:01:18 +0400 Subject: [PATCH 01/43] Adding the group norms --- collaboration/guide/1_group_norms.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/collaboration/guide/1_group_norms.md b/collaboration/guide/1_group_norms.md index c7bd0e34e..9063c00c4 100644 --- a/collaboration/guide/1_group_norms.md +++ b/collaboration/guide/1_group_norms.md @@ -1,4 +1,16 @@ # Group Norms -Complete the _Group Norms_ assignment from the Code Review workshop and write -your norms summary and list in the [Collaboration README](../README.md) +## The summary + +Our group is committed to fostering trust, collaboration, and open communication by valuing diverse perspectives, respecting time, and embracing accountability. We aim to create a positive and inclusive environment where everyone feels supported, empowered to contribute, and aligned toward shared goals. We strive to build strong relationships and ensure collective growth where mistakes are treated as learning opportunities, and trust is rebuilt through consistent actions and open dialogue. Together, we are dedicated to making this a meaningful and enjoyable experience for all. + +## The Refine + +1. Build and Sustain Trust: Commit to creating a reliable and supportive environment where trust underpins all interactions. +2. Foster Open Communication: Ensure a culture where all voices are valued, and ideas, concerns, and feedback are openly shared. +3. Respect Time and Focus: Honor each other’s time by striving for purposeful and efficient communication and collaboration. +4. Promote Team Growth: Support collective learning, personal development, and the achievement of shared goals. +5. Encourage Inclusivity: Create a space where diverse perspectives are welcomed and everyone feels empowered to contribute. +6. Ensure Clarity and Alignment: Maintain shared understanding and alignment on goals, expectations, and progress. +7. Cultivate a Positive Team Culture: Build a collaborative and motivating environment that values both achievements and relationships. +8. Embrace Growth from Challenges: Approach mistakes and challenges as opportunities for learning and improvement. From 27e286a050896e172ddbb06f38664ee538cde584 Mon Sep 17 00:00:00 2001 From: reunicorn1 <138371895+reunicorn1@users.noreply.github.com> Date: Tue, 24 Dec 2024 22:06:12 +0400 Subject: [PATCH 02/43] fixing the linting issues --- collaboration/guide/1_group_norms.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/collaboration/guide/1_group_norms.md b/collaboration/guide/1_group_norms.md index 9063c00c4..4ee3425fc 100644 --- a/collaboration/guide/1_group_norms.md +++ b/collaboration/guide/1_group_norms.md @@ -6,11 +6,19 @@ Our group is committed to fostering trust, collaboration, and open communication ## The Refine -1. Build and Sustain Trust: Commit to creating a reliable and supportive environment where trust underpins all interactions. -2. Foster Open Communication: Ensure a culture where all voices are valued, and ideas, concerns, and feedback are openly shared. -3. Respect Time and Focus: Honor each other’s time by striving for purposeful and efficient communication and collaboration. -4. Promote Team Growth: Support collective learning, personal development, and the achievement of shared goals. -5. Encourage Inclusivity: Create a space where diverse perspectives are welcomed and everyone feels empowered to contribute. -6. Ensure Clarity and Alignment: Maintain shared understanding and alignment on goals, expectations, and progress. -7. Cultivate a Positive Team Culture: Build a collaborative and motivating environment that values both achievements and relationships. -8. Embrace Growth from Challenges: Approach mistakes and challenges as opportunities for learning and improvement. +1. Build and Sustain Trust: Commit to creating a reliable and supportive environment where trust +underpins all interactions. +2. Foster Open Communication: Ensure a culture where all voices are valued, and ideas, concerns, +and feedback are openly shared. +3. Respect Time and Focus: Honor each other’s time by striving for purposeful and efficient +communication and collaboration. +4. Promote Team Growth: Support collective learning, personal development, and the achievement +of shared goals. +5. Encourage Inclusivity: Create a space where diverse perspectives are welcomed and everyone +feels empowered to contribute. +6. Ensure Clarity and Alignment: Maintain shared understanding and alignment on goals, expectations, +and progress. +7. Cultivate a Positive Team Culture: Build a collaborative and motivating environment that values +both achievements and relationships. +8. Embrace Growth from Challenges: Approach mistakes and challenges as opportunities for learning +and improvement. From 32db1c420e19e5137adcb9eb83730d18b075dd01 Mon Sep 17 00:00:00 2001 From: mxz Date: Tue, 24 Dec 2024 20:48:44 +0200 Subject: [PATCH 03/43] fix the collaboration Readme file --- .vscode/settings.json | 5 +++- collaboration/README.md | 35 ++++++++++++++++++++++++++++ collaboration/guide/1_group_norms.md | 24 ++----------------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a90e202f..30c6ea2e1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -113,5 +113,8 @@ }, // Enable/disable update table of contents on save - "markdown.extension.toc.updateOnSave": false + "markdown.extension.toc.updateOnSave": false, + "cSpell.words": [ + "Inclusivity" + ] } diff --git a/collaboration/README.md b/collaboration/README.md index 20889b951..64a2ebba7 100644 --- a/collaboration/README.md +++ b/collaboration/README.md @@ -1,5 +1,40 @@ # Collaboration +## The summary + +Our group is committed to fostering trust, collaboration, and open communication + by valuing diverse perspectives, respecting + time, and embracing accountability. We aim to create a positive and inclusive + environment where everyone feels supported, empowered to contribute, and aligned + toward shared goals. We strive to build strong relationships and ensure + collective growth where mistakes are treated as learning opportunities, and + trust is rebuilt through consistent actions and open dialogue. Together, we + are dedicated to making this a meaningful and enjoyable experience for all. +## The list + +1. Build and Sustain Trust: Commit to creating a reliable and supportive +environment where trust +underpins all interactions. +2. Foster Open Communication: Ensure a culture where all voices are valued, and + ideas, concerns, +and feedback are openly shared. +3. Respect Time and Focus: Honor each other’s time by striving for purposeful + and efficient +communication and collaboration. +4. Promote Team Growth: Support collective learning, personal development, and +the achievement +of shared goals. +5. Encourage Inclusivity: Create a space where diverse perspectives are +welcomed and everyone +feels empowered to contribute. +6. Ensure Clarity and Alignment: Maintain shared understanding and alignment on + goals, expectations, +and progress. +7. Cultivate a Positive Team Culture: Build a collaborative and motivating +environment that values +both achievements and relationships. +8. Embrace Growth from Challenges: Approach mistakes and challenges as +opportunities for learning and improvement. diff --git a/collaboration/guide/1_group_norms.md b/collaboration/guide/1_group_norms.md index 4ee3425fc..c7bd0e34e 100644 --- a/collaboration/guide/1_group_norms.md +++ b/collaboration/guide/1_group_norms.md @@ -1,24 +1,4 @@ # Group Norms -## The summary - -Our group is committed to fostering trust, collaboration, and open communication by valuing diverse perspectives, respecting time, and embracing accountability. We aim to create a positive and inclusive environment where everyone feels supported, empowered to contribute, and aligned toward shared goals. We strive to build strong relationships and ensure collective growth where mistakes are treated as learning opportunities, and trust is rebuilt through consistent actions and open dialogue. Together, we are dedicated to making this a meaningful and enjoyable experience for all. - -## The Refine - -1. Build and Sustain Trust: Commit to creating a reliable and supportive environment where trust -underpins all interactions. -2. Foster Open Communication: Ensure a culture where all voices are valued, and ideas, concerns, -and feedback are openly shared. -3. Respect Time and Focus: Honor each other’s time by striving for purposeful and efficient -communication and collaboration. -4. Promote Team Growth: Support collective learning, personal development, and the achievement -of shared goals. -5. Encourage Inclusivity: Create a space where diverse perspectives are welcomed and everyone -feels empowered to contribute. -6. Ensure Clarity and Alignment: Maintain shared understanding and alignment on goals, expectations, -and progress. -7. Cultivate a Positive Team Culture: Build a collaborative and motivating environment that values -both achievements and relationships. -8. Embrace Growth from Challenges: Approach mistakes and challenges as opportunities for learning -and improvement. +Complete the _Group Norms_ assignment from the Code Review workshop and write +your norms summary and list in the [Collaboration README](../README.md) From 3da9d0a24ca28a1344fc09cee05f70c0fd362552 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Mon, 30 Dec 2024 06:55:44 +0400 Subject: [PATCH 04/43] Adding the learning goals --- collaboration/learning_goals.md | 43 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/collaboration/learning_goals.md b/collaboration/learning_goals.md index 11c583d2b..511ec7f87 100644 --- a/collaboration/learning_goals.md +++ b/collaboration/learning_goals.md @@ -1,5 +1,42 @@ -# Learning Goals +# Learning Goals -## Collective +Our team comprises ten members with diverse backgrounds, including those new to +coding and others with significant experience. This variety presents an excellent +opportunity for mutual learning and growth. Below are the learning goals we have +collectively identified for these exercises: -## Individual +## Objectives for Team Members New to Coding + +- **Build foundational knowledge**: Understand the basics of data structures (DSs) + and algorithms. +- **Learn programming best practices**: Focus on writing clean, readable, and well- + documented code. +- **Practice problem-solving**: Develop confidence in tackling coding problems +step by step. +- **Gain exposure to code review**: Learn how to give and receive constructive feedback + to improve solutions. + +## Objectives for Experienced Team Members + +- **Strengthen advanced skills**: Dive deeper into complex DSs and algorithms to +enhance problem-solving capabilities. +- **Experiment with new approaches**: Explore and apply new programming language +features to refine solutions. +- **Focus on optimization**: Work on producing efficient and scalable code. +- **Mentor and collaborate**: Guide less experienced team members to create an +inclusive and supportive learning environment. + +## Shared Team Objectives + +- **Learn through collaboration**: Share knowledge and perspectives to maximize +learning outcomes for everyone. +- **Improve development speed**: Practice writing solutions faster while maintaining +quality. +- **Foster a culture of feedback**: Embrace multiple cycles of review to improve +individual and team skills. +- **Document solutions effectively**: Ensure every solution is well-commented and +easy to understand for future reference. + +These goals reflect our commitment to leveraging our diverse skills and experiences +to grow together as a team. We’ll revisit and refine these objectives as needed +to ensure alignment with our progress and expectations. From e4f3e8054d6fb2370213feab61644361095e5245 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Mon, 30 Dec 2024 07:37:12 +0400 Subject: [PATCH 05/43] Adding the Constraints --- collaboration/constraints.md | 95 ++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 32 deletions(-) diff --git a/collaboration/constraints.md b/collaboration/constraints.md index 24079505c..f1a506e49 100644 --- a/collaboration/constraints.md +++ b/collaboration/constraints.md @@ -1,34 +1,65 @@ -# Constraints - -Some boundaries around our project. - -## External - - - -## Internal: Involuntary - - - -## Internal: Voluntary - - +# Constraints + +This document outlines the constraints for our collaborative project, helping us +focus on realistic goals and effective teamwork. Each member will solve two +problems by writing Python code, documenting it, and testing it. Additionally, +every member will review two problems written by others. The repository is a +group effort, reflecting everyone's contributions. + +## External + + + +- **Project Deadlines**: The project must be completed by **January 10**, with +internal deadlines for milestones ensuring consistent progress. +- **Technologies**: The project requires Python, GitHub, VSCode, and linting +tools for coding, collaboration, and quality assurance. +- **Time Constraints**: Members have limited availability due to full-time jobs +and university schedules. + +## Internal: Involuntary + + + +- **Skill Levels**: The team includes members with a mix of beginner and experienced +skill levels, with most members new to coding. +- **Time Availability**: Each member can dedicate only a few hours per week due +to other commitments. + +## Internal: Voluntary + + + +- **Problem Solving**: Each member will solve two problems by writing Python +code, ensuring the solutions are well-documented and thoroughly tested. +- **Code Reviews**: Every member will review two problems written by others, +providing constructive feedback to enhance quality and learning. +- **Coding Conventions**: The team has agreed on consistent coding styles and a +code review checklist to maintain clarity and quality in the repository. +- **Repository Collaboration**: All members will contribute to a shared GitHub +repository, promoting teamwork and collective ownership of the project. +- **Scope Management**: Realistic project goals have been set to balance +learning opportunities with completing a high-quality final product. +- **Tools Commitment**: The team will use GitHub for version control, VSCode for +development, and Python linting tools to ensure clean, efficient code. +- **Feedback Cycles**: A process for iterative feedback and reviews has been +established to improve both individual skills and project outcomes. From 5e312da77d99f1f890df3f2ccdb3800b7dc242b3 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Mon, 30 Dec 2024 08:00:55 +0400 Subject: [PATCH 06/43] Adding the empty python file --- solutions/tests/test_fuel_gauge.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/tests/test_fuel_gauge.py diff --git a/solutions/tests/test_fuel_gauge.py b/solutions/tests/test_fuel_gauge.py new file mode 100644 index 000000000..e69de29bb From f09f7dcaa59f6c7f76402d88a8103ed0e7bca128 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Mon, 30 Dec 2024 08:24:06 +0400 Subject: [PATCH 07/43] Adding the Python file --- solutions/fuel_gauge.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/fuel_gauge.py diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py new file mode 100644 index 000000000..e69de29bb From 43918ea68d6fba3f6e38a0030c68fb04f0f4a296 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Mon, 30 Dec 2024 08:38:04 +0400 Subject: [PATCH 08/43] adding empty python files --- solutions/armstrong_number.py | 0 solutions/tests/test_armstrong_number.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/armstrong_number.py create mode 100644 solutions/tests/test_armstrong_number.py diff --git a/solutions/armstrong_number.py b/solutions/armstrong_number.py new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/tests/test_armstrong_number.py b/solutions/tests/test_armstrong_number.py new file mode 100644 index 000000000..e69de29bb From 1b290f0bfff14ad61a1efd8426d040bfff7fe0ef Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Mon, 30 Dec 2024 09:54:23 +0200 Subject: [PATCH 09/43] created the file for the arithmetic sequence test --- solutions/tests/test_arithmetic_sequence.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/tests/test_arithmetic_sequence.py diff --git a/solutions/tests/test_arithmetic_sequence.py b/solutions/tests/test_arithmetic_sequence.py new file mode 100644 index 000000000..e69de29bb From 75747e4120184ff9ef2aacaa538843cfb2efee9f Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Mon, 30 Dec 2024 11:17:17 +0200 Subject: [PATCH 10/43] I added the test file test_even_number_count.py --- solutions/tests/test_even_number_count.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/tests/test_even_number_count.py diff --git a/solutions/tests/test_even_number_count.py b/solutions/tests/test_even_number_count.py new file mode 100644 index 000000000..e69de29bb From 509a789ee8375af80277bae955bb2ebb18be5a4d Mon Sep 17 00:00:00 2001 From: Omnia-Agabani Date: Mon, 30 Dec 2024 18:50:19 +0400 Subject: [PATCH 11/43] Quadratic Sequence File --- .vscode/settings.json | 4 ++-- solutions/quadratic_sequence.py | 14 ++++++++++++++ solutions/tests/test_quadratic_sequence.py | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 solutions/quadratic_sequence.py create mode 100644 solutions/tests/test_quadratic_sequence.py diff --git a/.vscode/settings.json b/.vscode/settings.json index bbda5188d..252022b48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -119,8 +119,8 @@ "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.ruff": true, - "source.organizeImports.ruff": true + "source.fixAll.ruff": "explicit", + "source.organizeImports.ruff": "explicit" } } } diff --git a/solutions/quadratic_sequence.py b/solutions/quadratic_sequence.py new file mode 100644 index 000000000..c3ccf46b5 --- /dev/null +++ b/solutions/quadratic_sequence.py @@ -0,0 +1,14 @@ +def quadratic_sequence(a, b, c, n): + """ + The function creates quadratic sequence, based on formula: A(n): an^2 + bn + c + + Parameters: + a (int): Coefficient of n^2 + b (int): Coefficient of n + c (int): Constant term + n (int): Number of terms to generate + + Returns: + List: List containing the quadratic sequence + + """ diff --git a/solutions/tests/test_quadratic_sequence.py b/solutions/tests/test_quadratic_sequence.py new file mode 100644 index 000000000..4bcf37a95 --- /dev/null +++ b/solutions/tests/test_quadratic_sequence.py @@ -0,0 +1,4 @@ +import unittest +from ..quadratic_sequence import quadratic_sequence + +class TestAsciiCode(unittest.TestCase): From b7c55a7c852cf177a980d4281e13677d639b416f Mon Sep 17 00:00:00 2001 From: Omnia-Agabani Date: Mon, 30 Dec 2024 19:00:57 +0400 Subject: [PATCH 12/43] Create harmonic_sequence file --- solutions/harmonic_sequence.py | 13 +++++++++++++ solutions/tests/test_harmonic_sequence.py | 4 ++++ 2 files changed, 17 insertions(+) create mode 100644 solutions/harmonic_sequence.py create mode 100644 solutions/tests/test_harmonic_sequence.py diff --git a/solutions/harmonic_sequence.py b/solutions/harmonic_sequence.py new file mode 100644 index 000000000..9e66dcb91 --- /dev/null +++ b/solutions/harmonic_sequence.py @@ -0,0 +1,13 @@ +def harmonic_sequence(a, d, n): + """ + The function creates harmonic sequence, based on formula: A(n): 1/ (a +(n-1) *d) + + Parameters: + a (int): First term + d (int): Common difference + n (int): Number of terms to generate + + Returns: + List: List containing the harmonic sequence + + """ diff --git a/solutions/tests/test_harmonic_sequence.py b/solutions/tests/test_harmonic_sequence.py new file mode 100644 index 000000000..2284aa3e9 --- /dev/null +++ b/solutions/tests/test_harmonic_sequence.py @@ -0,0 +1,4 @@ +import unittest +from ..harmonic_sequence import harmonic_sequence + +class TestAsciiCode(unittest.TestCase): From 6e5731ece5deb11b3d26a2b128064682838b4f80 Mon Sep 17 00:00:00 2001 From: Omnia-Agabani Date: Tue, 31 Dec 2024 21:22:30 +0400 Subject: [PATCH 13/43] Delete files error --- solutions/harmonic_sequence.py | 13 ------------- solutions/quadratic_sequence.py | 14 -------------- solutions/tests/test_harmonic_sequence.py | 4 ---- solutions/tests/test_quadratic_sequence.py | 4 ---- 4 files changed, 35 deletions(-) delete mode 100644 solutions/harmonic_sequence.py delete mode 100644 solutions/quadratic_sequence.py delete mode 100644 solutions/tests/test_harmonic_sequence.py delete mode 100644 solutions/tests/test_quadratic_sequence.py diff --git a/solutions/harmonic_sequence.py b/solutions/harmonic_sequence.py deleted file mode 100644 index 9e66dcb91..000000000 --- a/solutions/harmonic_sequence.py +++ /dev/null @@ -1,13 +0,0 @@ -def harmonic_sequence(a, d, n): - """ - The function creates harmonic sequence, based on formula: A(n): 1/ (a +(n-1) *d) - - Parameters: - a (int): First term - d (int): Common difference - n (int): Number of terms to generate - - Returns: - List: List containing the harmonic sequence - - """ diff --git a/solutions/quadratic_sequence.py b/solutions/quadratic_sequence.py deleted file mode 100644 index c3ccf46b5..000000000 --- a/solutions/quadratic_sequence.py +++ /dev/null @@ -1,14 +0,0 @@ -def quadratic_sequence(a, b, c, n): - """ - The function creates quadratic sequence, based on formula: A(n): an^2 + bn + c - - Parameters: - a (int): Coefficient of n^2 - b (int): Coefficient of n - c (int): Constant term - n (int): Number of terms to generate - - Returns: - List: List containing the quadratic sequence - - """ diff --git a/solutions/tests/test_harmonic_sequence.py b/solutions/tests/test_harmonic_sequence.py deleted file mode 100644 index 2284aa3e9..000000000 --- a/solutions/tests/test_harmonic_sequence.py +++ /dev/null @@ -1,4 +0,0 @@ -import unittest -from ..harmonic_sequence import harmonic_sequence - -class TestAsciiCode(unittest.TestCase): diff --git a/solutions/tests/test_quadratic_sequence.py b/solutions/tests/test_quadratic_sequence.py deleted file mode 100644 index 4bcf37a95..000000000 --- a/solutions/tests/test_quadratic_sequence.py +++ /dev/null @@ -1,4 +0,0 @@ -import unittest -from ..quadratic_sequence import quadratic_sequence - -class TestAsciiCode(unittest.TestCase): From 5d229b06a02408ddbc4b898770defc3affe932c2 Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Tue, 31 Dec 2024 19:30:49 +0200 Subject: [PATCH 14/43] Added the test file and the python file for even_number_count --- solutions/even_number_count | 47 +++++++++++++++++++++ solutions/tests/test_even_number_count.py | 50 +++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 solutions/even_number_count diff --git a/solutions/even_number_count b/solutions/even_number_count new file mode 100644 index 000000000..63ea6c592 --- /dev/null +++ b/solutions/even_number_count @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A function that counts the number of even numbers in a countdown from n to 1 + +Module contents: + - even_number_count: generates a number for the amount of even numbers in the list. + +Created on Monday/ 30/ December/ 2024 +@author: Mayar Ali. +""" + +def even_number_count(number: list) -> int: + """Returns the number of even numbers on the list. + + Parameters: + int: list, the input list to process + + return - > int: indicating the number of even number in the list + + Raises: + AssertionError: + + Examples: + >>> even_number_count ([1]) + 0 + >>> even_number_count ([2,1]) + 1 + >>> even_number_count ([3,2,1]) + 1 + """ + assert isinstance(number,list) + for num in number: + assert isinstance(num,int) + + count = 0 + + for num in number: + if num % 2 ==0: + count +=1 + return count + +if __name__ == "__main__": + + print(even_number_count([1,2,3,4,5])) + + diff --git a/solutions/tests/test_even_number_count.py b/solutions/tests/test_even_number_count.py index e69de29bb..5d65f0a3c 100644 --- a/solutions/tests/test_even_number_count.py +++ b/solutions/tests/test_even_number_count.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Monday/ 30/ December/2024 +@author: Mayar Ali + +""" + +import unittest + +# --- imports & test class before documenting and testing --- + +# from ..TestEvenNumberCount import TestEvenNumberCount + +# class TestTestEvenNumberCount(unittest.TestCase): + +# --- imports & test class after documenting and testing --- + +from ..even_number_count import even_number_count # type: ignore + +class TestEvenNumberCount(unittest.TestCase): + """test the even_number_count function """ + + def test_0(self): + """It should return zero""" + self.assertEqual(even_number_count([1]), 0) + + def test_1(self): + """It should count the number of even numbers in a countdown from n to 1 """ + self.assertEqual(even_number_count([1,2]), 1) + + def test_2(self): + """It should count the number of even numbers in a countdown from n to 1 """ + self.assertEqual(even_number_count([1,2,3]), 1) + + def test_3(self): + """It should count the number of even numbers in a countdown from n to 1 """ + self.assertEqual(even_number_count([1,2,3,4]), 2) + + def test_4(self): + """It should count the number of even numbers in a countdown from n to 1 """ + self.assertEqual(even_number_count([1,2,3,4,5]), 2) + + def test_5(self): + """It should count the number of even numbers in a countdown from n to 1 """ + self.assertEqual(even_number_count([1,2,3,4,5,6]), [3]) + + def test_6(self): + """It should count the number of even numbers in a countdown from n to 1 """ + self.assertEqual(even_number_count([1,2,3,4,5,6,7]), [3]) \ No newline at end of file From 05ce776c6cc8f2cbb817647ad470915fd6823cb7 Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Tue, 31 Dec 2024 19:46:27 +0200 Subject: [PATCH 15/43] Resolved some errors --- solutions/{even_number_count => even_number_count.py} | 0 solutions/tests/test_even_number_count.py | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename solutions/{even_number_count => even_number_count.py} (100%) diff --git a/solutions/even_number_count b/solutions/even_number_count.py similarity index 100% rename from solutions/even_number_count rename to solutions/even_number_count.py diff --git a/solutions/tests/test_even_number_count.py b/solutions/tests/test_even_number_count.py index 5d65f0a3c..f594365bd 100644 --- a/solutions/tests/test_even_number_count.py +++ b/solutions/tests/test_even_number_count.py @@ -43,8 +43,8 @@ def test_4(self): def test_5(self): """It should count the number of even numbers in a countdown from n to 1 """ - self.assertEqual(even_number_count([1,2,3,4,5,6]), [3]) + self.assertEqual(even_number_count([1,2,3,4,5,6]), 3) def test_6(self): """It should count the number of even numbers in a countdown from n to 1 """ - self.assertEqual(even_number_count([1,2,3,4,5,6,7]), [3]) \ No newline at end of file + self.assertEqual(even_number_count([1,2,3,4,5,6,7]), 3) \ No newline at end of file From e283b78bd99a930e9c4b8b16d20d9a4afeac7f0b Mon Sep 17 00:00:00 2001 From: Goutbi Date: Tue, 31 Dec 2024 22:23:13 +0400 Subject: [PATCH 16/43] adding the code without the tests --- solutions/fuel_gauge.py | 13 +++++++++++++ solutions/tests/test_fuel_gauge.py | 3 +++ 2 files changed, 16 insertions(+) diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py index e69de29bb..ed67fc240 100644 --- a/solutions/fuel_gauge.py +++ b/solutions/fuel_gauge.py @@ -0,0 +1,13 @@ +def fuel_gauge(x, y): + """ + + """ + if y == 0 or x > y: + raise ValueError("Invalid input: y must be greater than 0 (tank size can't be zero) and x must be less than or equal to y(fuel can't be more than the tank capacity).") + + percentage = (x / y) * 100 + if percentage >= 99: + return 'F' + elif percentage <= 1: + return 'E' + return int(percentage) diff --git a/solutions/tests/test_fuel_gauge.py b/solutions/tests/test_fuel_gauge.py index e69de29bb..9cd4d2a9e 100644 --- a/solutions/tests/test_fuel_gauge.py +++ b/solutions/tests/test_fuel_gauge.py @@ -0,0 +1,3 @@ +import unittest +from ..fuel_gauge import fuel_gauge + From 8014440ef8dbdc20f2470a77412ae21e1ea0c25b Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Tue, 31 Dec 2024 21:42:12 +0200 Subject: [PATCH 17/43] made changes on tests --- .vscode/settings.json | 9 ++-- solutions/arithmetic_sequence.py | 55 +++++++++++++++++++++ solutions/tests/test_arithmetic_sequence.py | 35 +++++++++++++ 3 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 solutions/arithmetic_sequence.py diff --git a/.vscode/settings.json b/.vscode/settings.json index bbda5188d..89cc035cc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -119,8 +119,11 @@ "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.ruff": true, - "source.organizeImports.ruff": true + "source.fixAll.ruff": "explicit", + "source.organizeImports.ruff": "explicit" } - } + }, + "cSpell.words": [ + "Mayar" + ] } diff --git a/solutions/arithmetic_sequence.py b/solutions/arithmetic_sequence.py new file mode 100644 index 000000000..c4abfd644 --- /dev/null +++ b/solutions/arithmetic_sequence.py @@ -0,0 +1,55 @@ + + +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for generating a sequence for arithmetic numbers + +Module contents: + - arithmetic_sequence:generating a sequence of n arithmetic numbers. + +Created on Sunday/22/December/2024 +@author:Mayar Ali +""" + +#---before documenting and testing--- + + +def arithmetic_sequence(sequence_length: int) -> list: + """ + Generates a list in which the difference between consecutive terms is constant. + Parameters: + sequence_length:int, greater than zero + +Returns -list[int] with the first n number of the arithmetic sequence + +Raises: + AssertionError : if the argument is not an integer + AssertionError : if the argument is less or equal to zero + + Examples: + >>>arithmetic_sequence(0) + [1] + >>>arithmetic_sequence(5) + [0 ,1 ,5 ,9 ,13] + >>>arithmetic_sequence(11) + [0 ,1 ,5 ,9 ,13 ,17 ,21 ,25 ,29 ,33 ,37 ] + """ + assert isinstance(sequence_length, int) + assert sequence_length >= 0 + + if sequence_length ==0: + return[] + if sequence_length ==1: + return[1] + if sequence_length ==2: + return[0, 1] + sequence = [0, 1] + while len(sequence) < sequence_length: + sequence.append(sequence[-1] + 3) + + return sequence + +if __name__ == "__main__": + + print(arithmetic_sequence(10)) diff --git a/solutions/tests/test_arithmetic_sequence.py b/solutions/tests/test_arithmetic_sequence.py index e69de29bb..d0b113fd5 100644 --- a/solutions/tests/test_arithmetic_sequence.py +++ b/solutions/tests/test_arithmetic_sequence.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Monday/30/December/2024 +@author:Mayar Ali +""" +import unittest + +#---imports & test class before documenting and testing--- +# from ..arithmetic_sequence import arithmetic_sequence +# class TestArithmeticSequence(unittest.TestCase): +#---imports & test class after documenting and testing--- + +from ..arithmetic_sequence import arithmetic_sequence + +class TestArithmeticSequence(unittest.TestCase): + """Test the arithmetic_sequence function""" + + def test_0(self): + "It should evaluate 0 to []" + self.assertEqual(arithmetic_sequence(0), []) + + def test_1(self): + "Should evaluate 1 to [0]" + self.assertEqual(arithmetic_sequence(1), [1]) + + def test_2(self): + "Should evaluate 2 to [0,1]" + self.assertEqual(arithmetic_sequence(2) ,[0,1]) + + def test_3(self): + "Should evaluate 3 to [0, 1, 5]" + self.assertEqual(arithmetic_sequence(3) ,[0, 1, 4]) + + From 2bc4f49413ad90180f65e674ebf3f6fd1aea1f5d Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Tue, 31 Dec 2024 22:28:46 +0200 Subject: [PATCH 18/43] Added defensive cases --- solutions/tests/test_arithmetic_sequence.py | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/solutions/tests/test_arithmetic_sequence.py b/solutions/tests/test_arithmetic_sequence.py index d0b113fd5..ee3b9ba1c 100644 --- a/solutions/tests/test_arithmetic_sequence.py +++ b/solutions/tests/test_arithmetic_sequence.py @@ -32,4 +32,24 @@ def test_3(self): "Should evaluate 3 to [0, 1, 5]" self.assertEqual(arithmetic_sequence(3) ,[0, 1, 4]) - +#defensive cases + + def test_0_less_than_0(self): + """It should raise an assertion error if the argument is less than 0""" + with self.assertRaises(AssertionError): + arithmetic_sequence(-1) + + def test_1_not_an_integer(self): + """It should raise an assertion error if the argument is not an integer""" + with self.assertRaises(AssertionError): + arithmetic_sequence(1.0) + + def test_2_not_an_integer(self): + """It should raise an assertion error if the argument is not an integer""" + with self.assertRaises(AssertionError): + arithmetic_sequence([1 ,2 ,3]) + + def test_3_not_an_integer(self): + """It should raise an assertion error if the argument is not an integer""" + with self.assertRaises(AssertionError): + arithmetic_sequence(["1" ,2 ,3]) From 01ceeee11d5b1bd21f753fe257877295ddd8cf24 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Wed, 1 Jan 2025 06:11:28 +0400 Subject: [PATCH 19/43] unittest added --- solutions/fuel_gauge.py | 14 ++++++------ solutions/tests/test_fuel_gauge.py | 34 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py index ed67fc240..5153aa255 100644 --- a/solutions/fuel_gauge.py +++ b/solutions/fuel_gauge.py @@ -1,13 +1,13 @@ def fuel_gauge(x, y): - """ - - """ + """ """ if y == 0 or x > y: - raise ValueError("Invalid input: y must be greater than 0 (tank size can't be zero) and x must be less than or equal to y(fuel can't be more than the tank capacity).") - + raise ValueError( + "Invalid input: y must be greater than 0 (tank size can't be zero) and x must be less than or equal to y(fuel can't be more than the tank capacity)." + ) + percentage = (x / y) * 100 if percentage >= 99: - return 'F' + return "F" elif percentage <= 1: - return 'E' + return "E" return int(percentage) diff --git a/solutions/tests/test_fuel_gauge.py b/solutions/tests/test_fuel_gauge.py index 9cd4d2a9e..446928b24 100644 --- a/solutions/tests/test_fuel_gauge.py +++ b/solutions/tests/test_fuel_gauge.py @@ -1,3 +1,37 @@ import unittest + from ..fuel_gauge import fuel_gauge + +class TestFuelGauge(unittest.TestCase): + """Test cases for the fuel_gauge function.""" + + def test_full(self): + """Test cases where the percentage is 99% or more.""" + self.assertEqual(fuel_gauge(99, 100), "F") + self.assertEqual(fuel_gauge(100, 100), "F") + + def test_empty(self): + """Test cases where the percentage is 1% or less.""" + self.assertEqual(fuel_gauge(1, 100), "E") + self.assertEqual( + fuel_gauge( + 0, + 100, + ), + "E", + ) + + def test_percentage(self): + """Test cases where the result is a percentage.""" + self.assertEqual(fuel_gauge(50, 100), 50) + self.assertEqual(fuel_gauge(25, 50), 50) + + def test_invalid_input(self): + """Test cases for invalid inputs.""" + with self.assertRaises(ValueError): + fuel_gauge(3, 0) + with self.assertRaises(ValueError): + fuel_gauge(4, 3) + with self.assertRaises(ValueError): + fuel_gauge("abc", "def") From 88ec7183d56a895554295facceed06ab3eba1540 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Wed, 1 Jan 2025 07:50:22 +0400 Subject: [PATCH 20/43] added unittests and comments --- solutions/fuel_gauge.py | 19 +++++++++++------ solutions/tests/test_fuel_gauge.py | 33 ++++++++++++------------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py index 5153aa255..551098ee9 100644 --- a/solutions/fuel_gauge.py +++ b/solutions/fuel_gauge.py @@ -1,13 +1,20 @@ def fuel_gauge(x, y): - """ """ + """ + This is a function that calculates the percentage of fuel in a tank. + + Parameters: + X= fuel in the tank (x value must be less than or equal to y) + Y= tank capacity (y value must be greater than 0)""" if y == 0 or x > y: - raise ValueError( - "Invalid input: y must be greater than 0 (tank size can't be zero) and x must be less than or equal to y(fuel can't be more than the tank capacity)." - ) + """This is a condition that checks if the tank size is zero or if the fuel is more than the tank capacity.""" + return "Invalid input" percentage = (x / y) * 100 - if percentage >= 99: + """This is a formula that calculates the percentage of fuel in the tank.""" + if percentage >= 90: return "F" - elif percentage <= 1: + elif percentage > 10: + return "M" + elif percentage <= 10: return "E" return int(percentage) diff --git a/solutions/tests/test_fuel_gauge.py b/solutions/tests/test_fuel_gauge.py index 446928b24..d1d8aed8a 100644 --- a/solutions/tests/test_fuel_gauge.py +++ b/solutions/tests/test_fuel_gauge.py @@ -7,31 +7,24 @@ class TestFuelGauge(unittest.TestCase): """Test cases for the fuel_gauge function.""" def test_full(self): - """Test cases where the percentage is 99% or more.""" - self.assertEqual(fuel_gauge(99, 100), "F") + """Test cases where the percentage is 90% or more it should result in F.""" + self.assertEqual(fuel_gauge(90, 100), "F") self.assertEqual(fuel_gauge(100, 100), "F") + self.assertEqual(fuel_gauge(97, 100), "F") def test_empty(self): - """Test cases where the percentage is 1% or less.""" - self.assertEqual(fuel_gauge(1, 100), "E") - self.assertEqual( - fuel_gauge( - 0, - 100, - ), - "E", - ) + """Test cases where the percentage is 10% or less it should result E.""" + self.assertEqual(fuel_gauge(10, 100), "E") + self.assertEqual(fuel_gauge(0, 100), "E") + self.assertEqual(fuel_gauge(2, 100), "E") def test_percentage(self): - """Test cases where the result is a percentage.""" - self.assertEqual(fuel_gauge(50, 100), 50) - self.assertEqual(fuel_gauge(25, 50), 50) + """Test cases where the result is between 90 and 10 it should be M.""" + self.assertEqual(fuel_gauge(71, 100), "M") + self.assertEqual(fuel_gauge(23, 100), "M") + self.assertEqual(fuel_gauge(10, 50), "M") def test_invalid_input(self): """Test cases for invalid inputs.""" - with self.assertRaises(ValueError): - fuel_gauge(3, 0) - with self.assertRaises(ValueError): - fuel_gauge(4, 3) - with self.assertRaises(ValueError): - fuel_gauge("abc", "def") + self.assertEqual(fuel_gauge(6, 0), "Invalid input") + self.assertEqual(fuel_gauge(7, -1), "Invalid input") From c75eb4a6132a11d7f699699b10b47dff4eff4a19 Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Wed, 1 Jan 2025 17:47:03 +0200 Subject: [PATCH 21/43] added edge case --- solutions/tests/test_arithmetic_sequence.py | 114 +++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/solutions/tests/test_arithmetic_sequence.py b/solutions/tests/test_arithmetic_sequence.py index ee3b9ba1c..ab01b8bd4 100644 --- a/solutions/tests/test_arithmetic_sequence.py +++ b/solutions/tests/test_arithmetic_sequence.py @@ -11,7 +11,7 @@ # class TestArithmeticSequence(unittest.TestCase): #---imports & test class after documenting and testing--- -from ..arithmetic_sequence import arithmetic_sequence +from..arithmetic_sequence import arithmetic_sequence class TestArithmeticSequence(unittest.TestCase): """Test the arithmetic_sequence function""" @@ -53,3 +53,115 @@ def test_3_not_an_integer(self): """It should raise an assertion error if the argument is not an integer""" with self.assertRaises(AssertionError): arithmetic_sequence(["1" ,2 ,3]) + +#Edge case + + def test_a_big_number(self): + "Should evaluate 100 to [0, 1, 5]" + self.assertEqual( + arithmetic_sequence(100) , + [ + 0, + 1, + 4, + 7, + 10, + 13, + 16, + 19, + 22, + 25, + 28, + 31, + 34, + 37, + 40, + 43, + 46, + 49, + 52, + 55, + 58, + 61, + 64, + 67, + 70, + 73, + 76, + 79, + 82, + 85, + 88, + 91, + 94, + 97, + 100, + 103, + 106, + 109, + 112, + 115, + 118, + 121, + 124, + 127, + 130, + 133, + 136, + 139, + 142, + 145, + 148, + 151, + 154, + 157, + 160, + 163, + 166, + 169, + 172, + 175, + 178, + 181, + 184, + 187, + 190, + 193, + 196, + 199, + 202, + 205, + 208, + 211, + 214, + 217, + 220, + 223, + 226, + 229, + 232, + 235, + 238, + 241, + 244, + 247, + 250, + 253, + 256, + 259, + 262, + 265, + 268, + 271, + 274, + 277, + 280, + 283, + 286, + 289, + 292, + 295, + ] + ) + + From 9ab033b10ae3ec7fb18c306bedeafcb6c9a4e111 Mon Sep 17 00:00:00 2001 From: RAFAA ALI Date: Wed, 1 Jan 2025 21:08:17 +0400 Subject: [PATCH 22/43] FooBar code --- .vscode/settings.json | 4 ++-- solutions/FooBar_code.py | 13 +++++++++++++ solutions/tests/test_FooBar_code.py | 10 ++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 solutions/FooBar_code.py create mode 100644 solutions/tests/test_FooBar_code.py diff --git a/.vscode/settings.json b/.vscode/settings.json index bbda5188d..252022b48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -119,8 +119,8 @@ "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.ruff": true, - "source.organizeImports.ruff": true + "source.fixAll.ruff": "explicit", + "source.organizeImports.ruff": "explicit" } } } diff --git a/solutions/FooBar_code.py b/solutions/FooBar_code.py new file mode 100644 index 000000000..6d5c7595a --- /dev/null +++ b/solutions/FooBar_code.py @@ -0,0 +1,13 @@ +def FooBar_code(n: int): + assert isinstance(n, int), "N must be integer" + result = [] + for i in range(1, n + 1): + if i % 4 == 0 and i % 6 == 0: + result.append("FooBar") + elif i % 4 == 0: + result.append("foo") + elif i % 6 == 0: + result.append("Bar") + else: + result.append(i) + return result diff --git a/solutions/tests/test_FooBar_code.py b/solutions/tests/test_FooBar_code.py new file mode 100644 index 000000000..21d045247 --- /dev/null +++ b/solutions/tests/test_FooBar_code.py @@ -0,0 +1,10 @@ +import unittest + +from ..FooBar_code import FooBar_code + + +class TestFooBar(unittest.TestCase): + def test_int(self): + self.assertEqual( + FooBar_code(12), [1, 2, 3, "foo", 5, "Bar", 7, "foo", 9, 10, 11, "FooBar"] + ) From 5d5e16fca217411d6528de5a796461a06912989c Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Wed, 1 Jan 2025 19:43:38 +0200 Subject: [PATCH 23/43] Extre changed and CI checks --- solutions/__init__.py | 1 - solutions/arithmetic_sequence.py | 64 ++++++++++----------- solutions/tests/__init__.py | 1 - solutions/tests/test_arithmetic_sequence.py | 38 ++++++------ 4 files changed, 47 insertions(+), 57 deletions(-) diff --git a/solutions/__init__.py b/solutions/__init__.py index 8b1378917..e69de29bb 100644 --- a/solutions/__init__.py +++ b/solutions/__init__.py @@ -1 +0,0 @@ - diff --git a/solutions/arithmetic_sequence.py b/solutions/arithmetic_sequence.py index c4abfd644..fbab5c1fc 100644 --- a/solutions/arithmetic_sequence.py +++ b/solutions/arithmetic_sequence.py @@ -1,55 +1,53 @@ - - #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ A module for generating a sequence for arithmetic numbers -Module contents: +Module contents: - arithmetic_sequence:generating a sequence of n arithmetic numbers. Created on Sunday/22/December/2024 @author:Mayar Ali """ -#---before documenting and testing--- +# ---before documenting and testing--- def arithmetic_sequence(sequence_length: int) -> list: - """ - Generates a list in which the difference between consecutive terms is constant. - Parameters: - sequence_length:int, greater than zero - -Returns -list[int] with the first n number of the arithmetic sequence - -Raises: - AssertionError : if the argument is not an integer - AssertionError : if the argument is less or equal to zero - - Examples: - >>>arithmetic_sequence(0) - [1] - >>>arithmetic_sequence(5) - [0 ,1 ,5 ,9 ,13] - >>>arithmetic_sequence(11) - [0 ,1 ,5 ,9 ,13 ,17 ,21 ,25 ,29 ,33 ,37 ] + """ + list in which the difference between consecutive terms is constant. + Parameters: + sequence_length:int, greater than zero + + Returns -list[int] with the first n number of the arithmetic sequence + + Raises: + AssertionError : if the argument is not an integer + AssertionError : if the argument is less or equal to zero + + Examples: + >>>arithmetic_sequence(0) + [1] + >>>arithmetic_sequence(5) + [0 ,1 ,5 ,9 ,13] + >>>arithmetic_sequence(11) + [0 ,1 ,5 ,9 ,13 ,17 ,21 ,25 ,29 ,33 ,37 ] """ assert isinstance(sequence_length, int) assert sequence_length >= 0 - - if sequence_length ==0: - return[] - if sequence_length ==1: - return[1] - if sequence_length ==2: - return[0, 1] + + if sequence_length == 0: + return [] + if sequence_length == 1: + return [1] + if sequence_length == 2: + return [0, 1] sequence = [0, 1] while len(sequence) < sequence_length: - sequence.append(sequence[-1] + 3) - + sequence.append(sequence[-1] + 3) + return sequence + if __name__ == "__main__": - - print(arithmetic_sequence(10)) + print(arithmetic_sequence(20)) diff --git a/solutions/tests/__init__.py b/solutions/tests/__init__.py index 8b1378917..e69de29bb 100644 --- a/solutions/tests/__init__.py +++ b/solutions/tests/__init__.py @@ -1 +0,0 @@ - diff --git a/solutions/tests/test_arithmetic_sequence.py b/solutions/tests/test_arithmetic_sequence.py index ab01b8bd4..f1b305569 100644 --- a/solutions/tests/test_arithmetic_sequence.py +++ b/solutions/tests/test_arithmetic_sequence.py @@ -4,18 +4,19 @@ Created on Monday/30/December/2024 @author:Mayar Ali """ + import unittest -#---imports & test class before documenting and testing--- +# ---imports & test class before documenting and testing--- # from ..arithmetic_sequence import arithmetic_sequence # class TestArithmeticSequence(unittest.TestCase): -#---imports & test class after documenting and testing--- +# ---imports & test class after documenting and testing--- + +from ..arithmetic_sequence import arithmetic_sequence -from..arithmetic_sequence import arithmetic_sequence class TestArithmeticSequence(unittest.TestCase): """Test the arithmetic_sequence function""" - def test_0(self): "It should evaluate 0 to []" self.assertEqual(arithmetic_sequence(0), []) @@ -26,13 +27,13 @@ def test_1(self): def test_2(self): "Should evaluate 2 to [0,1]" - self.assertEqual(arithmetic_sequence(2) ,[0,1]) + self.assertEqual(arithmetic_sequence(2), [0, 1]) def test_3(self): "Should evaluate 3 to [0, 1, 5]" - self.assertEqual(arithmetic_sequence(3) ,[0, 1, 4]) + self.assertEqual(arithmetic_sequence(3), [0, 1, 4]) -#defensive cases + # defensive cases def test_0_less_than_0(self): """It should raise an assertion error if the argument is less than 0""" @@ -40,26 +41,21 @@ def test_0_less_than_0(self): arithmetic_sequence(-1) def test_1_not_an_integer(self): - """It should raise an assertion error if the argument is not an integer""" + """Should raise an assertion error if the argument is not an integer""" with self.assertRaises(AssertionError): - arithmetic_sequence(1.0) + arithmetic_sequence(1.0) def test_2_not_an_integer(self): - """It should raise an assertion error if the argument is not an integer""" - with self.assertRaises(AssertionError): - arithmetic_sequence([1 ,2 ,3]) - - def test_3_not_an_integer(self): - """It should raise an assertion error if the argument is not an integer""" + """Should raise an assertion error if the argument is not an integer""" with self.assertRaises(AssertionError): - arithmetic_sequence(["1" ,2 ,3]) + arithmetic_sequence(["1", 2, 3]) -#Edge case + # Edge case def test_a_big_number(self): "Should evaluate 100 to [0, 1, 5]" self.assertEqual( - arithmetic_sequence(100) , + arithmetic_sequence(100), [ 0, 1, @@ -161,7 +157,5 @@ def test_a_big_number(self): 289, 292, 295, - ] - ) - - + ], + ) From 6d777201ff3799a60fee8972f5fb178d78e23d06 Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Wed, 1 Jan 2025 20:07:33 +0200 Subject: [PATCH 24/43] changed documentation --- solutions/tests/test_arithmetic_sequence.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solutions/tests/test_arithmetic_sequence.py b/solutions/tests/test_arithmetic_sequence.py index f1b305569..026e2392c 100644 --- a/solutions/tests/test_arithmetic_sequence.py +++ b/solutions/tests/test_arithmetic_sequence.py @@ -17,6 +17,7 @@ class TestArithmeticSequence(unittest.TestCase): """Test the arithmetic_sequence function""" + def test_0(self): "It should evaluate 0 to []" self.assertEqual(arithmetic_sequence(0), []) @@ -41,7 +42,7 @@ def test_0_less_than_0(self): arithmetic_sequence(-1) def test_1_not_an_integer(self): - """Should raise an assertion error if the argument is not an integer""" + """Should raise an assertion error if the argument is a float""" with self.assertRaises(AssertionError): arithmetic_sequence(1.0) From 185b27979a83c135d291044fc4cbf071bb844452 Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Wed, 1 Jan 2025 21:06:51 +0200 Subject: [PATCH 25/43] CI Checks --- solutions/__init__.py | 1 - solutions/even_number_count.py | 25 +-- solutions/tests/__init__.py | 1 - solutions/tests/test_even_number_count.py | 254 ++++++++++++++++++++-- 4 files changed, 251 insertions(+), 30 deletions(-) diff --git a/solutions/__init__.py b/solutions/__init__.py index 8b1378917..e69de29bb 100644 --- a/solutions/__init__.py +++ b/solutions/__init__.py @@ -1 +0,0 @@ - diff --git a/solutions/even_number_count.py b/solutions/even_number_count.py index 63ea6c592..4f076d41c 100644 --- a/solutions/even_number_count.py +++ b/solutions/even_number_count.py @@ -4,23 +4,24 @@ A function that counts the number of even numbers in a countdown from n to 1 Module contents: - - even_number_count: generates a number for the amount of even numbers in the list. + - even_number_count: gen number for even numbers in the list. Created on Monday/ 30/ December/ 2024 @author: Mayar Ali. """ + def even_number_count(number: list) -> int: """Returns the number of even numbers on the list. Parameters: - int: list, the input list to process + int: list, the input list to process return - > int: indicating the number of even number in the list Raises: - AssertionError: - + AssertionError: + Examples: >>> even_number_count ([1]) 0 @@ -29,19 +30,17 @@ def even_number_count(number: list) -> int: >>> even_number_count ([3,2,1]) 1 """ - assert isinstance(number,list) + assert isinstance(number, list) for num in number: - assert isinstance(num,int) - + assert isinstance(num, int) + count = 0 for num in number: - if num % 2 ==0: - count +=1 + if num % 2 == 0: + count += 1 return count -if __name__ == "__main__": - - print(even_number_count([1,2,3,4,5])) - +if __name__ == "__main__": + print(even_number_count([1, 2, 3, 4, 5])) diff --git a/solutions/tests/__init__.py b/solutions/tests/__init__.py index 8b1378917..e69de29bb 100644 --- a/solutions/tests/__init__.py +++ b/solutions/tests/__init__.py @@ -1 +0,0 @@ - diff --git a/solutions/tests/test_even_number_count.py b/solutions/tests/test_even_number_count.py index f594365bd..303ee6a07 100644 --- a/solutions/tests/test_even_number_count.py +++ b/solutions/tests/test_even_number_count.py @@ -16,35 +16,259 @@ # --- imports & test class after documenting and testing --- -from ..even_number_count import even_number_count # type: ignore +from ..even_number_count import even_number_count # type: ignore + class TestEvenNumberCount(unittest.TestCase): - """test the even_number_count function """ + """test the even_number_count function""" def test_0(self): """It should return zero""" self.assertEqual(even_number_count([1]), 0) def test_1(self): - """It should count the number of even numbers in a countdown from n to 1 """ - self.assertEqual(even_number_count([1,2]), 1) + """Count the number of even numbers in a countdown from n to 1""" + self.assertEqual(even_number_count([1, 2]), 1) def test_2(self): - """It should count the number of even numbers in a countdown from n to 1 """ - self.assertEqual(even_number_count([1,2,3]), 1) + """Count the number of even numbers in a countdown from n to 1""" + self.assertEqual(even_number_count([1, 2, 3]), 1) def test_3(self): - """It should count the number of even numbers in a countdown from n to 1 """ - self.assertEqual(even_number_count([1,2,3,4]), 2) - + """Count the number of even numbers in a countdown from n to 1""" + self.assertEqual(even_number_count([1, 2, 3, 4]), 2) + def test_4(self): - """It should count the number of even numbers in a countdown from n to 1 """ - self.assertEqual(even_number_count([1,2,3,4,5]), 2) + """Count the number of even numbers in a countdown from n to 1""" + self.assertEqual(even_number_count([1, 2, 3, 4, 5]), 2) def test_5(self): - """It should count the number of even numbers in a countdown from n to 1 """ - self.assertEqual(even_number_count([1,2,3,4,5,6]), 3) + """Count the number of even numbers in a countdown from n to 1""" + self.assertEqual(even_number_count([1, 2, 3, 4, 5, 6]), 3) def test_6(self): - """It should count the number of even numbers in a countdown from n to 1 """ - self.assertEqual(even_number_count([1,2,3,4,5,6,7]), 3) \ No newline at end of file + """Count the number of even numbers in a countdown from n to 1""" + self.assertEqual(even_number_count([1, 2, 3, 4, 5, 6, 7]), 3) + + # Boundary case + + def test_big_numbers(self): + """it should evaluate 100 to [1,2,3,4,5,...]""" + self.assertEqual( + even_number_count( + [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110, + 111, + 112, + 113, + 114, + 115, + 116, + 117, + 118, + 119, + 120, + 121, + 122, + 123, + 124, + 125, + 126, + 127, + 128, + 129, + 130, + 131, + 132, + 133, + 134, + 135, + 136, + 137, + 138, + 139, + 140, + 141, + 142, + 143, + 145, + 146, + 147, + 148, + 149, + 150, + 151, + 152, + 153, + 154, + 155, + 156, + 157, + 158, + 159, + 160, + 161, + 162, + 163, + 164, + 165, + 166, + 167, + 168, + 169, + 170, + 171, + 172, + 173, + 174, + 175, + 176, + 177, + 178, + 179, + 180, + 181, + 182, + 183, + 184, + 185, + 186, + 187, + 188, + 189, + 190, + 191, + 192, + 193, + 194, + 195, + 196, + 197, + 198, + 199, + 200, + ] + ), + 99, + ) + + # Defensive cases + + def test_0_less_than_0(self): + """Raise an assertion error if the there is a string within a list""" + with self.assertRaises(AssertionError): + (even_number_count([1, 2, "-6", 4]),) + + def test_0_less_than_1(self): + """Raise an assertion error if the there is a list within a list""" + with self.assertRaises(AssertionError): + even_number_count([1, 2, [1, 2, 3], 4]) From 5bd9e005d52a6d32d1c572cee166150577d2b75a Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Wed, 1 Jan 2025 22:48:41 +0200 Subject: [PATCH 26/43] added --- solutions/tests/test_arithmetic_sequence.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solutions/tests/test_arithmetic_sequence.py b/solutions/tests/test_arithmetic_sequence.py index 026e2392c..9d5cd19d5 100644 --- a/solutions/tests/test_arithmetic_sequence.py +++ b/solutions/tests/test_arithmetic_sequence.py @@ -56,7 +56,7 @@ def test_2_not_an_integer(self): def test_a_big_number(self): "Should evaluate 100 to [0, 1, 5]" self.assertEqual( - arithmetic_sequence(100), + arithmetic_sequence(101), [ 0, 1, @@ -158,5 +158,6 @@ def test_a_big_number(self): 289, 292, 295, + 298 ], ) From b75c05a602bd53a5de0b47a3e33f8eb1671831da Mon Sep 17 00:00:00 2001 From: Mayar-Agab Date: Wed, 1 Jan 2025 22:55:00 +0200 Subject: [PATCH 27/43] extended example --- solutions/tests/test_arithmetic_sequence.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/solutions/tests/test_arithmetic_sequence.py b/solutions/tests/test_arithmetic_sequence.py index 9d5cd19d5..5fe1172a3 100644 --- a/solutions/tests/test_arithmetic_sequence.py +++ b/solutions/tests/test_arithmetic_sequence.py @@ -56,7 +56,7 @@ def test_2_not_an_integer(self): def test_a_big_number(self): "Should evaluate 100 to [0, 1, 5]" self.assertEqual( - arithmetic_sequence(101), + arithmetic_sequence(102), [ 0, 1, @@ -158,6 +158,7 @@ def test_a_big_number(self): 289, 292, 295, - 298 + 298, + 301, ], ) From b86f0661db0fb3cf12bff981a4d355bd4f6609c6 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Thu, 2 Jan 2025 08:19:59 +0400 Subject: [PATCH 28/43] modified code and added doctests --- solutions/fuel_gauge.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py index 551098ee9..641d65345 100644 --- a/solutions/fuel_gauge.py +++ b/solutions/fuel_gauge.py @@ -1,20 +1,36 @@ -def fuel_gauge(x, y): +def fuel_gauge(x: int, y: int) -> str: """ - This is a function that calculates the percentage of fuel in a tank. + Calculates the percentage of fuel in a tank and returns a status indicator. Parameters: - X= fuel in the tank (x value must be less than or equal to y) - Y= tank capacity (y value must be greater than 0)""" + x (int): Fuel in the tank (must be ≤ y). + y (int): Tank capacity (must be > 0). + + Returns: + str: + - "F" if percentage >= 90. + - "E" if percentage <= 10. + - "M" for all other cases. + - "Invalid input" for invalid parameters. + + Raises: + AssertionError: If y <= 0 or x > y. + + Examples: + >>> fuel_gauge(90, 100) + 'F' + >>> fuel_gauge(10, 100) + 'E' + >>> fuel_gauge(50, 100) + 'M' + """ if y == 0 or x > y: - """This is a condition that checks if the tank size is zero or if the fuel is more than the tank capacity.""" return "Invalid input" percentage = (x / y) * 100 - """This is a formula that calculates the percentage of fuel in the tank.""" if percentage >= 90: return "F" - elif percentage > 10: - return "M" elif percentage <= 10: return "E" - return int(percentage) + else: + return "M" From 772978924a05b11667e9b2e2173fbbbbcc7fe3e5 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Thu, 2 Jan 2025 08:31:26 +0400 Subject: [PATCH 29/43] modified code and added doctests --- solutions/fuel_gauge.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py index 551098ee9..641d65345 100644 --- a/solutions/fuel_gauge.py +++ b/solutions/fuel_gauge.py @@ -1,20 +1,36 @@ -def fuel_gauge(x, y): +def fuel_gauge(x: int, y: int) -> str: """ - This is a function that calculates the percentage of fuel in a tank. + Calculates the percentage of fuel in a tank and returns a status indicator. Parameters: - X= fuel in the tank (x value must be less than or equal to y) - Y= tank capacity (y value must be greater than 0)""" + x (int): Fuel in the tank (must be ≤ y). + y (int): Tank capacity (must be > 0). + + Returns: + str: + - "F" if percentage >= 90. + - "E" if percentage <= 10. + - "M" for all other cases. + - "Invalid input" for invalid parameters. + + Raises: + AssertionError: If y <= 0 or x > y. + + Examples: + >>> fuel_gauge(90, 100) + 'F' + >>> fuel_gauge(10, 100) + 'E' + >>> fuel_gauge(50, 100) + 'M' + """ if y == 0 or x > y: - """This is a condition that checks if the tank size is zero or if the fuel is more than the tank capacity.""" return "Invalid input" percentage = (x / y) * 100 - """This is a formula that calculates the percentage of fuel in the tank.""" if percentage >= 90: return "F" - elif percentage > 10: - return "M" elif percentage <= 10: return "E" - return int(percentage) + else: + return "M" From 88712dd74cf1a3b02dc95b2e2010c4bf74d93259 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Thu, 2 Jan 2025 08:46:26 +0400 Subject: [PATCH 30/43] modified the code and added doctests --- solutions/fuel_gauge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py index 641d65345..eb00a1f0d 100644 --- a/solutions/fuel_gauge.py +++ b/solutions/fuel_gauge.py @@ -4,7 +4,7 @@ def fuel_gauge(x: int, y: int) -> str: Parameters: x (int): Fuel in the tank (must be ≤ y). - y (int): Tank capacity (must be > 0). + y (int): Tank capacity (must be > 0, the tank can't be 0 or a negative value). Returns: str: From 2fb77a08dcd2c7832589f211e15f35cfa49c28d5 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Thu, 2 Jan 2025 09:11:04 +0400 Subject: [PATCH 31/43] modified the code --- solutions/fuel_gauge.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py index eb00a1f0d..553998c17 100644 --- a/solutions/fuel_gauge.py +++ b/solutions/fuel_gauge.py @@ -4,14 +4,14 @@ def fuel_gauge(x: int, y: int) -> str: Parameters: x (int): Fuel in the tank (must be ≤ y). - y (int): Tank capacity (must be > 0, the tank can't be 0 or a negative value). + y (int): Tank capacity (must be > 0, the tank can't be 0 or a negative number). Returns: str: - "F" if percentage >= 90. - "E" if percentage <= 10. - "M" for all other cases. - - "Invalid input" for invalid parameters. + - "Invalid input" for invalid inputs. Raises: AssertionError: If y <= 0 or x > y. From 60aafa60c5f2d32f8b82579c2e3dbd9cc1022c2e Mon Sep 17 00:00:00 2001 From: Goutbi Date: Thu, 2 Jan 2025 09:16:28 +0400 Subject: [PATCH 32/43] resolving python formatting -1 --- solutions/fuel_gauge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py index 553998c17..a4dcac5da 100644 --- a/solutions/fuel_gauge.py +++ b/solutions/fuel_gauge.py @@ -4,7 +4,7 @@ def fuel_gauge(x: int, y: int) -> str: Parameters: x (int): Fuel in the tank (must be ≤ y). - y (int): Tank capacity (must be > 0, the tank can't be 0 or a negative number). + y (int): Tank capacity (must be > 0). Returns: str: From 6f5f69e7bfb2242a50bd30a8a1c3016ad6d94b5f Mon Sep 17 00:00:00 2001 From: Goutbi Date: Thu, 2 Jan 2025 09:26:35 +0400 Subject: [PATCH 33/43] fixing pyformatting -2 --- solutions/fuel_gauge.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/solutions/fuel_gauge.py b/solutions/fuel_gauge.py index a4dcac5da..fbc35ca08 100644 --- a/solutions/fuel_gauge.py +++ b/solutions/fuel_gauge.py @@ -1,3 +1,6 @@ +"""module calculates the percentage of fuel in a tank and returns a status indicator.""" + + def fuel_gauge(x: int, y: int) -> str: """ Calculates the percentage of fuel in a tank and returns a status indicator. @@ -7,7 +10,7 @@ def fuel_gauge(x: int, y: int) -> str: y (int): Tank capacity (must be > 0). Returns: - str: + str: - "F" if percentage >= 90. - "E" if percentage <= 10. - "M" for all other cases. From f27bfb783b02ec64fda22da821d0eb1d11ed3e79 Mon Sep 17 00:00:00 2001 From: RAFAA ALI Date: Thu, 2 Jan 2025 23:13:00 +0400 Subject: [PATCH 34/43] tests have been added --- solutions/FooBar_code.py | 51 ++++++++++++++++++++++++++ solutions/tests/test_FooBar_code.py | 55 ++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/solutions/FooBar_code.py b/solutions/FooBar_code.py index 6d5c7595a..ee05eb825 100644 --- a/solutions/FooBar_code.py +++ b/solutions/FooBar_code.py @@ -1,4 +1,55 @@ +""" +Creates a sequence where numbers divisible by 4 return 'Foo', +numbers divisible by 6 return 'Bar', numbers divisible by both +return 'FooBar', and other numbers remain unchanged. + +Author: Rafaa Ali +Created date: 1.1.2025 +""" + + def FooBar_code(n: int): + """This function, `FooBar_code`, creates a sequence that replaces numbers + based on their divisibility by 4 and 6. + + Parameters: + n (int):the last number in the list + + Returns: + List containing the sequence with 'Foo', 'Bar', 'FooBar' or numbers + + assertion: + n must be integer otherwise error + + + example: + Edge cases: + >>> FooBar_code(1) + [1] + >>> FooBar_code(0) + [] + >>> FooBar_code(-1) + [] + + Standard cases: + >>> FooBar_code(8) + [1, 2, 3, 'Foo', 5, 'Bar', 7, 'Foo'] + >>> FooBar_code(12) + [1, 2, 3, 'Foo', 5, 'Bar', 7, 'Foo', 9, 10, 11, 'FooBar'] + >>> FooBar_code(16) + [1, 2, 3, 'Foo', 5, 'Bar', 7, 'Foo', 9, 10, 11, 'FooBar', + 13, 14, 15, 'Foo'] + + Defensive cases: + >>> FooBar_code("rafaa") + AssertionError: N must be integer + >>> FooBar_code(5.5) + AssertionError: N must be integer + >>> FooBar_code([1, 2, 3]) + AssertionError: N must be integer + + + """ assert isinstance(n, int), "N must be integer" result = [] for i in range(1, n + 1): diff --git a/solutions/tests/test_FooBar_code.py b/solutions/tests/test_FooBar_code.py index 21d045247..3b1f67331 100644 --- a/solutions/tests/test_FooBar_code.py +++ b/solutions/tests/test_FooBar_code.py @@ -4,7 +4,60 @@ class TestFooBar(unittest.TestCase): - def test_int(self): + # Edge cases: + def test_int1(self): + self.assertEqual(FooBar_code(1), [1]) + + def test_int0(self): + self.assertEqual(FooBar_code(0), []) + + def test_negative_int(self): + self.assertEqual(FooBar_code(-1), []) + + # Standard cases: + def test_int8(self): + self.assertEqual(FooBar_code(8), [1, 2, 3, "foo", 5, "Bar", 7, "foo"]) + + def test_int12(self): self.assertEqual( FooBar_code(12), [1, 2, 3, "foo", 5, "Bar", 7, "foo", 9, 10, 11, "FooBar"] ) + + def test_is_int(self): + self.assertEqual( + FooBar_code(16), + [ + 1, + 2, + 3, + "foo", + 5, + "Bar", + 7, + "foo", + 9, + 10, + 11, + "FooBar", + 13, + 14, + 15, + "foo", + ], + ) + + # defensive cases + def test_string_input(self): + """It should raise AssertionError for string input""" + with self.assertRaises(AssertionError): + FooBar_code("rafaa") + + def test_is_float_input(self): + """It should raise AssertionError for float input""" + with self.assertRaises(AssertionError): + FooBar_code(5.5) + + def test_is_list_input(self): + """It should raise AssertionError for list input""" + with self.assertRaises(AssertionError): + FooBar_code([1, 2, 3]) From bb6b72aea6d3ab61937fe33613284dafa42cd7f8 Mon Sep 17 00:00:00 2001 From: RAFAA ALI Date: Thu, 2 Jan 2025 23:38:35 +0400 Subject: [PATCH 35/43] docstring has been added --- solutions/FooBar_code.py | 11 +++++++++++ solutions/tests/test_FooBar_code.py | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/solutions/FooBar_code.py b/solutions/FooBar_code.py index ee05eb825..d73611426 100644 --- a/solutions/FooBar_code.py +++ b/solutions/FooBar_code.py @@ -50,15 +50,26 @@ def FooBar_code(n: int): """ + # assert an error when n is not integer assert isinstance(n, int), "N must be integer" + # prepare empty list for the result result = [] + # loop for checking the sequence for i in range(1, n + 1): + # checking if the number is devisable by 4 and 6 if i % 4 == 0 and i % 6 == 0: + # add FooBar to the list if it devisable by both 4,6 result.append("FooBar") + # checking if the number is devisable by 4 elif i % 4 == 0: + # add Foo to the list if it devisable by 4 result.append("foo") + # checking if the number is devisable by 6 elif i % 6 == 0: + # add Bar to the list if it devisable by 6 result.append("Bar") + # otherwise add the number to the list else: result.append(i) + # return the result's list return result diff --git a/solutions/tests/test_FooBar_code.py b/solutions/tests/test_FooBar_code.py index 3b1f67331..412a520b7 100644 --- a/solutions/tests/test_FooBar_code.py +++ b/solutions/tests/test_FooBar_code.py @@ -6,24 +6,30 @@ class TestFooBar(unittest.TestCase): # Edge cases: def test_int1(self): + """check if the input is 1""" self.assertEqual(FooBar_code(1), [1]) def test_int0(self): + """check if the input is 0""" self.assertEqual(FooBar_code(0), []) def test_negative_int(self): + """check if the input is negative""" self.assertEqual(FooBar_code(-1), []) # Standard cases: def test_int8(self): + """check if the input is 8""" self.assertEqual(FooBar_code(8), [1, 2, 3, "foo", 5, "Bar", 7, "foo"]) def test_int12(self): + """check if the input is 12""" self.assertEqual( FooBar_code(12), [1, 2, 3, "foo", 5, "Bar", 7, "foo", 9, 10, 11, "FooBar"] ) def test_is_int(self): + """check if the input is large number""" self.assertEqual( FooBar_code(16), [ From ebc09b73b7e21491be8882d78ef1d51beae74614 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Sat, 4 Jan 2025 12:27:10 +0400 Subject: [PATCH 36/43] Adding the armstrong checker --- solutions/armstrong_checker.py | 35 +++++++++++++++++++++++ solutions/armstrong_number.py | 0 solutions/tests/test_armstrong_checker.py | 24 ++++++++++++++++ solutions/tests/test_armstrong_number.py | 0 4 files changed, 59 insertions(+) create mode 100644 solutions/armstrong_checker.py delete mode 100644 solutions/armstrong_number.py create mode 100644 solutions/tests/test_armstrong_checker.py delete mode 100644 solutions/tests/test_armstrong_number.py diff --git a/solutions/armstrong_checker.py b/solutions/armstrong_checker.py new file mode 100644 index 000000000..794f203de --- /dev/null +++ b/solutions/armstrong_checker.py @@ -0,0 +1,35 @@ +"""Module checks if a number is an Armstrong number.""" + + +def armstrong_checker(number: int) -> str: + """ + Checks if a given positive integer is an Armstrong number. + + Parameters: + number (int): The number to check (must be > 0). + + Returns: + str: + - "True" if the number is an Armstrong number. + - "False" if the number is not an Armstrong number. + - "Invalid input" for invalid inputs. + + Raises: + AssertionError: If the input is not a positive integer. + + Examples: + >>> armstrong_checker(153) + 'True' + >>> armstrong_checker(123) + 'False' + >>> armstrong_checker(-153) + 'Invalid input' + """ + if not isinstance(number, int) or number < 0: + return "Invalid input" + + digits = [int(d) for d in str(number)] + n = len(digits) + armstrong_sum = sum(d**n for d in digits) + + return "True" if armstrong_sum == number else "False" diff --git a/solutions/armstrong_number.py b/solutions/armstrong_number.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/solutions/tests/test_armstrong_checker.py b/solutions/tests/test_armstrong_checker.py new file mode 100644 index 000000000..54aec7a8a --- /dev/null +++ b/solutions/tests/test_armstrong_checker.py @@ -0,0 +1,24 @@ +import unittest + +from ..armstrong_checker import armstrong_checker + + +class TestArmstrongChecker(unittest.TestCase): + """Test cases for the armstrong_checker function.""" + + def test_valid_armstrong_numbers(self): + """Test cases where the number is an Armstrong number.""" + self.assertEqual(armstrong_checker(153), "True") + self.assertEqual(armstrong_checker(9474), "True") + self.assertEqual(armstrong_checker(9475), "False") + + def test_non_armstrong_numbers(self): + """Test cases where the number is not an Armstrong number.""" + self.assertEqual(armstrong_checker(123), "False") + self.assertEqual(armstrong_checker(100), "False") + + def test_invalid_inputs(self): + """Test cases for invalid inputs.""" + self.assertEqual(armstrong_checker(-153), "Invalid input") + self.assertEqual(armstrong_checker("153"), "Invalid input") + self.assertEqual(armstrong_checker(0.5), "Invalid input") diff --git a/solutions/tests/test_armstrong_number.py b/solutions/tests/test_armstrong_number.py deleted file mode 100644 index e69de29bb..000000000 From 55746c157837b557ebb79477abadef64a39b08e7 Mon Sep 17 00:00:00 2001 From: Goutbi Date: Sat, 4 Jan 2025 13:07:37 +0400 Subject: [PATCH 37/43] adding comments to describe the code functions --- solutions/armstrong_checker.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/solutions/armstrong_checker.py b/solutions/armstrong_checker.py index 794f203de..087d35cfb 100644 --- a/solutions/armstrong_checker.py +++ b/solutions/armstrong_checker.py @@ -28,8 +28,15 @@ def armstrong_checker(number: int) -> str: if not isinstance(number, int) or number < 0: return "Invalid input" + # Calculate the sum of the nth power of each digit in the number. digits = [int(d) for d in str(number)] + # digits puts each digit in the number into a list + n = len(digits) + # n is the number of digits in the number by using the len() function + armstrong_sum = sum(d**n for d in digits) + # armstrong_sum is the sum of the nth power of each digit in the number return "True" if armstrong_sum == number else "False" + # if the sum of the nth power of each digit in the number is equal to the number, return "True", otherwise return "False" From 62a781add2b787c689646701302107809d8fa0f4 Mon Sep 17 00:00:00 2001 From: RAFAA ALI Date: Sun, 5 Jan 2025 01:15:39 +0400 Subject: [PATCH 38/43] fixing importing issues --- solutions/FooBar_code.py | 4 +- solutions/count_characters.py | 67 ++++++++++++++++++++++++ solutions/tests/test_FooBar_code.py | 4 +- solutions/tests/test_count_characters.py | 57 ++++++++++++++++++++ 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 solutions/count_characters.py create mode 100644 solutions/tests/test_count_characters.py diff --git a/solutions/FooBar_code.py b/solutions/FooBar_code.py index d73611426..8c5bf9fe3 100644 --- a/solutions/FooBar_code.py +++ b/solutions/FooBar_code.py @@ -13,10 +13,10 @@ def FooBar_code(n: int): based on their divisibility by 4 and 6. Parameters: - n (int):the last number in the list + n (int):the last number in the list Returns: - List containing the sequence with 'Foo', 'Bar', 'FooBar' or numbers + List containing the sequence with 'Foo', 'Bar', 'FooBar' or numbers assertion: n must be integer otherwise error diff --git a/solutions/count_characters.py b/solutions/count_characters.py new file mode 100644 index 000000000..d30cd0d12 --- /dev/null +++ b/solutions/count_characters.py @@ -0,0 +1,67 @@ +""" +Creates a function that counts the number of vowels (a, e, i, o, u) in a given string. +The function is case-insensitive, meaning both uppercase and lowercase vowels are counted. + +Author: Rafaa Ali +Created date: 3.1.2025 +""" + + +def count_characters(string: str) -> int: + """This function, `count_vowels`, counts the number of vowels in a given string, + ignoring case sensitivity. + + Parameters: + string (str): The input string to count vowels from + + Returns: + int: The total number of vowels in the string + + assertion: + string must be string type otherwise error + + example: + Edge cases: + >>> count_characters("") + 0 + >>> count_characters("krm") + 0 + >>> count_characters(" ") + 0 + + Standard cases: + >>> count_characters lowercase("hello") + 2 + >>> count_characters uppercase("RAFF") + 1 + >>>count_characters mixed case("aEiOu") + 5 + + Defensive cases: + >>> count_characters(123) + AssertionError: Input must be string + >>>count_characters(["hello"]) + AssertionError: Input must be string + >>> count_characters(None) + AssertionError: Input must be string + """ + # assert an error when input is not string + assert isinstance(string, str), "Input must be string" + + # Convert string to lowercase for case-insensitive counting + string = string.lower() + + # Define vowels to check against + vowels = "aeiou" + + # Initialize counter for vowels + count = 0 + + # Loop through each character in the string + for char in string: + # If character is a vowel, increment counter + if char in vowels: + count += 1 + + # Return the total count of vowels + return count diff --git a/solutions/tests/test_FooBar_code.py b/solutions/tests/test_FooBar_code.py index 412a520b7..33e4c2a32 100644 --- a/solutions/tests/test_FooBar_code.py +++ b/solutions/tests/test_FooBar_code.py @@ -1,9 +1,11 @@ +"""test module for FooBar_code function""" import unittest -from ..FooBar_code import FooBar_code +from FooBar_code import FooBar_code class TestFooBar(unittest.TestCase): + """ this class to test FooBar_code function """ # Edge cases: def test_int1(self): """check if the input is 1""" diff --git a/solutions/tests/test_count_characters.py b/solutions/tests/test_count_characters.py new file mode 100644 index 000000000..7493f3532 --- /dev/null +++ b/solutions/tests/test_count_characters.py @@ -0,0 +1,57 @@ +import unittest +from .. count_characters import count_characters + +class Testcount_characters(unittest.TestCase): + # Edge cases: + def test_empty_string(self): + """check if the input is empty string""" + self.assertEqual(count_characters(""), 0) + + def test_no_vowels(self): + """check if string has no vowels""" + self.assertEqual(count_characters("krm"), 0) + + """check if string is just whitespace""" + self.assertEqual(count_characters(" "), 0) + + # Standard cases: + def test_lowercase_word(self): + """check if handles lowercase correctly""" + self.assertEqual(count_characters("hello"), 2) + + def test_uppercase_word(self): + """check if handles uppercase correctly""" + self.assertEqual(count_characters("RAFF"), 1) + + def test_mixed_case(self): + """check if handles mixed case correctly""" + self.assertEqual(count_characters("aEiOu"), 5) + + def test_sentence(self): + """check if handles full sentence correctly""" + self.assertEqual(count_characters("Hello World"), 3) + + def test_all_vowels(self): + """check if counts all vowel types correctly""" + self.assertEqual(count_characters("AeIoU"), 5) + + # defensive cases + def test_number_input(self): + """It should raise AssertionError for integer input""" + with self.assertRaises(AssertionError): + count_characters(123) + + def test_list_input(self): + """It should raise AssertionError for list input""" + with self.assertRaises(AssertionError): + count_characters(["hello"]) + + def test_none_input(self): + """It should raise AssertionError for None input""" + with self.assertRaises(AssertionError): + count_characters(None) + + def test_float_input(self): + """It should raise AssertionError for float input""" + with self.assertRaises(AssertionError): + count_characters(3.14) \ No newline at end of file From 32be9d9998c8f04462933167e96f4bb21491b216 Mon Sep 17 00:00:00 2001 From: RAFAA ALI Date: Sun, 5 Jan 2025 01:27:55 +0400 Subject: [PATCH 39/43] fixing more issues --- solutions/tests/test_FooBar_code.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/solutions/tests/test_FooBar_code.py b/solutions/tests/test_FooBar_code.py index 33e4c2a32..3eb613132 100644 --- a/solutions/tests/test_FooBar_code.py +++ b/solutions/tests/test_FooBar_code.py @@ -1,11 +1,13 @@ """test module for FooBar_code function""" + import unittest -from FooBar_code import FooBar_code +from solutions.FooBar_code import FooBar_code class TestFooBar(unittest.TestCase): - """ this class to test FooBar_code function """ + """this class to test FooBar_code function""" + # Edge cases: def test_int1(self): """check if the input is 1""" From d0503fc7706ae4769041bf28c0f93b0015c0a270 Mon Sep 17 00:00:00 2001 From: RAFAA ALI Date: Sun, 5 Jan 2025 21:43:15 +0400 Subject: [PATCH 40/43] delete extra files --- solutions/FooBar_code.py | 75 ----------------------------- solutions/tests/test_FooBar_code.py | 73 ---------------------------- 2 files changed, 148 deletions(-) delete mode 100644 solutions/FooBar_code.py delete mode 100644 solutions/tests/test_FooBar_code.py diff --git a/solutions/FooBar_code.py b/solutions/FooBar_code.py deleted file mode 100644 index 8c5bf9fe3..000000000 --- a/solutions/FooBar_code.py +++ /dev/null @@ -1,75 +0,0 @@ -""" -Creates a sequence where numbers divisible by 4 return 'Foo', -numbers divisible by 6 return 'Bar', numbers divisible by both -return 'FooBar', and other numbers remain unchanged. - -Author: Rafaa Ali -Created date: 1.1.2025 -""" - - -def FooBar_code(n: int): - """This function, `FooBar_code`, creates a sequence that replaces numbers - based on their divisibility by 4 and 6. - - Parameters: - n (int):the last number in the list - - Returns: - List containing the sequence with 'Foo', 'Bar', 'FooBar' or numbers - - assertion: - n must be integer otherwise error - - - example: - Edge cases: - >>> FooBar_code(1) - [1] - >>> FooBar_code(0) - [] - >>> FooBar_code(-1) - [] - - Standard cases: - >>> FooBar_code(8) - [1, 2, 3, 'Foo', 5, 'Bar', 7, 'Foo'] - >>> FooBar_code(12) - [1, 2, 3, 'Foo', 5, 'Bar', 7, 'Foo', 9, 10, 11, 'FooBar'] - >>> FooBar_code(16) - [1, 2, 3, 'Foo', 5, 'Bar', 7, 'Foo', 9, 10, 11, 'FooBar', - 13, 14, 15, 'Foo'] - - Defensive cases: - >>> FooBar_code("rafaa") - AssertionError: N must be integer - >>> FooBar_code(5.5) - AssertionError: N must be integer - >>> FooBar_code([1, 2, 3]) - AssertionError: N must be integer - - - """ - # assert an error when n is not integer - assert isinstance(n, int), "N must be integer" - # prepare empty list for the result - result = [] - # loop for checking the sequence - for i in range(1, n + 1): - # checking if the number is devisable by 4 and 6 - if i % 4 == 0 and i % 6 == 0: - # add FooBar to the list if it devisable by both 4,6 - result.append("FooBar") - # checking if the number is devisable by 4 - elif i % 4 == 0: - # add Foo to the list if it devisable by 4 - result.append("foo") - # checking if the number is devisable by 6 - elif i % 6 == 0: - # add Bar to the list if it devisable by 6 - result.append("Bar") - # otherwise add the number to the list - else: - result.append(i) - # return the result's list - return result diff --git a/solutions/tests/test_FooBar_code.py b/solutions/tests/test_FooBar_code.py deleted file mode 100644 index 3eb613132..000000000 --- a/solutions/tests/test_FooBar_code.py +++ /dev/null @@ -1,73 +0,0 @@ -"""test module for FooBar_code function""" - -import unittest - -from solutions.FooBar_code import FooBar_code - - -class TestFooBar(unittest.TestCase): - """this class to test FooBar_code function""" - - # Edge cases: - def test_int1(self): - """check if the input is 1""" - self.assertEqual(FooBar_code(1), [1]) - - def test_int0(self): - """check if the input is 0""" - self.assertEqual(FooBar_code(0), []) - - def test_negative_int(self): - """check if the input is negative""" - self.assertEqual(FooBar_code(-1), []) - - # Standard cases: - def test_int8(self): - """check if the input is 8""" - self.assertEqual(FooBar_code(8), [1, 2, 3, "foo", 5, "Bar", 7, "foo"]) - - def test_int12(self): - """check if the input is 12""" - self.assertEqual( - FooBar_code(12), [1, 2, 3, "foo", 5, "Bar", 7, "foo", 9, 10, 11, "FooBar"] - ) - - def test_is_int(self): - """check if the input is large number""" - self.assertEqual( - FooBar_code(16), - [ - 1, - 2, - 3, - "foo", - 5, - "Bar", - 7, - "foo", - 9, - 10, - 11, - "FooBar", - 13, - 14, - 15, - "foo", - ], - ) - - # defensive cases - def test_string_input(self): - """It should raise AssertionError for string input""" - with self.assertRaises(AssertionError): - FooBar_code("rafaa") - - def test_is_float_input(self): - """It should raise AssertionError for float input""" - with self.assertRaises(AssertionError): - FooBar_code(5.5) - - def test_is_list_input(self): - """It should raise AssertionError for list input""" - with self.assertRaises(AssertionError): - FooBar_code([1, 2, 3]) From 1886a9fec6eec4bf171e7ca55d5dbc0146c0a7e4 Mon Sep 17 00:00:00 2001 From: RAFAA ALI Date: Sun, 5 Jan 2025 21:49:44 +0400 Subject: [PATCH 41/43] solving ruff issues --- solutions/tests/test_count_characters.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/solutions/tests/test_count_characters.py b/solutions/tests/test_count_characters.py index 7493f3532..0adadd5f4 100644 --- a/solutions/tests/test_count_characters.py +++ b/solutions/tests/test_count_characters.py @@ -1,5 +1,6 @@ import unittest -from .. count_characters import count_characters +from ..count_characters import count_characters + class Testcount_characters(unittest.TestCase): # Edge cases: @@ -54,4 +55,4 @@ def test_none_input(self): def test_float_input(self): """It should raise AssertionError for float input""" with self.assertRaises(AssertionError): - count_characters(3.14) \ No newline at end of file + count_characters(3.14) From 7329b598109c37478e76f241c138ec448c91398a Mon Sep 17 00:00:00 2001 From: RAFAA ALI Date: Mon, 6 Jan 2025 19:32:16 +0400 Subject: [PATCH 42/43] docstring editing --- .vscode/settings.json | 2 +- solutions/count_characters.py | 2 +- solutions/tests/test_count_characters.py | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 252022b48..84916e5c9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,7 @@ //-------- Editor configuration -------- // Controls auto save of editors that have unsaved changes.: https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save - "files.autoSave": "onFocusChange", + "files.autoSave": "off", // Format a file on save. A formatter must be available. "editor.formatOnSave": true, diff --git a/solutions/count_characters.py b/solutions/count_characters.py index d30cd0d12..6ea62bebf 100644 --- a/solutions/count_characters.py +++ b/solutions/count_characters.py @@ -12,7 +12,7 @@ def count_characters(string: str) -> int: ignoring case sensitivity. Parameters: - string (str): The input string to count vowels from + string (str): The input string to count vowels characters Returns: int: The total number of vowels in the string diff --git a/solutions/tests/test_count_characters.py b/solutions/tests/test_count_characters.py index 0adadd5f4..104e4715c 100644 --- a/solutions/tests/test_count_characters.py +++ b/solutions/tests/test_count_characters.py @@ -1,8 +1,16 @@ +""" +test_count_characters.py +this module contains unit tests for the 'count_characters' +function + +""" + import unittest + from ..count_characters import count_characters -class Testcount_characters(unittest.TestCase): +class TestCountCharacters(unittest.TestCase): # Edge cases: def test_empty_string(self): """check if the input is empty string""" From 5cbcb6689ac127e960d525c49a384dbb11c104d9 Mon Sep 17 00:00:00 2001 From: RAFAA ALI Date: Sun, 12 Jan 2025 17:57:13 +0400 Subject: [PATCH 43/43] adding enhancment --- solutions/count_characters.py | 2 ++ solutions/tests/test_count_characters.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/solutions/count_characters.py b/solutions/count_characters.py index 6ea62bebf..6ba169087 100644 --- a/solutions/count_characters.py +++ b/solutions/count_characters.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 +# -- coding: utf-8 -- """ Creates a function that counts the number of vowels (a, e, i, o, u) in a given string. The function is case-insensitive, meaning both uppercase and lowercase vowels are counted. diff --git a/solutions/tests/test_count_characters.py b/solutions/tests/test_count_characters.py index 104e4715c..409ccc6f9 100644 --- a/solutions/tests/test_count_characters.py +++ b/solutions/tests/test_count_characters.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 +# -- coding: utf-8 -- """ test_count_characters.py this module contains unit tests for the 'count_characters'