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

Assertions for arrays #1

Open
faloi opened this issue Jun 17, 2014 · 1 comment
Open

Assertions for arrays #1

faloi opened this issue Jun 17, 2014 · 1 comment

Comments

@faloi
Copy link
Contributor

faloi commented Jun 17, 2014

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 faloi changed the title Assertions para arrays Arrays assertions Jun 18, 2014
@faloi faloi changed the title Arrays assertions Assertions for arrays Jun 18, 2014
@mdumrauf
Copy link

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

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

No branches or pull requests

2 participants