add test for sensor_name and sensor_unit
All checks were successful
Unit Tests / Run Tests (push) Successful in 10s
All checks were successful
Unit Tests / Run Tests (push) Successful in 10s
This commit is contained in:
parent
4b766f54ae
commit
113384b6ce
2 changed files with 25 additions and 2 deletions
|
|
@ -14,8 +14,8 @@ pub type SensorReading {
|
||||||
SensorReading(sensor: Sensor, value: Float)
|
SensorReading(sensor: Sensor, value: Float)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_sensor_reading(reading: SensorReading) -> Nil {
|
pub fn sensor_name(sensor: Sensor) -> String {
|
||||||
let sensor_name = case reading.sensor {
|
case sensor {
|
||||||
Temperature -> "Temperature"
|
Temperature -> "Temperature"
|
||||||
Humidity -> "Humidity"
|
Humidity -> "Humidity"
|
||||||
Pressure -> "Pressure"
|
Pressure -> "Pressure"
|
||||||
|
|
@ -23,6 +23,10 @@ pub fn print_sensor_reading(reading: SensorReading) -> Nil {
|
||||||
ParticalMatterTwoPointFive -> "Partical matter 2.5 micros or less"
|
ParticalMatterTwoPointFive -> "Partical matter 2.5 micros or less"
|
||||||
ParticalMatterTen -> "Partical matter 10 microns or less"
|
ParticalMatterTen -> "Partical matter 10 microns or less"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_sensor_reading(reading: SensorReading) -> Nil {
|
||||||
|
let sensor_name = sensor_name(reading.sensor)
|
||||||
io.println(sensor_name <> ": " <> float.to_string(reading.value))
|
io.println(sensor_name <> ": " <> float.to_string(reading.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
19
test/sensors_test.gleam
Normal file
19
test/sensors_test.gleam
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import gleeunit
|
||||||
|
import gleeunit/should
|
||||||
|
import sensors
|
||||||
|
|
||||||
|
pub fn main() -> Nil {
|
||||||
|
gleeunit.main()
|
||||||
|
}
|
||||||
|
|
||||||
|
// gleeunit test functions end in `_test`
|
||||||
|
pub fn file_read_test() {
|
||||||
|
let reading =
|
||||||
|
sensors.sensor_name(sensors.Temperature)
|
||||||
|
<> " "
|
||||||
|
<> "20.5"
|
||||||
|
<> " "
|
||||||
|
<> sensors.sensor_unit(sensors.Temperature)
|
||||||
|
reading
|
||||||
|
|> should.equal("Temperature 20.5 °C")
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue