Skip to content

Instantly share code, notes, and snippets.

@mariozig
Last active November 14, 2023 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariozig/524cb9d22a6981ab55a8641f6e2e4650 to your computer and use it in GitHub Desktop.
Save mariozig/524cb9d22a6981ab55a8641f6e2e4650 to your computer and use it in GitHub Desktop.
Question 1: Given the following implementation, please produce a test suite for TemperatureManager
import Foundation
import XCTest
// Implementation
protocol TemperatureManagerDelegate: AnyObject {
func temperatureManager(_ temperatureManager: TemperatureManager, didUpdateTemperature temperature: Double)
}
class TemperatureManager {
weak var delegate: TemperatureManagerDelegate?
func startUpdating() {
// Simulate of continuous update of temperature change.
DispatchQueue.global().async {
usleep(100)
for i in 0..<5 {
let newTemperature: Double = Double(i * 7)
DispatchQueue.main.async {
self.delegate?.temperatureManager(self, didUpdateTemperature: newTemperature)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment