Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #115 from Sensirion/add-voc-algorithm-tests
Browse files Browse the repository at this point in the history
Add VOC algorithm tests
  • Loading branch information
rnestler authored Oct 26, 2020
2 parents d423ab5 + 10dee7c commit 5752390
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions tests/sensirion-voc-algorithm-test.cpp
Original file line number Diff line number Diff line change
@@ -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(&params);
for (int i = 0; i < VocAlgorithm_INITIAL_BLACKOUT; ++i) {
int32_t voc_index;
VocAlgorithm_process(&params, 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(&params);
int32_t voc_index;
for (int i = 0; i < VocAlgorithm_INITIAL_BLACKOUT + 2; ++i) {
VocAlgorithm_process(&params, 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);
}

0 comments on commit 5752390

Please sign in to comment.