coffee/barista/test/test_overheat.c
2025-10-15 21:14:19 +02:00

37 lines
736 B
C

/* Copyright (c) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
* SPDX-License-Identifier: GPL-3.0-or-later */
#include <stdio.h>
#include "overheat.h"
/* Read a CSV from the stdin in the format
* <time_in_seconds> <state> <temp_in_C>
* skipping the first row (header).
*
* Outputs overheat state. */
#define MAX_LINE 1024
int main(void)
{
char buf[MAX_LINE];
fgets(buf, MAX_LINE, stdin);
float t, temp;
int st;
struct overheat ovh;
overheat_init(&ovh);
while (scanf("%f %d %f", &t, &st, &temp) == 3) {
overheat_input(&ovh, t * 1000.0, temp);
float delta = overheat_delta(&ovh);
int panic = overheat_panic(&ovh);
printf("%.3f %d %.2f %.1f %s\n", t, st, temp, delta, panic ? "PANIC" : "OK");
}
return 0;
}