Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import Foundation
  2.  
  3. func testAssert(x:Int)->Int {
  4. var res = 0
  5. if x > 0 {
  6. res += 3
  7.  
  8. assertionFailure("testAssert")
  9. res += 5
  10. return res
  11. } else {
  12. res += 7
  13. }
  14.  
  15. res += 2
  16. return res
  17. }
  18.  
  19.  
  20. let i:Int = Int(arc4random())
  21. print(i)
  22.  
  23. let result = testAssert(i)
  24.  
  25. print("\n")
  26.  
  27. print(result)
  28.  
  29. print("\n")
  30. print("End")
  31.  
  32. // Result is:
  33. // 1661870581 -- (random result will vary but will be +ve
  34. // 9 -- (result of false case as assertion assumed valid in -Ounchecked in 6.4 or DISABLE_SAFETY_CHECKS in XC7
  35. // End -- Reaches end of execution
  36. // Program ended with exit code: 0 -- (Exits without error).
  37.  
  38. // For -O /safety checks on builds the 9 is replaced by 8 showing the test remains in place.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement