Added tests for calc

This commit is contained in:
Magnus 2022-12-02 10:59:39 +01:00
parent a191f6bb35
commit a7362a42fa

View File

@ -21,20 +21,41 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <Arduino.h>
#include <main.hpp>
#include <calc.hpp>
#include <helper.hpp>
#include <AUnit.h>
test(calc_createFormula) {
Serial.println("Not implemented yet (calc_createFormula)");
// TODO: Add more test cases to explore formula creation error conditions when values are out of bounds
// TODO: Add more test cases to check order 3 + 4 formula creation as well.
test(calc_createFormula1) {
char buffer[100];
RawFormulaData fd = { { 0.0, 25.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 1.02, 1.033, 1.00011, 1.0, 1.0, 1.0, 1.0, 1.0} };
int i = createFormula(fd, &buffer[0], sizeof(buffer), 2);
assertEqual( i, ERR_FORMULA_NOTENOUGHVALUES );
}
test(calc_createFormula2) {
char buffer[100];
RawFormulaData fd = { { 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0}, {1.0, 1.01, 1.02, 1.03, 1.04, 1.05, 1.06, 1.07, 1.08, 1.1} };
int i = createFormula(fd, &buffer[0], sizeof(buffer), 2);
assertEqual( i, 0 );
assertEqual( &buffer[0], "0.00000909*tilt^2+0.00124545*tilt+0.96445455");
}
test(calc_calculateGravity) {
Serial.println("Not implemented yet (calc_calculateGravity)");
const char* formula = "0.00000909*tilt^2+0.00124545*tilt+0.96445455";
double g = calculateGravity(30, 20, formula);
float v1 = reduceFloatPrecision(g, 2);
float v2 = 1.01;
assertEqual(v1, v2);
}
test(calc_gravityTemperatureCorrectionC) {
Serial.println("Not implemented yet (calc_gravityTemperatureCorrectionC)");
double g = gravityTemperatureCorrectionC( 1.02, 45.0, 20.0);
float v1 = reduceFloatPrecision(g, 2);
float v2 = 1.03;
assertEqual(v1, v2);
}
// EOF