Skip to content

Missing equals and hash implementation #16

@HossamSaberr

Description

@HossamSaberr

While reviewing CTQueue, I noticed that two distinct queue instances containing the exact same elements in the same order are not considered equal.

Because CTQueue inherits directly from Object it misses out on the default content-based = and hash methods provided by the Pharo Collection hierarchy. Consequently, equality checks fall back to memory identity (==).

Failing Test to Reproduce:
Adding the following test to CTQueueTest reproduces the issue:

testEquality
	| q1 q2 |
	q1 := CTQueue new.
	q2 := CTQueue new.
	
	q1 enqueue: 'A'; enqueue: 'B'.
	q2 enqueue: 'A'; enqueue: 'B'.
	
	self assert: q1 equals: q2.
	self assert: q1 hash equals: q2 hash.

Proposed Solution:
Implement custom = and hash methods in CTQueue to ensure equality is evaluated based on the queue's size and the ordered contents of its internal elements, rather than its memory address.

I would be happy to open a PR for this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions