Swift Track Exercise: Word Search

The required function returns WordLocation. But there is no explanation or definition of this type. Here is one of the provided test code:

let grid = ["clojurermt"]
    let words = ["clojure"]
    var expected = [String: WordLocation?]()
    expected["clojure"] = WordLocation(
      start: ["column": 1, "row": 1],
      end: ["column": 7, "row": 1]
    )

Is this the actual test being carried out?

After reviewing some of the Community Solutions, I realized that we need to use the nested type WordLocation.Location to specify the row and column, e.g.

WordLocation(
      start: WordLocation.Location(row: r1, column: c1), 
      end: WordLocation.Location(row: r2 column: c2)
    )

So, are the sample tests provided in the Exercise page out of date?

=============
EDIT: Okay, I read the error message more carefully. It stated

error: cannot convert value of type '[String : Int]' to expected argument type 'WordLocation.Location'41 |     42 |     return WordLocation(43 |        start: ["column": c0+1, "row": r0+1],   

when I ran code with

WordLocation(
       start: ["column": c0+1, "row": r0+1],
        end: ["column": endCol + 1, "row": endRow + 1]
    )

I guess I should have deduced that I need to use WordLocation.Location, but still, it would be nicer if there’s some discussion on the return type WordLocation.

Hi, @rwctwo!

But there is no explanation or definition of this type.

The definition could be found in the editor next to WordSearch file.
image

I think adding a note in the description about where to find this definition would be helpful.

Is this the actual test being carried out?

Yes, everything visible in Tests tab are real tests.

Ahhh. I didn’t see that tab!! Thank you.

On my second question, given that WordLocation definition, how does the test routine such as

let grid = ["clojurermt"]
let words = ["clojure"]
var expected = [String: WordLocation?]()
expected["clojure"] = WordLocation(
  start: ["column": 1, "row": 1],
  end: ["column": 7, "row": 1]
)

even compile? You will get this error.

Cannot convert value of type '[String : Int]' to expected argument type 'WordLocation.Location'

You are right, this specific initializer is not visible and available in the editor. It’s added specifically for testing purposes as a part of the test package and isn’t meant to be visible in the editor — it’s just a helper used to initialize WordLocation with a specific test data format.

Okay, I got it. Thank you for your reply.