Your question is Write a Simple Function Test. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
You're interviewing for a QA Engineer role at ScienceLogic, which monitors IT infrastructure and alerts on devices with abnormal uptime. Here's a function used to parse a device's reported uptime string into seconds, which then feeds an alert that fires when a device's uptime looks suspiciously low right after it should have been rebooted.
def parse_uptime_to_seconds(uptime_str):
# uptime_str examples: "5d 3h 12m", "0d 0h 45m", "2h", "90m"
if not uptime_str:
return 0
total_seconds = 0
parts = uptime_str.strip().split(" ")
for part in parts:
if part.endswith("d"):
total_seconds += int(part[:-1]) * 86400
elif part.endswith("h"):
total_seconds += int(part[:-1]) * 3600
elif part.endswith("m"):
total_seconds += int(part[:-1]) * 60
return total_seconds
Describe, as a set of concrete test cases, how you'd validate this function before it ships into the alerting pipeline. For each case, say what input you'd use, what you expect, and why that case matters given where this function is used. You don't need to write real code, just describe each test precisely enough that someone else could implement it exactly as you mean it.