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

[stdlib] Add array_tester with Tester and Testee for lists #3565

Open
wants to merge 1 commit into
base: nightly
Choose a base branch
from

Conversation

rd4com
Copy link
Contributor

@rd4com rd4com commented Sep 29, 2024

Introducing two new types for testing lists and datastructures.
(Tester and Testee)

Testee can be used as the element type of an array or a similar datastructure.
Tester holds Int fields to count the amount of moves, copy, init, del.

Multiple instances of Testee contains an UnsafePointer to an instance of Tester.
Assertions can be created on the current amount of init, copy, del, moves a list does.

Additionally, Testee have an Int field to store a value.
That value can be used to check the equality of the elements of two lists.

Example:

def main():
    var _tester = Tester()
    var x = List[Testee]()
    for i in range(10):
        x.append(Testee(_tester, i))
    for i in x: print(i[].value)
    assert_equal(_tester.oninit, 10)
    assert_equal(_tester.ondelete, 0)
    assert_equal(_tester.oncopy, 0)
    y = x[0]
    assert_equal(y.value, 0)
    assert_equal(_tester.oncopy, 1)
    _ = x.pop()
    assert_equal(_tester.ondelete, 2)
    __type_of(x).__del__(x^)
    assert_equal(_tester.ondelete, 11)
    assert_equal(_tester.oncopy, 1)

@rd4com rd4com requested a review from a team as a code owner September 29, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant