27 lines
820 B
C
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;
|
|
}
|