26 lines
743 B
Plaintext
26 lines
743 B
Plaintext
The number of elements in a collection, an array or a string are always greater than or equal to zero. So testing that a size or length is greater than or equal to zero doesn't make sense, since the result is always ``++true++``. Similarly testing that it is less than zero will always return ``++false++``. Perhaps the intent was to check the non-emptiness instead.
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
if (myArray.count >= 0) { ... }
|
|
|
|
if (myString.characters.count < 0) { ... }
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
if (myArray.isEmpty) { ... }
|
|
|
|
if (myString.isEmpty) { ... }
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|