Last active
November 14, 2023 04:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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