cspec icon indicating copy to clipboard operation
cspec copied to clipboard

Assertions for arrays

Open faloi opened this issue 10 years ago • 1 comments

It would be nice to have array equality assertions, comparing element by element.

Some thoughts about this:

  • As seen here, C++ supports literal arrays, but I believe it's mandatory to assign them to a variable: int expected[] = { 16, 2, 77, 40, 12071 };. It would be great to avoid the variable and write something like should(numbers) be equal({ 16, 2, 77, 40, 12071 })
  • The user should be able to decide whether the elements must be in the same order or not

faloi avatar Jun 17 '14 18:06 faloi

Regarding literal arrays, you can avoid the variable by casting (starting C99). Something like this should work:

should(numbers) be equal (int[5] { 16, 2, 77, 40, 12071 })

And equal signature shoud be something like:

equal(int a[static 1]);

Ref: http://stackoverflow.com/a/1269651/1335438

mdumrauf avatar Apr 22 '15 21:04 mdumrauf