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

Added doctests for matrix/count_islands_in_matrix.py #12555

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

CheerfulBear22
Copy link

Describe your change:

Related to #9943

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Comment on lines 6 to 18
class Matrix: # Public class to implement a graph
def __init__(self, row: int, col: int, graph: list[list[bool]]) -> None:
"""
Initialise matrix with number of rows, columns, and graph

>>> m = Matrix(4, 3, [[True, False, False, False], [True, False, True, False], [False, False, True, True]])
>>> m.ROW
4
>>> m.COL
3
>>> m.graph
[[True, False, False, False], [True, False, True, False], [False, False, True, True]]
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the row and col parameters from the Matrix init and instead derive them from the graph's dimensions. This prevents inconsistencies and possible index errors.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully that should be good now. Let me know if there's anything else that needs fixing

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Feb 4, 2025
Comment on lines -29 to +76
def count_islands(self) -> int: # And finally, count all islands.
def count_islands(self) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not Required initially to define the function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed

Comment on lines -21 to +54
# Checking all 8 elements surrounding nth element
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to define the element in the comments when it's already presented?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be sorted now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants