mojo icon indicating copy to clipboard operation
mojo copied to clipboard

`TestSuite` not overloaded for basic types like Int

Open hoxha-saber opened this issue 1 year ago • 2 comments

Bug Description

There is a compiler error when using the TestSuite on Int values. Consider the following code snippet

from Testing import TestSuite
let x: Int = 42
let y: Int = 42
let ts = TestSuite("testing")
ts.assertEqual(x, y)

When run on the Mojo playground I get the following error:

error: Expression [31]:22:19: invalid call to 'assertEqual': callee expects 2 input parameters but 0 were provided
    ts.assertEqual(x, y)
    ~~~~~~~~~~~~~~^~~~~~

/.modular/Kernels/mojo/Stdlib/Testing.mojo:81:5: function declared here
    fn assertEqual[
    ^

Steps to Reproduce

  1. Run the above code snippet
  2. Observe the error

Additional notes

The above code snippet also doesn't work for assertAlmostEqual. Also, as notied in the discord the code snippet below does work:

let x: SI32 = 42
let y: SI32 = 42
let ts = TestSuite("testing")
print(ts.assertEqual(x, y))

hoxha-saber avatar May 03 '23 23:05 hoxha-saber

Thanks for the issue! This doesn't seem to be a bug -- rather the API for TestSuite only seems to be providing overloads for the SIMD type. @abduld FYI

Mogball avatar May 04 '23 05:05 Mogball

Oh right, I probably should have noticed that in the declaration... I guess I expect it to work with any type that defines some form of mojo equivalent operator==. Perhaps a parameterized version can be added later to accommodate for that?

Thanks

hoxha-saber avatar May 04 '23 13:05 hoxha-saber