Skip to content

Commit

Permalink
Merge branch 'main' into 61-names-asc-sorter-new
Browse files Browse the repository at this point in the history
  • Loading branch information
mohd-makki authored Jan 13, 2025
2 parents 79f1838 + a7c3acf commit b577918
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 1 deletion.
41 changes: 40 additions & 1 deletion collaboration/retrospective.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,59 @@

## Stop Doing

- Missing meetings.
- Absence of effective communication.
- Non-compliance with deadlines.
- Not adhering to group norms strictly.

## Continue Doing

- Collaborative work.
- Access to support whenever needed.
- Open to learn and to ask.
- Consistency with work.
- Good and organized planning.

## Start Doing

- Use the GitHub discussion section more frequently.
- Peer programming.
- Detailed documentation of work and activities.
- Create a detailed project timeline.
- Assign tasks and roles at the outset of the project.
- Keep meetings shorter and on a fixed agreed-upon day.
- Understand everyone’s strengths and weaknesses, then build a common ground.

## Lessons Learned

- GitHub workflow.
- Project management.
- VScode workflow.
- Navigating issues related to Python, GitHub, and VSCode.
- Flexibility.
- Clear communication is the key for asynchronous collaboration.

______________________________________________________________________

## Strategy vs. Board

### What parts of your plan went as expected?

- Communication with the team.
- Collaborating on GitHub.
- The majority of team members were able to meet the project's main requirements
before the final deadline.
- All team members were cautious with the repository.

### What parts of your plan did not work out?

- **Internal deadline:** Some team members missed it.
- **Time management and availability:** Coordinating meetings with all team members
was quite challenging.

### Did you need to add things that weren't in your strategy?

### Or remove extra steps?
- Include an alternative communication medium.
- Ensure that everyone is on the same page and understands the workflow.
- Utilize a task management tool such as **_Asana_** or **_Trello_** for more insights
and details into the progress of each team member.
44 changes: 44 additions & 0 deletions solutions/least_common_multiple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A module for calculating the Least Common Multiple (LCM) of a list of three integers
Module contents:
- least_common_multiple: function to calculates the LCM
Created on 12/01/2025
@author: Amin
"""


def least_common_multiple(nums: list) -> int:
"""calculate the Least Common Multiple for a list of three integers.
Parameters:
nums: list, the input list containing the three integers
Returns -> int: the Least Common Multiple for the three integers
Raises:
AssertionError: if the argument is not a list
Examples:
>>> least_common_multiple([1, 2, 3])
6
>>> least_common_multiple([3, 4, 5])
60
>>> least_common_multiple([2, 1, 5])
10
"""
assert isinstance(nums, list), "input must be a list"
# Check if the input list contains three elements
if len(nums) != 3:
return -1
# Sort the input list of integers
nums.sort()
# Iterate through multiples of the greatest number (c) within a range up to the numbers product
# Return the first multiple that is divisible by the other numbers (b, a)
c = nums[2]
b = nums[1]
a = nums[0]
for i in range(c, c * b * a + 1, c):
if i % b == 0 and i % a == 0:
return i
56 changes: 56 additions & 0 deletions solutions/maximum_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A module to find the maximum length of the
concatenation of a subsequence of arr that has unique characters.
Return the maximum possible length of s
Module contents:
- maxLength: Function to get the Maximum Length of a Concatenated String with Unique Characters
- backtrack: Helper function to perform backtracking
Created on 2024-01-12
Author: Kefah Albashityalshaer
"""


def max_length(arr: list) -> int:
"""
Function to get the Maximum Length of a Concatenated String with Unique Characters
Takes a list of strings and returns the max length of concatenated string with unique characters
Parameters:
arr: list of stings elements to process
Returns -> int: the maximum length
Examples:
>>> max_length(["un","iq","ue"])
4
>>> max_length(["cha","r","act","ers"])
6
>>> max_length(["abcdefghijklmnopqrstuvwxyz"])
26
>>> max_length(["a", "bb", "ccc"])
1
>>> max_length([])
0
"""
assert isinstance(arr, list), "input should be a list of strings"

# Helper function to perform backtracking
def backtrack(index, current_string):
# If the current string has duplicate characters, return 0
if len(current_string) != len(set(current_string)):
return 0

# Calculate the maximum length by trying to add each subsequent string
max_length = len(current_string)
for i in range(index, len(arr)):
max_length = max(max_length, backtrack(i + 1, current_string + arr[i]))
return max_length

# Start the backtracking from index 0 and an empty string
return backtrack(0, "")
61 changes: 61 additions & 0 deletions solutions/tests/test_least_common_multiple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A module for testing the least_common_multiple function.
Test cases include:
- Valid inputs: a list of three integers.
- Sorted and unsorted numbers.
- Invalid inputs: a list of invalid range.
- A list containing number formats other than integers.
- Edge cases: special numbers such as 0 and negative numbers.
Created on 12/01/2025
@author: Amin
"""

import unittest

from ..least_common_multiple import least_common_multiple


class TestLeastCommonMultiple(unittest.TestCase):
"""Test the least_common_multiple function"""

def test_sorted_list(self):
"""It should return the Least Common Multiple for a sorted list of three integers"""
self.assertEqual(least_common_multiple([2, 3, 4]), 12)

def test_unsorted_list(self):
"""It should return the Least Common Multiple for a sorted list of three integers"""
self.assertEqual(least_common_multiple([5, 2, 4]), 20)

def test_more_than_three_numbers(self):
"""It should return -1 for a list containing more than three integers"""
self.assertEqual(least_common_multiple([1, 2, 3, 4]), -1)

def test_fewer_than_three_numbers(self):
"""It should return -1 for a list containing fewer than three integers"""
self.assertEqual(least_common_multiple([1, 2]), -1)

def test_empty_list(self):
"""It should return -1 for an empty list"""
self.assertEqual(least_common_multiple([]), -1)

def test_including_zero(self):
"""It should return None for lists including 0"""
self.assertEqual(least_common_multiple([0, 2, 4]), None)

def test_including_negative_numbers(self):
"""It should return None for lists including 0"""
self.assertEqual(least_common_multiple([-1, 9, 5]), None)

def test_non_integer_numbers(self):
"""It should raise ValueError for lists containing numbers other than integers"""
with self.assertRaises(TypeError):
least_common_multiple([1.2, 5, 2])

def test_not_list(self):
"""It should raise AssertionError for non-list inputs"""
with self.assertRaises(AssertionError):
least_common_multiple("not a list")
70 changes: 70 additions & 0 deletions solutions/tests/test_maximum_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Test module for maximum_length function.
Test categories:
- Standard cases: list of strings that may have unique or overlapping characters
- Edge cases: empty lists, strings with identical bounds or duplicate characters, substrings with repetitive letters
- Defensive tests: invalid inputs, assertions, or `TypeError` exceptions
Created on 2024-01-12
Author: Kefah Albashityalshaer
"""

import unittest

from ..maximum_length import max_length


class TestMaxLengthFunction(unittest.TestCase):
# Standard test cases
def test_basic_cases(self):
self.assertEqual(
max_length(["un", "iq", "ue"]), 4
) # "uniq" forms a concatenated string of length 4
self.assertEqual(
max_length(["cha", "r", "act", "ers"]), 6
) # The longest concatenated string is "acters" (length 6)
self.assertEqual(
max_length(["abcdefghijklmnopqrstuvwxyz"]), 26
) # The string contains all unique lowercase letters (length 26)

# Edge Cases
def test_empty_list(self):
self.assertEqual(
max_length([]), 0
) # No strings to concatenate, so the result is 0

def test_single_element(self):
self.assertEqual(max_length(["a"]), 1)
self.assertEqual(max_length(["abcdef"]), 6)

def test_no_unique_concatenation(self):
self.assertEqual(max_length(["a", "bb", "ccc"]), 1)

def test_repeated_characters(self):
self.assertEqual(max_length(["abc", "def", "abc"]), 6)

def test_large_input(self):
arr = ["ab", "cd", "ef", "gh", "ij", "kl", "mnop"]
self.assertEqual(max_length(arr), 16) # Longest possible combination

# Defensive tests
def test_invalid_input(self):
with self.assertRaises(
AssertionError,
msg="Input should raise an AssertionError for non-list input.",
):
max_length("not a list")

def test_non_string_input(self):
with self.assertRaises(TypeError):
max_length(["abc", 123, "def"])

def test_empty_strings(self):
self.assertEqual(max_length(["", "abc", "de"]), 5)


if __name__ == "__main__":
unittest.main()

0 comments on commit b577918

Please sign in to comment.