Files
yocto_rpi/sandbox_c/tests/test_temperature.c
T
druppy ba41deb9ec
Build RPi image / build (push) Successful in 10s
Sandbox - ephemeral runner + shared cache / cargo (push) Successful in 1m27s
Sandbox - cmake + ccache on the pool / build (push) Successful in 10s
Add sandbox_c cmake project + ccache workflow for pool testing
2026-10-24 22:54:55 +02:00

27 lines
820 B
C

#include "temperature.h"
#include <assert.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
int main(void) {
assert(fabs(to_fahrenheit(0.0) - 32.0) < 1e-9);
assert(fabs(to_fahrenheit(100.0) - 212.0) < 1e-9);
Reading r;
assert(parse_reading("{\"sensor\":\"attic\",\"celsius\":21.50}", &r) == 0);
assert(strcmp(r.sensor, "attic") == 0);
assert(fabs(r.celsius - 21.5) < 1e-9);
assert(parse_reading("{\"celsius\":-300.0}", &r) == 0);
assert(fabs(clamp_to_absolute_zero(r.celsius) + 273.15) < 1e-9);
assert(parse_reading("nonsense", &r) != 0);
char buf[128];
Reading in = { "boiler", 65.25 };
assert(format_reading(&in, buf, sizeof buf) == 0);
assert(strstr(buf, "\"sensor\":\"boiler\"") != NULL);
puts("all tempsense assertions passed");
return 0;
}