diff --git a/concepts/arrays/.meta/config.json b/concepts/arrays/.meta/config.json index 9e4e1a395..bfbbdacd4 100644 --- a/concepts/arrays/.meta/config.json +++ b/concepts/arrays/.meta/config.json @@ -1,7 +1,8 @@ { "blurb": "Arrays are a collection of multiple values of the same type.", "authors": [ - "wneumann" + "wneumann", + "meatball133" ], "contributors": [] } diff --git a/concepts/arrays/about.md b/concepts/arrays/about.md index 0c83b2cdc..4a8422995 100644 --- a/concepts/arrays/about.md +++ b/concepts/arrays/about.md @@ -1,54 +1,173 @@ # About -[Arrays][array] are one of Swift's three primary collection types. Arrays are ordered lists of elements where the elements can be of any type, however, all elements of any given list must have the same type. +[Arrays][array] are one of Swift's three primary collection types. +Arrays are ordered lists of elements where the elements can be of any type, however, all elements of any given list must have the same type. +Arrays are mutable when assigned to a variable, meaning that the elements of an array can be modified after the array is created. +This is not the case when an array is assigned to a constant, in which case the array is immutable. -Arrays literals are written as a series of elements, each separated by commas, enclosed in square brackets. Empty arrays are just a pair of square brackets. Type names for arrays are written in one of two ways: `Array` or `[T]` where `T` is the type of the elements in thee array. When creating an empty array, the type must be specified. +Arrays literals are written as a series of elements, each separated by commas, enclosed in square brackets. +Swift will infer the type of the array from the types of the elements in the array literal. + +```swift +let evenInts = [2, 4, 6, 8, 10, 12] +var oddInts = [1, 3, 5, 7, 9, 11, 13] +let greetings = ["Hello!", "Hi!", "¡Hola!"] +``` + +Arrays can also be explicitly typed by specifying the type of the elements in the array. +Type names for arrays are written in one of two ways: `Array` or `[T]` where `T` is the type of the elements in thee array. ```swift let evenInts: Array = [2, 4, 6, 8, 10, 12] var oddInts: [Int] = [1, 3, 5, 7, 9, 11, 13] -let greetings = ["Hello!", "Hi!", "¡Hola!"] -var myStringArray: [String] = [] +let greetings : [String] = ["Hello!", "Hi!", "¡Hola!"] +``` + +## Size of an Array + +The number of elements in an array can be determined using the [`count`][count] property. + +```swift +evenInts.count +// returns 6 +``` + +## Empty Arrays + +When wanting an empty array, the type must be specified. +This can be done by using either the array initializer syntax or by using the type annotation syntax. + +```swift +let emptyArray = [Int]() +let emptyArray2 = Array() +let emptyArray3: [Int] = [] +``` + +## Multi-dimensional Arrays + +Arrays can be nested to create multi-dimensional arrays. +When explicitly typing a multi-dimensional array, the type of the elements of the innermost array must be specified, using: `Array>` or `[[T]]`. + +```swift +let multiDimArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] +let multiDimArray2: [[Int]] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` -Elements of an array can be accessed individually by supplying the index of the element inside square brackets following the array; array indices are `Int`s and start with `0` for the first (leftmost) element. This subscript notation can be used to get the element at that index as well as to set the element at that index, provided the array was defined as a variable (i.e. using `var`). +## Append to an Array -Trying to access elements at indices outside the valid range of indices will result in a runtime error that crashes the program. Since any invalid array index access will crash a program, it is common to test arrays to see if the are empty before working with them by checking the `isEmpty` property or checking if an index is valid by ensuring that it is greater than or equal to 0 and less than the array's `count` property. +Elements can be appended to the end of an array using the [`append(_:)`][append] method. +The `append(_:)` method takes a single argument, the element to be appended to the array. ```swift -guard !evenInts.isEmpty, !oddInts.isEmpty else { return } +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.append(15) +// oddInts is now [1, 3, 5, 7, 9, 11, 13, 15] +``` + +## Insert into an Array + +Elements can be inserted into an array using the [`insert(_:at:)`][insert] method. +The `insert(_:at:)` method takes two arguments, the element to be inserted into the array and the index at which the element should be inserted. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.insert(0, at: 0) +// oddInts is now [0, 1, 3, 5, 7, 9, 11, 13] +``` + +## Add an Array to an Array + +Array can be added to the end of an array using the `+` operator. +It is important to note that the `+` operator creates a new array and does not modify the original array, which is different from the `append(_:)` or `insert(_:at:)` methods. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts + [15, 17, 19] +// returns [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] + +print(oddInts) +// prints [1, 3, 5, 7, 9, 11, 13] +``` + +## Accessing Elements of an Array + +Elements of an array can be accessed individually by supplying the index of the element inside square brackets following the array. +The index of an element is an `Int` and starts with `0` for the first (leftmost) element. +If the index is outside the valid range of indices, a runtime error will occur and the program will crash. + +```swift +let evenInts = [2, 4, 6, 8, 10, 12] +let oddInts = [1, 3, 5, 7, 9, 11, 13] + evenInts[2] -// => 6 -oddInts[0] = 27 -// oddInts is now [27, 3, 5, 7, 9, 11, 13] +// returns 6 -// these operations are not allowed -greetings[3] -// error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). -evenInts[1] = 0 -// Cannot assign through subscript: 'evenInts' is a 'let' constant +oddInts[7] +// Fatal error: Index out of range ``` -Arrays in Swift are not fixed size (though constant arrays, defined using `let` cannot be modified, including adding and removing elements). Elements can quickly be appended or dropped from the end of an array, and elements can be inserted or removed at any other location, though these operations are slower. The entire contents of another array can also be inserted at a given position in the original array. +## Modifying Elements of an Array -The elements of an array can be stepped through one at a time using a for-in loop. This type of loop takes each element of the array, in order, and binds the element to a specified name for further processing inside the loop body. For example, to print out all of the odd integers in an array one can write: +Elements of an array can be modified by assigning a new value to the element at a given index. +The index of an element is an `Int` and starts with `0` for the first (leftmost) element. +If the index is outside the valid range of indices, a runtime error will occur and the program will crash. ```swift -let ints = [1, 3, 6, 14, 17, 8, 23, 5, 18, 11] +var evenInts = [2, 4, 6, 8, 10, 12] -for int in ints { - if !int.isMultiple(of: 2) { - print(int) - } -} +evenInts[2] = 0 +// evenInts is now [2, 4, 0, 8, 10, 12] +``` -// prints out: -// 1 -// 3 -// 17 -// 23 -// 5 -// 11 +## Converting an Array to a String and Back + +An array ofn strings can be converted to a single string using the [`joined(separator:)`][joined] method. +The `joined(separator:)` property takes a single argument, the separator to be used between elements of the array. +The separator must be a string. + +```swift +let evenInts = ["2", "4", "6", "8", "10", "12"] +let evenIntsString = evenInts.joined(separator: ", ") +// returns "2, 4, 6, 8, 10, 12" +``` + +An array can be converted from a string using the [`split(separator:)`][split] method. +The `split(separator:)` method takes a single argument, the separator to be used between elements of the array. + +```swift +let evenIntsString = "2, 4, 6, 8, 10, 12" +let evenInts = evenIntsString.split(separator: ", ") +// returns ["2", "4", "6", "8", "10", "12"] +``` + +## Delete an Element from an Array + +Elements can be deleted from an array using the [`remove(at:)`][remove] method. +The `remove(at:)` method takes a single argument, the index of the element to be removed from the array. +The index of an element is an `Int` and starts with `0` for the first (leftmost) element. +If the index is outside the valid range of indices, a runtime error will occur and the program will crash. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.remove(at: 3) +// oddInts is now [1, 3, 5, 9, 11, 13] +``` + +If the last element of an array is to be removed, the [`removeLast()`][removeLast] method can be used. +The `removeLast()` method takes no arguments. +If the array is empty, a runtime error will occur and the program will crash. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.removeLast() +// oddInts is now [1, 3, 5, 7, 9, 11] ``` [array]: https://developer.apple.com/documentation/swift/array +[count]: https://developer.apple.com/documentation/swift/array/count +[insert]: https://developer.apple.com/documentation/swift/array/insert(_:at:)-3erb3 +[remove]: https://developer.apple.com/documentation/swift/array/remove(at:)-1p2pj +[removeLast]: https://developer.apple.com/documentation/swift/array/removelast() +[append]: https://developer.apple.com/documentation/swift/array/append(_:)-1ytnt +[joined]: https://developer.apple.com/documentation/swift/array/joined(separator:)-5do1g +[split]: https://developer.apple.com/documentation/swift/string/2894564-split diff --git a/concepts/arrays/introduction.md b/concepts/arrays/introduction.md index 7ad8685ea..4a8422995 100644 --- a/concepts/arrays/introduction.md +++ b/concepts/arrays/introduction.md @@ -1,49 +1,173 @@ -# Introduction +# About -Arrays are one of Swift's three primary collection types. Arrays are ordered lists of elements where the elements can be of any type, however, all elements of any given list must have the same type. +[Arrays][array] are one of Swift's three primary collection types. +Arrays are ordered lists of elements where the elements can be of any type, however, all elements of any given list must have the same type. +Arrays are mutable when assigned to a variable, meaning that the elements of an array can be modified after the array is created. +This is not the case when an array is assigned to a constant, in which case the array is immutable. -Arrays literals are written as a series of elements, each separated by commas, enclosed in square brackets. Empty arrays are just a pair of square brackets. Type names for arrays are written in one of two ways: `Array` or `[T]` where `T` is the type of the elements in the array. When creating an empty array, the type must be specified. +Arrays literals are written as a series of elements, each separated by commas, enclosed in square brackets. +Swift will infer the type of the array from the types of the elements in the array literal. + +```swift +let evenInts = [2, 4, 6, 8, 10, 12] +var oddInts = [1, 3, 5, 7, 9, 11, 13] +let greetings = ["Hello!", "Hi!", "¡Hola!"] +``` + +Arrays can also be explicitly typed by specifying the type of the elements in the array. +Type names for arrays are written in one of two ways: `Array` or `[T]` where `T` is the type of the elements in thee array. ```swift let evenInts: Array = [2, 4, 6, 8, 10, 12] var oddInts: [Int] = [1, 3, 5, 7, 9, 11, 13] -let greetings = ["Hello!", "Hi!", "¡Hola!"] -var myStringArray: [String] = [] +let greetings : [String] = ["Hello!", "Hi!", "¡Hola!"] ``` -Elements of an array can be accessed individually by supplying the index of the element inside square brackets following the array; array indices are `Int`s and start with `0` for the first (leftmost) element. This subscript notation can be used to get the element at that index as well as to set the element at that index, provided the array was defined as a variable (i.e. using `var`). +## Size of an Array -Trying to access elements at indices outside the valid range of indices will result in a runtime error that crashes the program. Since any invalid array index access will crash a program, it is common to test arrays to see if they are empty before working with them by checking the `isEmpty` property or checking if an index is valid by ensuring that it is greater than or equal to 0 and less than the array's `count` property. +The number of elements in an array can be determined using the [`count`][count] property. ```swift +evenInts.count +// returns 6 +``` + +## Empty Arrays + +When wanting an empty array, the type must be specified. +This can be done by using either the array initializer syntax or by using the type annotation syntax. + +```swift +let emptyArray = [Int]() +let emptyArray2 = Array() +let emptyArray3: [Int] = [] +``` + +## Multi-dimensional Arrays + +Arrays can be nested to create multi-dimensional arrays. +When explicitly typing a multi-dimensional array, the type of the elements of the innermost array must be specified, using: `Array>` or `[[T]]`. + +```swift +let multiDimArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] +let multiDimArray2: [[Int]] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] +``` + +## Append to an Array + +Elements can be appended to the end of an array using the [`append(_:)`][append] method. +The `append(_:)` method takes a single argument, the element to be appended to the array. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.append(15) +// oddInts is now [1, 3, 5, 7, 9, 11, 13, 15] +``` + +## Insert into an Array + +Elements can be inserted into an array using the [`insert(_:at:)`][insert] method. +The `insert(_:at:)` method takes two arguments, the element to be inserted into the array and the index at which the element should be inserted. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.insert(0, at: 0) +// oddInts is now [0, 1, 3, 5, 7, 9, 11, 13] +``` + +## Add an Array to an Array + +Array can be added to the end of an array using the `+` operator. +It is important to note that the `+` operator creates a new array and does not modify the original array, which is different from the `append(_:)` or `insert(_:at:)` methods. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts + [15, 17, 19] +// returns [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] + +print(oddInts) +// prints [1, 3, 5, 7, 9, 11, 13] +``` + +## Accessing Elements of an Array + +Elements of an array can be accessed individually by supplying the index of the element inside square brackets following the array. +The index of an element is an `Int` and starts with `0` for the first (leftmost) element. +If the index is outside the valid range of indices, a runtime error will occur and the program will crash. + +```swift +let evenInts = [2, 4, 6, 8, 10, 12] +let oddInts = [1, 3, 5, 7, 9, 11, 13] + evenInts[2] -// => 6 -oddInts[0] = 27 -// oddInts is now [27, 3, 5, 7, 9, 11, 13] +// returns 6 + +oddInts[7] +// Fatal error: Index out of range +``` + +## Modifying Elements of an Array + +Elements of an array can be modified by assigning a new value to the element at a given index. +The index of an element is an `Int` and starts with `0` for the first (leftmost) element. +If the index is outside the valid range of indices, a runtime error will occur and the program will crash. + +```swift +var evenInts = [2, 4, 6, 8, 10, 12] + +evenInts[2] = 0 +// evenInts is now [2, 4, 0, 8, 10, 12] +``` + +## Converting an Array to a String and Back + +An array ofn strings can be converted to a single string using the [`joined(separator:)`][joined] method. +The `joined(separator:)` property takes a single argument, the separator to be used between elements of the array. +The separator must be a string. + +```swift +let evenInts = ["2", "4", "6", "8", "10", "12"] +let evenIntsString = evenInts.joined(separator: ", ") +// returns "2, 4, 6, 8, 10, 12" +``` + +An array can be converted from a string using the [`split(separator:)`][split] method. +The `split(separator:)` method takes a single argument, the separator to be used between elements of the array. -// these operations are not allowed -greetings[3] -// error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). -evenInts[1] = 0 -// Cannot assign through subscript: 'evenInts' is a 'let' constant +```swift +let evenIntsString = "2, 4, 6, 8, 10, 12" +let evenInts = evenIntsString.split(separator: ", ") +// returns ["2", "4", "6", "8", "10", "12"] ``` -The elements of an array can be stepped through one at a time using a for-in loop. This type of loop takes each element of the array, in order, and binds the element to a specified name for further processing inside the loop body. For example, to print out all of the odd integers in an array one can write: +## Delete an Element from an Array + +Elements can be deleted from an array using the [`remove(at:)`][remove] method. +The `remove(at:)` method takes a single argument, the index of the element to be removed from the array. +The index of an element is an `Int` and starts with `0` for the first (leftmost) element. +If the index is outside the valid range of indices, a runtime error will occur and the program will crash. ```swift -let ints = [1, 3, 6, 14, 17, 8, 23, 5, 18, 11] +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.remove(at: 3) +// oddInts is now [1, 3, 5, 9, 11, 13] +``` -for int in ints { - if !int.isMultiple(of: 2) { - print(int) - } -} +If the last element of an array is to be removed, the [`removeLast()`][removeLast] method can be used. +The `removeLast()` method takes no arguments. +If the array is empty, a runtime error will occur and the program will crash. -// prints out: -// 1 -// 3 -// 17 -// 23 -// 5 -// 11 +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.removeLast() +// oddInts is now [1, 3, 5, 7, 9, 11] ``` + +[array]: https://developer.apple.com/documentation/swift/array +[count]: https://developer.apple.com/documentation/swift/array/count +[insert]: https://developer.apple.com/documentation/swift/array/insert(_:at:)-3erb3 +[remove]: https://developer.apple.com/documentation/swift/array/remove(at:)-1p2pj +[removeLast]: https://developer.apple.com/documentation/swift/array/removelast() +[append]: https://developer.apple.com/documentation/swift/array/append(_:)-1ytnt +[joined]: https://developer.apple.com/documentation/swift/array/joined(separator:)-5do1g +[split]: https://developer.apple.com/documentation/swift/string/2894564-split diff --git a/concepts/arrays/links.json b/concepts/arrays/links.json index 555894303..86dae2a61 100644 --- a/concepts/arrays/links.json +++ b/concepts/arrays/links.json @@ -4,7 +4,7 @@ "description": "Apple Swift Documentation: Array" }, { - "url": "https://docs.swift.org/swift-book/LanguageGuide/CollectionTypes.html#", + "url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/collectiontypes/#Arrays", "description": "The Swift Language Guide: Collection Types" } ] \ No newline at end of file diff --git a/exercises/concept/magician-in-training/.docs/instructions.md b/exercises/concept/magician-in-training/.docs/instructions.md index 8f2acbf44..f23a75d4f 100644 --- a/exercises/concept/magician-in-training/.docs/instructions.md +++ b/exercises/concept/magician-in-training/.docs/instructions.md @@ -1,93 +1,94 @@ # Instructions -As a magician-to-be, Elyse needs to practice some basics. She has a stack of cards that she wants to manipulate. +As a magician-to-be, Elyse needs to practice some basics. +She has a stack of cards that she wants to manipulate. -To make things a bit easier she only uses the cards 1 to 10. +To make things a bit easier she only uses the cards 1 to 10 so her stack of cards can be represented by an array of numbers. +The position of a certain card corresponds to the index in the array. +That means position 0 refers to the first card, position 1 to the second card etc. + +~~~~exercism/note +All functions should update the array of cards and then return the modified array - a common way of working known as the Builder pattern, which allows you to nicely daisy-chain functions together. +~~~~ ## 1. Retrieve a card from a stack -Implement the function `getCard(at:from:)` that returns the card at position `index` from the given stack. +To pick a card, return the card at index `position` from the given stack. + +Implement the function `getCard(at:from:)` that takes two arguments: `at` which is the position of the card in the stack, and `from` which is the stack of cards. +The function should return the card at position `index` from the given stack. ```swift let index = 2 getCard(at: index, from: [1, 2, 4, 1]) -// => 4 +// returns 4 ``` ## 2. Change a card in the stack -Implement the function `setCard(at:in:to)` that returns a new stack that is a copy of the input stack but which has the card at position `index` changed to the new card provided. If the given `index` is not a valid index in the stack, the original stack should be returned, unchanged. +Perform some sleight of hand and exchange the card at index `position` with the replacement card provided. + +Implement the function `setCard(at:in:to)` that takes three arguments: `at` which is the position of the card in the stack, `in` which is the stack of cards, and `to` which is the new card to replace the card at position `index`. +The function should return a copy of the stack with the card at position `index` replaced with the new card. +If the given `index` is not a valid index in the stack, the original stack should be returned, unchanged. ```swift let index = 2 let newCard = 6 setCard(at: index, in: [1, 2, 4, 1], to: newCard) -// => [1, 2, 6, 1] +// returns [1, 2, 6, 1] ``` ## 3. Insert a card at the of top the stack -Implement the function `insert(_:atTopOf:)` that returns a copy of the stack with the new card provided added to the top of the stack. +Make a card appear by inserting a new card at the top of the stack. + +Implement the function `insert(_:atTopOf:)` that takes two arguments: the new card to be inserted, and the stack of cards. +The function should returns a copy of the stack with the new card provided added to the top of the stack. ```swift let newCard = 8 insert(newCard, atTopOf: [5, 9, 7, 1]) -// => [5, 9, 7, 1, 8] +// returns [5, 9, 7, 1, 8] ``` ## 4. Remove a card from the stack -Implement the function `removeCard(at:from:)` that returns a copy of the stack which has had the card at position `index` removed. If the given `index` is not a valid index in the stack, the original stack should be returned, unchanged. +Make a card disappear by removing the card at the given `position` from the stack. + +Implement the function `removeCard(at:from:)` that takes two arguments: `at` which is the position of the card in the stack, and `from` which is the stack of cards. +The function should return a copy of the stack with the card at position `index` removed. +If the given `index` is not a valid index in the stack, the original stack should be returned, unchanged. ```swift let index = 2 removeCard(at: index, from: [3, 2, 6, 4, 8]) -// => [3, 2, 4, 8] +// returns [3, 2, 4, 8] ``` -## 5. Remove the top card from the stack - -Implement the function `removeTopCard(_:)` that returns a copy of the stack which has had the card at the top of the stack removed. If the given stack is empty, the original stack should be returned, unchanged. - -```swift -removeTopCard([3, 2, 6, 4, 8]) -// => [3, 2, 6, 4] -``` +## 5. Insert a card in the stack -## 6. Insert a card at the bottom of the stack +Make a card appear by inserting a new card at the given `position` in the stack. -Implement the function `insert(_:atBottomOf:)` that returns a copy of the stack with the new card provided added to the bottom of the stack. +Implement the function `insert(_:at:from:)` that takes three arguments: the new card to be inserted, the position at which the new card should be inserted, and the stack of cards. +The function should return a copy of the stack with the new card provided added at the given position. +If the given `index` is not a valid index in the stack, the original stack should be returned, unchanged. ```swift let newCard = 8 -insert(newCard, atBottomOf: [5, 9, 7, 1]) -// => [8, 5, 9, 7, 1] +insert(newCard, at: 2, from: [5, 9, 7, 1]) +// returns [5, 9, 8, 7, 1] ``` -## 7. Remove a card from the bottom of the stack +## 6. Check size of the stack -Implement the function `removeBottomCard(_:)` that returns a copy of the stack which has had the card at the bottom of the stack removed. If the given stack is empty, the original stack should be returned, unchanged. +Check whether the size of the stack is equal to `stackSize` or not. -```swift -removeBottomCard([8, 5, 9, 7, 1]) -// => [5, 9, 7, 1] -``` - -## 8. Check size of the stack - -Implement the function `checkSizeOfStack(_:_:)` that checks whether the size of the stack is equal to a given `stackSize` or not. +Implement the function `checkSizeOfStack(_:_:)` that takes two arguments: `stack` which is the stack of cards, and `stackSize` which is the size of the stack. +The function should return `true` if the size of the stack is equal to `stackSize` and `false` otherwise. ```swift let stackSize = 4 checkSizeOfStack([3, 2, 6, 4, 8], stackSize) -// => false -``` - -## 9. Count the number of even cards in the stack - -Implement the function `evenCardCount(_:)` that steps through the stack and counts the number of even cards in it. - -```swift -evenCardCount([3,8,4,5,1,6,10]) -// => 4 +// returns false ``` diff --git a/exercises/concept/magician-in-training/.docs/introduction.md b/exercises/concept/magician-in-training/.docs/introduction.md index 7ad8685ea..4a8422995 100644 --- a/exercises/concept/magician-in-training/.docs/introduction.md +++ b/exercises/concept/magician-in-training/.docs/introduction.md @@ -1,49 +1,173 @@ -# Introduction +# About -Arrays are one of Swift's three primary collection types. Arrays are ordered lists of elements where the elements can be of any type, however, all elements of any given list must have the same type. +[Arrays][array] are one of Swift's three primary collection types. +Arrays are ordered lists of elements where the elements can be of any type, however, all elements of any given list must have the same type. +Arrays are mutable when assigned to a variable, meaning that the elements of an array can be modified after the array is created. +This is not the case when an array is assigned to a constant, in which case the array is immutable. -Arrays literals are written as a series of elements, each separated by commas, enclosed in square brackets. Empty arrays are just a pair of square brackets. Type names for arrays are written in one of two ways: `Array` or `[T]` where `T` is the type of the elements in the array. When creating an empty array, the type must be specified. +Arrays literals are written as a series of elements, each separated by commas, enclosed in square brackets. +Swift will infer the type of the array from the types of the elements in the array literal. + +```swift +let evenInts = [2, 4, 6, 8, 10, 12] +var oddInts = [1, 3, 5, 7, 9, 11, 13] +let greetings = ["Hello!", "Hi!", "¡Hola!"] +``` + +Arrays can also be explicitly typed by specifying the type of the elements in the array. +Type names for arrays are written in one of two ways: `Array` or `[T]` where `T` is the type of the elements in thee array. ```swift let evenInts: Array = [2, 4, 6, 8, 10, 12] var oddInts: [Int] = [1, 3, 5, 7, 9, 11, 13] -let greetings = ["Hello!", "Hi!", "¡Hola!"] -var myStringArray: [String] = [] +let greetings : [String] = ["Hello!", "Hi!", "¡Hola!"] ``` -Elements of an array can be accessed individually by supplying the index of the element inside square brackets following the array; array indices are `Int`s and start with `0` for the first (leftmost) element. This subscript notation can be used to get the element at that index as well as to set the element at that index, provided the array was defined as a variable (i.e. using `var`). +## Size of an Array -Trying to access elements at indices outside the valid range of indices will result in a runtime error that crashes the program. Since any invalid array index access will crash a program, it is common to test arrays to see if they are empty before working with them by checking the `isEmpty` property or checking if an index is valid by ensuring that it is greater than or equal to 0 and less than the array's `count` property. +The number of elements in an array can be determined using the [`count`][count] property. ```swift +evenInts.count +// returns 6 +``` + +## Empty Arrays + +When wanting an empty array, the type must be specified. +This can be done by using either the array initializer syntax or by using the type annotation syntax. + +```swift +let emptyArray = [Int]() +let emptyArray2 = Array() +let emptyArray3: [Int] = [] +``` + +## Multi-dimensional Arrays + +Arrays can be nested to create multi-dimensional arrays. +When explicitly typing a multi-dimensional array, the type of the elements of the innermost array must be specified, using: `Array>` or `[[T]]`. + +```swift +let multiDimArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] +let multiDimArray2: [[Int]] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] +``` + +## Append to an Array + +Elements can be appended to the end of an array using the [`append(_:)`][append] method. +The `append(_:)` method takes a single argument, the element to be appended to the array. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.append(15) +// oddInts is now [1, 3, 5, 7, 9, 11, 13, 15] +``` + +## Insert into an Array + +Elements can be inserted into an array using the [`insert(_:at:)`][insert] method. +The `insert(_:at:)` method takes two arguments, the element to be inserted into the array and the index at which the element should be inserted. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.insert(0, at: 0) +// oddInts is now [0, 1, 3, 5, 7, 9, 11, 13] +``` + +## Add an Array to an Array + +Array can be added to the end of an array using the `+` operator. +It is important to note that the `+` operator creates a new array and does not modify the original array, which is different from the `append(_:)` or `insert(_:at:)` methods. + +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts + [15, 17, 19] +// returns [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] + +print(oddInts) +// prints [1, 3, 5, 7, 9, 11, 13] +``` + +## Accessing Elements of an Array + +Elements of an array can be accessed individually by supplying the index of the element inside square brackets following the array. +The index of an element is an `Int` and starts with `0` for the first (leftmost) element. +If the index is outside the valid range of indices, a runtime error will occur and the program will crash. + +```swift +let evenInts = [2, 4, 6, 8, 10, 12] +let oddInts = [1, 3, 5, 7, 9, 11, 13] + evenInts[2] -// => 6 -oddInts[0] = 27 -// oddInts is now [27, 3, 5, 7, 9, 11, 13] +// returns 6 + +oddInts[7] +// Fatal error: Index out of range +``` + +## Modifying Elements of an Array + +Elements of an array can be modified by assigning a new value to the element at a given index. +The index of an element is an `Int` and starts with `0` for the first (leftmost) element. +If the index is outside the valid range of indices, a runtime error will occur and the program will crash. + +```swift +var evenInts = [2, 4, 6, 8, 10, 12] + +evenInts[2] = 0 +// evenInts is now [2, 4, 0, 8, 10, 12] +``` + +## Converting an Array to a String and Back + +An array ofn strings can be converted to a single string using the [`joined(separator:)`][joined] method. +The `joined(separator:)` property takes a single argument, the separator to be used between elements of the array. +The separator must be a string. + +```swift +let evenInts = ["2", "4", "6", "8", "10", "12"] +let evenIntsString = evenInts.joined(separator: ", ") +// returns "2, 4, 6, 8, 10, 12" +``` + +An array can be converted from a string using the [`split(separator:)`][split] method. +The `split(separator:)` method takes a single argument, the separator to be used between elements of the array. -// these operations are not allowed -greetings[3] -// error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). -evenInts[1] = 0 -// Cannot assign through subscript: 'evenInts' is a 'let' constant +```swift +let evenIntsString = "2, 4, 6, 8, 10, 12" +let evenInts = evenIntsString.split(separator: ", ") +// returns ["2", "4", "6", "8", "10", "12"] ``` -The elements of an array can be stepped through one at a time using a for-in loop. This type of loop takes each element of the array, in order, and binds the element to a specified name for further processing inside the loop body. For example, to print out all of the odd integers in an array one can write: +## Delete an Element from an Array + +Elements can be deleted from an array using the [`remove(at:)`][remove] method. +The `remove(at:)` method takes a single argument, the index of the element to be removed from the array. +The index of an element is an `Int` and starts with `0` for the first (leftmost) element. +If the index is outside the valid range of indices, a runtime error will occur and the program will crash. ```swift -let ints = [1, 3, 6, 14, 17, 8, 23, 5, 18, 11] +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.remove(at: 3) +// oddInts is now [1, 3, 5, 9, 11, 13] +``` -for int in ints { - if !int.isMultiple(of: 2) { - print(int) - } -} +If the last element of an array is to be removed, the [`removeLast()`][removeLast] method can be used. +The `removeLast()` method takes no arguments. +If the array is empty, a runtime error will occur and the program will crash. -// prints out: -// 1 -// 3 -// 17 -// 23 -// 5 -// 11 +```swift +var oddInts = [1, 3, 5, 7, 9, 11, 13] +oddInts.removeLast() +// oddInts is now [1, 3, 5, 7, 9, 11] ``` + +[array]: https://developer.apple.com/documentation/swift/array +[count]: https://developer.apple.com/documentation/swift/array/count +[insert]: https://developer.apple.com/documentation/swift/array/insert(_:at:)-3erb3 +[remove]: https://developer.apple.com/documentation/swift/array/remove(at:)-1p2pj +[removeLast]: https://developer.apple.com/documentation/swift/array/removelast() +[append]: https://developer.apple.com/documentation/swift/array/append(_:)-1ytnt +[joined]: https://developer.apple.com/documentation/swift/array/joined(separator:)-5do1g +[split]: https://developer.apple.com/documentation/swift/string/2894564-split diff --git a/exercises/concept/magician-in-training/.meta/Sources/MagicianInTraining/MagicianInTrainingExemplar.swift b/exercises/concept/magician-in-training/.meta/Sources/MagicianInTraining/MagicianInTrainingExemplar.swift index ca2fbb202..0feaee6e1 100644 --- a/exercises/concept/magician-in-training/.meta/Sources/MagicianInTraining/MagicianInTrainingExemplar.swift +++ b/exercises/concept/magician-in-training/.meta/Sources/MagicianInTraining/MagicianInTrainingExemplar.swift @@ -3,7 +3,9 @@ func getCard(at index: Int, from stack: [Int]) -> Int { } func setCard(at index: Int, in stack: [Int], to newCard: Int) -> [Int] { - guard index >= 0 && index < stack.count else { return stack } + if index > stack.count { + return stack + } var newStack = stack newStack[index] = newCard return newStack @@ -14,42 +16,23 @@ func insert(_ newCard: Int, atTopOf stack: [Int]) -> [Int] { } func removeCard(at index: Int, from stack: [Int]) -> [Int] { - guard index >= 0 && index < stack.count else { return stack } + if index > stack.count { + return stack + } var newStack = stack newStack.remove(at: index) return newStack } -func removeTopCard(_ stack: [Int]) -> [Int] { - guard !stack.isEmpty else { return stack } - var newStack = stack - newStack.removeLast() - return newStack -} - -func insert(_ newCard: Int, atBottomOf stack: [Int]) -> [Int] { - var newStack = stack - newStack.insert(newCard, at: 0) - return newStack -} - -func removeBottomCard(_ stack: [Int]) -> [Int] { - guard !stack.isEmpty else { return stack } +func insert(_ newCard: Int, at index: Int, from stack: [Int]) -> [Int] { + if index > stack.count { + return stack + } var newStack = stack - newStack.removeFirst() + newStack.insert(newCard, at: index) return newStack } func checkSizeOfStack(_ stack: [Int], _ size: Int) -> Bool { return stack.count == size } - -func evenCardCount(_ stack: [Int]) -> Int { - var evens = 0 - for card in stack { - if card.isMultiple(of: 2) { - evens += 1 - } - } - return evens -} diff --git a/exercises/concept/magician-in-training/.meta/config.json b/exercises/concept/magician-in-training/.meta/config.json index a3b7e7915..e8b957ce2 100644 --- a/exercises/concept/magician-in-training/.meta/config.json +++ b/exercises/concept/magician-in-training/.meta/config.json @@ -1,6 +1,7 @@ { "authors": [ - "wneumann" + "wneumann", + "meatball133" ], "files": { "solution": [ diff --git a/exercises/concept/magician-in-training/Package.swift b/exercises/concept/magician-in-training/Package.swift index 0c2c2abcf..022fc1f67 100644 --- a/exercises/concept/magician-in-training/Package.swift +++ b/exercises/concept/magician-in-training/Package.swift @@ -4,25 +4,25 @@ import PackageDescription let package = Package( - name: "MagicianInTraining", - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "MagicianInTraining", - targets: ["MagicianInTraining"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), - ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages this package depends on. - .target( - name: "MagicianInTraining", - dependencies: []), - .testTarget( - name: "MagicianInTrainingTests", - dependencies: ["MagicianInTraining"]), - ] + name: "MagicianInTraining", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "MagicianInTraining", + targets: ["MagicianInTraining"]) + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "MagicianInTraining", + dependencies: []), + .testTarget( + name: "MagicianInTrainingTests", + dependencies: ["MagicianInTraining"]), + ] ) diff --git a/exercises/concept/magician-in-training/Sources/MagicianInTraining/MagicianInTraining.swift b/exercises/concept/magician-in-training/Sources/MagicianInTraining/MagicianInTraining.swift index 51fe79d03..29c310764 100644 --- a/exercises/concept/magician-in-training/Sources/MagicianInTraining/MagicianInTraining.swift +++ b/exercises/concept/magician-in-training/Sources/MagicianInTraining/MagicianInTraining.swift @@ -14,22 +14,10 @@ func removeCard(at index: Int, from stack: [Int]) -> [Int] { fatalError("Please implement the removeCard(at:from:) function") } -func removeTopCard(_ stack: [Int]) -> [Int] { - fatalError("Please implement the removeTopCard(_) function") -} - -func insert(_ newCard: Int, atBottomOf stack: [Int]) -> [Int] { - fatalError("Please implement the insert(_:atBottomOf:) function") -} - -func removeBottomCard(_ stack: [Int]) -> [Int] { - fatalError("Please implement the removeBottomCard(_) function") +func insert(_ newCard: Int, at index: Int, from stack: [Int]) -> [Int] { + fatalError("Please implement the insert(_:at:from:) function") } func checkSizeOfStack(_ stack: [Int], _ size: Int) -> Bool { fatalError("Please implement the checkSizeOfStack(_:_:) function") } - -func evenCardCount(_ stack: [Int]) -> Int { - fatalError("Please implement the evenCardCount(_) function") -} diff --git a/exercises/concept/magician-in-training/Tests/LinuxMain.swift b/exercises/concept/magician-in-training/Tests/LinuxMain.swift deleted file mode 100644 index 4e9800ff5..000000000 --- a/exercises/concept/magician-in-training/Tests/LinuxMain.swift +++ /dev/null @@ -1,6 +0,0 @@ -import MagicianInTrainingTests -import XCTest - -var tests = [XCTestCaseEntry]() -tests += MagicianInTrainingTests.allTests() -XCTMain(tests) diff --git a/exercises/concept/magician-in-training/Tests/MagicianInTrainingTests/MagicianInTrainingTests.swift b/exercises/concept/magician-in-training/Tests/MagicianInTrainingTests/MagicianInTrainingTests.swift index fefb02a97..69164af72 100644 --- a/exercises/concept/magician-in-training/Tests/MagicianInTrainingTests/MagicianInTrainingTests.swift +++ b/exercises/concept/magician-in-training/Tests/MagicianInTrainingTests/MagicianInTrainingTests.swift @@ -2,134 +2,133 @@ import XCTest @testable import MagicianInTraining -final class MagicianInTrainingTests: XCTestCase { - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false +let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false - func testGetCard() { - let stack = (1...10).shuffled() - guard let idx = stack.indices.randomElement() else { fatalError("test suite failure") } - XCTAssertEqual(getCard(at: idx, from: stack), stack[idx]) +class TaskGetCardTests: XCTestCase { + func testGetFirstCard() { + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(getCard(at: 0, from: stack), 1) } - func testSetCard() throws { + func testGetMiddleCard() { + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(getCard(at: 2, from: stack), 3) + } + + func testGetLastCard() { + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(getCard(at: 4, from: stack), 5) + } +} + +class TaskSetCardTests: XCTestCase { + func testSetFirstCard() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [9, 4, 3, 6, 1, 7, 2, 8, 5] - let idx = 5 - XCTAssertEqual(setCard(at: idx, in: stack, to: 10), [9, 4, 3, 6, 1, 10, 2, 8, 5]) + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(setCard(at: 0, in: stack, to: 10), [10, 2, 3, 4, 5]) } - func testSetCardIndexTooLow() throws { + func testSetMiddleCard() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [9, 4, 3, 6, 1, 7, 2, 8, 5] - let idx = -3 - XCTAssertEqual(setCard(at: idx, in: stack, to: 10), stack) + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(setCard(at: 2, in: stack, to: 10), [1, 2, 10, 4, 5]) } - func testSetCardIndexTooHigh() throws { + func testSetLastCard() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [9, 4, 3, 6, 1, 7, 2, 8, 5] - let idx = 50 - XCTAssertEqual(setCard(at: idx, in: stack, to: 10), stack) + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(setCard(at: 4, in: stack, to: 10), [1, 2, 3, 4, 10]) } - func testInsertAtTop() throws { + func testSetCardIndexOutOfBounds() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [1, 7, 5, 8, 3, 9, 6, 4, 2] - XCTAssertEqual(insert(10, atTopOf: stack), [1, 7, 5, 8, 3, 9, 6, 4, 2, 10]) + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(setCard(at: 5, in: stack, to: 10), stack) } +} - func testRemoveCard() throws { +class TaskInsertAtTopTests: XCTestCase { + func testInsertAtTop() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [9, 2, 1, 6, 5, 7, 4, 3, 8] - let idx = 2 - XCTAssertEqual(removeCard(at: idx, from: stack), [9, 2, 6, 5, 7, 4, 3, 8]) + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(insert(10, atTopOf: stack), [1, 2, 3, 4, 5, 10]) } - func testRemoveCardIndexTooLow() throws { + func testInsertAnotherAtTop() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [9, 2, 1, 6, 5, 7, 4, 3, 8] - let idx = -2 - XCTAssertEqual(removeCard(at: idx, from: stack), stack) + let stack = [6, 7, 8, 9, 10] + XCTAssertEqual(insert(5, atTopOf: stack), [6, 7, 8, 9, 10, 5]) } - func testRemoveCardIndexTooHigh() throws { + func testInsertAtTopOfEmptyStack() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [9, 2, 1, 6, 5, 7, 4, 3, 8] - let idx = 20 - XCTAssertEqual(removeCard(at: idx, from: stack), stack) + let stack = [Int]() + XCTAssertEqual(insert(5, atTopOf: stack), [5]) } +} - func testRemoveTopCard() throws { +class TaskRemoveCardTests: XCTestCase { + func testRemoveFirstCard() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [2, 7, 4, 6, 9, 1, 8, 3, 5] - XCTAssertEqual(removeTopCard(stack), [2, 7, 4, 6, 9, 1, 8, 3]) + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(removeCard(at: 0, from: stack), [2, 3, 4, 5]) } - func testRemoveTopCardFromEmptyStack() throws { + func testRemoveMiddleCard() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [Int]() - XCTAssertEqual(removeTopCard(stack), stack) + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(removeCard(at: 2, from: stack), [1, 2, 4, 5]) } - func testInsertAtBottom() throws { + func testRemoveLastCard() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [4, 3, 8, 9, 1, 7, 6, 5, 2] - XCTAssertEqual(insert(10, atBottomOf: stack), [10, 4, 3, 8, 9, 1, 7, 6, 5, 2]) + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(removeCard(at: 4, from: stack), [1, 2, 3, 4]) } - func testRemoveBottomCard() throws { + func testRemoveCardIndexOutOfBounds() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [8, 7, 4, 2, 6, 5, 3, 1, 9] - XCTAssertEqual(removeBottomCard(stack), [7, 4, 2, 6, 5, 3, 1, 9]) + let stack = [1, 2, 3, 4, 5] + XCTAssertEqual(removeCard(at: 5, from: stack), stack) } +} - func testRemoveBottomCardFromEmptyStack() throws { +class TaskInsertAtTask: XCTestCase{ + func testInsertAtTask() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [Int]() - XCTAssertEqual(removeTopCard(stack), stack) + let stack = [1,2,3,4,5] + XCTAssertEqual(insert(10, at: 2, from: stack), [1,2,10,3,4,5]) } - func testCheckSizeTrue() throws { + func testInsertAnotherAtTask() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [6, 9, 7, 8, 2, 3, 4, 5, 1] - XCTAssertTrue(checkSizeOfStack(stack, 9)) + let stack = [6,7,8,9,10] + XCTAssertEqual(insert(5, at: 3, from: stack), [6,7,8,5,9,10]) } - func testCheckSizeFalse() throws { + func testInsertAtTaskOfEmptyStack() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [6, 9, 7, 8, 2, 3, 4, 5, 1] - XCTAssertFalse(checkSizeOfStack(removeBottomCard(stack), 9)) + let stack = [Int]() + XCTAssertEqual(insert(5, at: 0, from: stack), [5]) } - func testEvenCardCount() throws { + func testInsertAtTaskIndexOutOfBounds() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [4, 6, 3, 7, 1, 9, 5, 8, 2] - XCTAssertEqual(evenCardCount(stack), 4) + let stack = [1,2,3,4,5] + XCTAssertEqual(insert(10, at: 6, from: stack), stack) } +} - func testEvenCardCountZero() throws { +class TaskCheckSizeOfStackTests: XCTestCase { + func testCheckSizeOfStackTrue() throws { try XCTSkipIf(true && !runAll) // change true to false to run this test - let stack = [7, 3, 7, 1, 5, 5, 3, 9, 9] - XCTAssertEqual(evenCardCount(stack), 0) + let stack = [1,2,3,4,5] + XCTAssertTrue(checkSizeOfStack(stack, 5)) } - static var allTests = [ - ("testGetCard", testGetCard), - ("testSetCard", testSetCard), - ("testSetCardIndexTooLow", testSetCardIndexTooLow), - ("testSetCardIndexTooHigh", testSetCardIndexTooHigh), - ("testInsertAtTop", testInsertAtTop), - ("testRemoveCard", testRemoveCard), - ("testRemoveCardIndexTooLow", testRemoveCardIndexTooLow), - ("testRemoveCardIndexTooHigh", testRemoveCardIndexTooHigh), - ("testRemoveTopCard", testRemoveTopCard), - ("testRemoveTopCardFromEmptyStack", testRemoveTopCardFromEmptyStack), - ("testInsertAtBottom", testInsertAtBottom), - ("testRemoveBottomCard", testRemoveBottomCard), - ("testRemoveBottomCardFromEmptyStack", testRemoveBottomCardFromEmptyStack), - ("testCheckSizeTrue", testCheckSizeTrue), - ("testCheckSizeFalse", testCheckSizeFalse), - ("testEvenCardCount", testEvenCardCount), - ("testEvenCardCountZero", testEvenCardCountZero), - ] + func testCheckSizeOfStackFalse() throws { + try XCTSkipIf(true && !runAll) // change true to false to run this test + let stack = [1,2,3,4,5] + XCTAssertFalse(checkSizeOfStack(stack, 4)) + } } diff --git a/exercises/concept/magician-in-training/Tests/MagicianInTrainingTests/XCTestManifests.swift b/exercises/concept/magician-in-training/Tests/MagicianInTrainingTests/XCTestManifests.swift deleted file mode 100644 index b1ebd20f7..000000000 --- a/exercises/concept/magician-in-training/Tests/MagicianInTrainingTests/XCTestManifests.swift +++ /dev/null @@ -1,9 +0,0 @@ -import XCTest - -#if !canImport(ObjectiveC) - public func allTests() -> [XCTestCaseEntry] { - return [ - testCase(MagicianInTrainingTests.allTests) - ] - } -#endif