Skip to content

Box Class Implementation #141

@Swapnilden

Description

@Swapnilden

Summary

The initial implementation of the Box class contains several bugs and areas for improvement. This report identifies the issues and proposes a solution to address them.

Description of Issues

  1. Side Counting Bug:
  • Issue: The sides attribute is incremented each time a side is set, regardless of whether the side was previously unset. This can lead to incorrect counting if a side is set multiple times.

  • Impact: Incorrectly incrementing sides could prematurely mark a box as complete (with all four sides set) when it is not.

  1. Repetitive Code in Setters:
  • Issue: The setters for _top, _bottom, _left, and _right are repetitive and contain similar logic.

  • Impact: This makes the code harder to maintain and increases the likelihood of bugs.

Proposed Changes

  1. Fix Side Counting:
  • Implement a check to ensure that sides is only incremented if the side was previously unset.
  1. Refactor Setters:
  • Use a private method _set_side to handle the logic for setting sides, reducing code repetition and improving maintainability.
  1. Additional Enhancements:
  • Add type hints and docstrings for better code readability and maintainability.

  • Implement a method to get neighboring boxes, which can be useful for grid-based logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions