diff --git a/.gitignore b/.gitignore index a41989f..1050030 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ tests/sgpc3-test-hw_i2c tests/sgpc3-test-sw_i2c tests/svm30-test-hw_i2c tests/svm30-test-sw_i2c +tests/sensirion-voc-algorithm-test diff --git a/tests/Makefile b/tests/Makefile index d50fa75..cc37ed3 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -8,7 +8,9 @@ include ${sgp_driver_dir}/sgpc3/default_config.inc sgp30_test_binaries := sgp30-test-hw_i2c sgp30-test-sw_i2c sgp40_test_binaries := sgp40-test-hw_i2c sgp40-test-sw_i2c -sgp40_voc_index_test_binaries := sgp40-voc-index-test-hw_i2c sgp40-voc-index-test-sw_i2c +sgp40_voc_index_test_binaries := sgp40-voc-index-test-hw_i2c \ + sgp40-voc-index-test-sw_i2c \ + sensirion-voc-algorithm-test sgpc3_test_binaries := sgpc3-test-hw_i2c sgpc3-test-sw_i2c svm30_test_binaries := svm30-test-hw_i2c svm30-test-sw_i2c sgp_test_binaries := ${sgp30_test_binaries} \ @@ -48,6 +50,9 @@ sgp40-voc-index-test-sw_i2c: CONFIG_I2C_TYPE := sw_i2c sgp40-voc-index-test-sw_i2c: sgp40-voc-index-test.cpp ${sgp40_voc_index_sources} ${sw_i2c_sources} ${sensirion_test_sources} $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) +sensirion-voc-algorithm-test: sensirion-voc-algorithm-test.cpp ${sgp40_voc_index_voc_algorithm_sources} + $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) + sgpc3-test-hw_i2c: CONFIG_I2C_TYPE := hw_i2c sgpc3-test-hw_i2c: sgpc3-test.cpp ${sgpc3_sources} ${hw_i2c_sources} ${sensirion_test_sources} $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) diff --git a/tests/sensirion-voc-algorithm-test.cpp b/tests/sensirion-voc-algorithm-test.cpp new file mode 100644 index 0000000..c95843a --- /dev/null +++ b/tests/sensirion-voc-algorithm-test.cpp @@ -0,0 +1,32 @@ +#include "CppUTest/CommandLineTestRunner.h" +#include "sensirion_voc_algorithm.h" + +TEST_GROUP (Sgp40VocIndexAlgorithmTest) {}; + +TEST (Sgp40VocIndexAlgorithmTest, returns_zero_during_blackout) { + VocAlgorithmParams params; + VocAlgorithm_init(¶ms); + for (int i = 0; i < VocAlgorithm_INITIAL_BLACKOUT; ++i) { + int32_t voc_index; + VocAlgorithm_process(¶ms, 0, &voc_index); + CHECK_EQUAL_TEXT(0, voc_index, + "VOC index should be 0 during initial blackout"); + } +} + +TEST (Sgp40VocIndexAlgorithmTest, returns_average_after_blackout) { + VocAlgorithmParams params; + VocAlgorithm_init(¶ms); + int32_t voc_index; + for (int i = 0; i < VocAlgorithm_INITIAL_BLACKOUT + 2; ++i) { + VocAlgorithm_process(¶ms, 0, &voc_index); + } + + CHECK_EQUAL_TEXT( + VocAlgorithm_VOC_INDEX_OFFSET_DEFAULT, voc_index, + "VOC index should be the offset default after the the blackout period"); +} + +int main(int argc, char** argv) { + return CommandLineTestRunner::RunAllTests(argc, argv); +}