0
0
Swiftprogramming~10 mins

Assertions (XCTAssertEqual, XCTAssertTrue) in Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if two values are equal using XCTAssertEqual.

Swift
XCTAssertEqual([1], 5)
Drag options to blanks, or click blank then click option'
Aresult
Bprint
Ctrue
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a literal like 5 as the first argument instead of the variable.
Using XCTAssertTrue instead of XCTAssertEqual for value comparison.
2fill in blank
medium

Complete the code to assert that a condition is true using XCTAssertTrue.

Swift
XCTAssertTrue([1])
Drag options to blanks, or click blank then click option'
Aresult = 10
Bprint(result)
Cfalse
Dresult == 10
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment (=) instead of comparison (==).
Passing a function call like print() instead of a boolean condition.
3fill in blank
hard

Fix the error in the assertion to correctly check if two strings are equal.

Swift
XCTAssertEqual([1], "Hello")
Drag options to blanks, or click blank then click option'
Agreeting
Bgreeting()
Cprint(greeting)
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses after the variable name as if it were a function.
Passing print statements inside XCTAssertEqual.
4fill in blank
hard

Fill both blanks to assert that the count of items is greater than zero.

Swift
XCTAssertTrue([1] [2] 0)
Drag options to blanks, or click blank then click option'
Aitems.count
B==
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality (==) instead of greater than (>).
Using less than (<) which would check the wrong condition.
5fill in blank
hard

Fill all three blanks to assert that the uppercase version of a string equals "WORLD".

Swift
XCTAssertEqual([1].[2](), "[3]")
Drag options to blanks, or click blank then click option'
Aword
Buppercased
CWORLD
Dlowercased
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercased() instead of uppercased().
Comparing to the wrong string value.