software:firmware
MakAir Firmware
test_pressure.cpp File Reference

Unit tests for pressure.cpp. More...

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <iostream>
#include <vector>
#include "../includes/pressure_utl.h"

Go to the source code of this file.

Classes

class  PressionTest
 Test Fixture to test the pression file. More...
 

Macros

#define KPA_MMH2O   101.97162129779
 
#define RATIO_VOLTAGE_DIVIDER   0.8192
 
#define V_SUPPLY   5.08
 
#define NEAR_EQUAL_DIFF   2
 

Functions

int16_t convertSensor2PressureFloat (uint16_t sensorValue)
 Old converting function using floats. More...
 
 TEST_F (PressionTest, testConvertSensor2PressureCompWithFloat)
 Test convertSensor2Pressure with comparison with old floating point function. More...
 
 TEST_F (PressionTest, testConvertSensor2Pressure)
 Test convertSensor2Pressure with arbitrary values. More...
 

Detailed Description

Unit tests for pressure.cpp.

Author
Makers For Life

Definition in file test_pressure.cpp.

Macro Definition Documentation

◆ KPA_MMH2O

#define KPA_MMH2O   101.97162129779

Definition at line 16 of file test_pressure.cpp.

◆ NEAR_EQUAL_DIFF

#define NEAR_EQUAL_DIFF   2

Definition at line 52 of file test_pressure.cpp.

◆ RATIO_VOLTAGE_DIVIDER

#define RATIO_VOLTAGE_DIVIDER   0.8192

Definition at line 17 of file test_pressure.cpp.

◆ V_SUPPLY

#define V_SUPPLY   5.08

Definition at line 18 of file test_pressure.cpp.

Function Documentation

◆ convertSensor2PressureFloat()

int16_t convertSensor2PressureFloat ( uint16_t  sensorValue)

Old converting function using floats.

Definition at line 21 of file test_pressure.cpp.

21  {
22  static float filteredVout = 0;
23  double rawVout = sensorValue * 3.3 / 1024.0;
24  filteredVout = filteredVout + (rawVout - filteredVout) * 0.2;
25 
26  // Voltage divider ratio
27  double vOut = filteredVout / RATIO_VOLTAGE_DIVIDER;
28 
29  // Pressure converted to kPA
30  double pressure = ((vOut / V_SUPPLY) - 0.04) / 0.09;
31 
32  if (pressure <= 0.0) {
33  pressure = 0;
34  }
35 
36  return pressure * KPA_MMH2O;
37 }
#define KPA_MMH2O
#define RATIO_VOLTAGE_DIVIDER
#define V_SUPPLY

◆ TEST_F() [1/2]

TEST_F ( PressionTest  ,
testConvertSensor2Pressure   
)

Test convertSensor2Pressure with arbitrary values.

Definition at line 77 of file test_pressure.cpp.

77  {
78  std::vector<uint16_t> outputTruth = {0, 0, 144, 984, 2182, 4545, 7839, 17762};
79  std::vector<uint16_t> output;
80 
81  for (size_t i = 0; i < input.size(); i++) {
82  output.push_back(convertSensor2Pressure(input[i]));
83 
84  std::cout << output.back() << std::endl;
85  }
86 
87  ASSERT_THAT(output, testing::ElementsAreArray(outputTruth));
88 }
uint16_t i
int16_t convertSensor2Pressure(uint32_t sensorValue)
Convert the analog value from sensor to a pressure value.

◆ TEST_F() [2/2]

TEST_F ( PressionTest  ,
testConvertSensor2PressureCompWithFloat   
)

Test convertSensor2Pressure with comparison with old floating point function.

Definition at line 57 of file test_pressure.cpp.

57  {
58  std::vector<uint16_t> outputTruth;
59  std::vector<uint16_t> output;
60 
61  for (size_t i = 0; i < input.size(); i++) {
62  outputTruth.push_back(convertSensor2PressureFloat(input[i]));
63  output.push_back(convertSensor2Pressure(input[i]));
64 
65  std::cout << outputTruth.back() << " " << output.back() << std::endl;
66  }
67 
68  for (int i = 0; i < output.size(); i++) {
69  ASSERT_LE(std::abs(outputTruth[i] - output[i]), 2);
70  }
71 }
int16_t convertSensor2PressureFloat(uint16_t sensorValue)
Old converting function using floats.