mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[stdlib] Add `array_tester` with `Tester` and `Testee` for lists

Open rd4com opened this issue 4 months ago • 0 comments

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 avatar Sep 29 '24 16:09 rd4com