Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Employee #82

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
countvowel
  • Loading branch information
majdadel20 committed Jan 7, 2025
commit 4c518c38a884816a033951f990a7399077631b6c
1 change: 1 addition & 0 deletions solutions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 0 additions & 2 deletions solutions/intersection_element.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Write Python 3 code in this online

def common_elements(list1, list2):
# Convert both lists to sets to remove duplicates and find intersection
set1 = set(list1)
Expand Down
18 changes: 12 additions & 6 deletions solutions/tests/test_intersection_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,42 @@ def common_elements(list1, list2):
result = common_elements(list1, list2)
print(result) # Output: [4, 5, 6]

# Example usage
list1 = [1, 2, 3, 4, 5, 6]
list2 = [4, 5, 6, 7, 8, 9]
result = common_elements(list1, list2) # type: ignore
print(result) # Output: [4, 5, 6]

def test_common_elements():
# Test case 1: Common elements exist
list1 = [1, 2, 3, 4, 5]
list2 = [4, 5, 6, 7, 8]
assert sorted(common_elements(list1, list2)) == [4, 5], "Test case 1 failed"
assert sorted(common_elements(list1, list2)) == [4, 5], "Test case 1 failed" # type: ignore

# Test case 2: No common elements
list1 = [1, 2, 3]
list2 = [4, 5, 6]
assert common_elements(list1, list2) == [], "Test case 2 failed"
assert common_elements(list1, list2) == [], "Test case 2 failed" # type: ignore

# Test case 3: Identical lists
list1 = [1, 2, 3, 4, 5]
list2 = [1, 2, 3, 4, 5]
assert sorted(common_elements(list1, list2)) == [1, 2, 3, 4, 5], "Test case 3 failed"
assert sorted(common_elements(list1, list2)) == [1, 2, 3, 4, 5], "Test case 3 failed" # type: ignore

# Test case 4: One list is empty
list1 = []
list2 = [1, 2, 3]
assert common_elements(list1, list2) == [], "Test case 4 failed"
assert common_elements(list1, list2) == [], "Test case 4 failed" # type: ignore

# Test case 5: Both lists are empty
list1 = []
list2 = []
assert common_elements(list1, list2) == [], "Test case 5 failed"
assert common_elements(list1, list2) == [], "Test case 5 failed" # type: ignore

# Test case 6: Lists with duplicate elements
list1 = [1, 2, 2, 3, 4]
list2 = [3, 3, 4, 5, 6]
assert sorted(common_elements(list1, list2)) == [3, 4], "Test case 6 failed"
assert sorted(common_elements(list1, list2)) == [3, 4], "Test case 6 failed" # type: ignore

print("All test cases passed!")

Expand Down