What is the correct way to check the number of NSArray elements using STAssertEquals for NSArray.
The following work is expected:
... STAssertEquals(1, [myArray count], @"One item should be in array");
This code generates a "Type of mismatch" runtime error when running the test.
Instead, I have to do an explicit cast to NSUInteger:
STAssertEquals((NSUInteger)1, [myArray count], @"One item should be in array");
It works - but it looks clearly ugly due to an explicit cast.
I also want to avoid using STAssertTrue, because STAssertEquals looks more appropriate (we compare two values) and show the actual and expected values.
What is the correct way to test it in Objective-C?
UPDATE 1
Thanks for the answers suggested using 1u as unsigned int literal
STAssertEquals(1u, [myArray count], @"One item should be in array");
But since @Aaron mentioned that it is still ugly - I would like to use "1" directly - now instead of using myArray.count == 1. And the reason for this is that 1u does not look very clean. 1 for me 1. You never write 1u in math :-) Any other suggestions?
UPDATE 2
As mentioned in @ H2CO3, 1u may not always work, and, as suggested in some thread, we could use a more declarative definition of the expected value that would solve the casting problem:
NSUInteger expectedItemsCount = 1; STAssertEquals(expectedItemsCount, [myArray count], @"One item should be in array");
I prefer it for 1u solution because it looks cleaner. But the disadvantages of this approach are that we have an extra line and the code is not very compact. So, it looks like we need to choose between two approaches: (NSUInteger)1 and NSUInteger expectedItemsCount = 1;