Skip to content

Clean up the fractals directory - #15099

Merged
cclauss merged 2 commits into
TheAlgorithms:masterfrom
priya-sundaram-dev:cleanup-fractals
Aug 28, 2026
Merged

Clean up the fractals directory#15099
cclauss merged 2 commits into
TheAlgorithms:masterfrom
priya-sundaram-dev:cleanup-fractals

Conversation

@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Follows #15098 (networking_flow) as the next directory in the tidy-up shortlist from #15081, keeping to the one-directory-at-a-time cadence.

What this adds

  • fractals/README.md — an overview table of every fractal in the directory, how to run each one, and further reading. It separates the visual demos (turtle / matplotlib / PIL) from the pure-computation generators that can run under doctest in CI without a display.
  • fractals/sierpinski_carpet.py — a new, display-free Sierpinski carpet built with integer arithmetic. is_filled(), generate_carpet() and count_filled_cells() are all type-hinted and doctested (the closed-form 8**depth count is cross-checked against a brute-force scan).
  • fractals/barnsley_fern.py — the Barnsley fern iterated function system. transform(), choose_transformation() and generate_fern() are type-hinted and doctested; output is made deterministic via an optional seed, and the matplotlib plot is optional and guarded behind __main__.

The directory previously had no README and only visual (turtle / image) generators. These two additions are fully verifiable in CI.

Checklist

  • Add an algorithm?
  • 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.
  • ruff check and ruff format --check pass on the new files.

Add a directory README plus two new, fully doctested fractal generators.

- README.md: overview table of every fractal, how to run them, and further
  reading. Distinguishes the visual (turtle/matplotlib) demos from the
  pure-computation ones that run under doctest in CI.
- sierpinski_carpet.py: integer-arithmetic Sierpinski carpet. is_filled(),
  generate_carpet() and count_filled_cells() are all doctested; no display
  needed.
- barnsley_fern.py: the Barnsley fern iterated function system. transform(),
  choose_transformation() and generate_fern() are doctested and made
  deterministic via an optional seed; matplotlib plotting is optional and
  guarded behind __main__.
@algorithms-keeper algorithms-keeper Bot added documentation This PR modified documentation files require tests Tests [doctest/unittest/pytest] are required labels Aug 27, 2026

@algorithms-keeper algorithms-keeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

Comment thread fractals/barnsley_fern.py Outdated
return points


def main() -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file fractals/barnsley_fern.py, please provide doctest for the function main

Comment thread fractals/sierpinski_carpet.py Outdated
return 8**depth


def main() -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file fractals/sierpinski_carpet.py, please provide doctest for the function main

@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Aug 27, 2026
@priya-sundaram-dev

Copy link
Copy Markdown
Contributor Author

Thanks, keeper-bot. Both main() functions were display-only (matplotlib plot / print), so I moved that demo code directly under if __name__ == "__main__": and added a doctest.testmod() call there. No named function is now left without a doctest, and the computational functions (generate_fern, generate_carpet, count_filled_cells, etc.) all keep their doctests. Ready for review.

@algorithms-keeper algorithms-keeper Bot removed the require tests Tests [doctest/unittest/pytest] are required label Aug 27, 2026

@cclauss cclauss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fantastic!! Fractals are everywhere!

@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Aug 28, 2026
@cclauss
cclauss merged commit 1813f7d into TheAlgorithms:master Aug 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation This PR modified documentation files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants