-1

i want to check if a collection is sorted in my UnitTest using XCTest, does swift iOS provide any such framework or method.

let countrieds = ["Alabama","Benin","Alaska","Togo"]
    XCTAssertTrue(countrieds.sorted())

The above is just a sample and ofcourse i get the error below

Cannot convert value of type '[String]' to expected argument type 'Bool'

i will be glad to be educated on how to use XCTest to determine if a collection is sorted.

BigFire
  • 317
  • 1
  • 4
  • 17
  • 1
    XCTest offers nothing for this, so this is effectively a duplicate of [Extending Array to check if it is sorted in Swift?](https://stackoverflow.com/questions/24602595/extending-array-to-check-if-it-is-sorted-in-swift) –  Apr 07 '22 at 10:06

2 Answers2

1

A simple way to test that is to do an assertEqual with your array. For exemple:

let countries = ["Alabama","Benin","Alaska","Togo"]
XCTAssertEqual(countries, countries.sorted())

(In this exemple the test will return false obviously)

Lucas A
  • 36
  • 2
0

Use

XCTAssertTrue(countrieds == countrieds.sorted())

or

XCTAssertEqual(countrieds, countrieds.sorted())
zzzwco
  • 184
  • 6