changeset 285:cd2320cd6f9a

NEW unit tests for gas volumes...
author jdg@air
date Fri, 29 May 2015 01:25:45 +0200
parents d1117b99fd99
children 729b01914098
files src/Tests/compass_test.cpp src/Tests/compass_test.pro src/Tests/deco_volume_test.cpp src/Tests/main_test.cpp src/Tests/unit_test.cpp src/Tests/unit_test.pro src/p2_definitions.h
diffstat 7 files changed, 150 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/src/Tests/compass_test.cpp	Thu May 28 09:56:15 2015 +0200
+++ b/src/Tests/compass_test.cpp	Fri May 29 01:25:45 2015 +0200
@@ -56,7 +56,7 @@
              + sqr(compass_CZ_f/32768.0f - cz);
 
     // Calibration error less than 2 bits:
-    EXPECT_NEAR(0, sqrtf(r2), 3.0f/32768.0f)
+    EXPECT_NEAR(0, sqrtf(r2), 4.0f/32768.0f)
         << "Center at (" << compass_CX_f/32768.0f << ", "
                          << compass_CY_f/32768.0f << ", "
                          << compass_CZ_f/32768.0f << ")."
--- a/src/Tests/compass_test.pro	Thu May 28 09:56:15 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-#-----------------------------------------------------------------------------
-#
-# Project created by QtCreator 2013-03-29T10:58:23
-#
-#-----------------------------------------------------------------------------
-
-TEMPLATE = app
-TARGET = compass_test
-
-CONFIG   *= qt
-CONFIG   -= app_bundle
-
-QT       *= core
-QT       -= gui
-
-DEFINES *= UNIX
-
-#-----------------------------------------------------------------------------
-# Need the GoogleTest 1.6.0 library here:
-GTEST=$$PWD/../../../../Dependencies/gtest-1.6.0
-!exists($$GTEST/include): error(Requires GoogleTest 1.6.0)
-INCLUDEPATH *= $$GTEST/include $$GTEST/gtest-1.6.0
-SOURCES *= $$GTEST/gtest-1.6.0/src/gtest-all.cc
-win32: DEFINES *= _VARIADIC_MAX=10
-
-#-----------------------------------------------------------------------------
-SOURCES += \
-    $$PWD/../compass.c \
-    $$PWD/../compass_calib.c \
-    compass_trigo_test.cpp \
-    compass_test.cpp \
-    main_test.cpp
-
-INCLUDEPATH *= $$PWD/..
-HEADERS += \
-    $$PWD/../compass.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tests/deco_volume_test.cpp	Fri May 29 01:25:45 2015 +0200
@@ -0,0 +1,78 @@
+//////////////////////////////////////////////////////////////////////////////
+/// deco_volume_test.cpp
+/// Unit test for gas consumption c code.
+/// Copyright (c) 2015, JD Gascuel, HeinrichsWeikamp, all right reserved.
+//////////////////////////////////////////////////////////////////////////////
+//  HISTORY
+// 2015-05-27 jDG: Creation for gas volum re-introduction in hwOS 1.80
+
+extern "C" {
+#   include "p2_deco.c"
+}
+
+#include <gtest/gtest.h>
+
+//////////////////////////////////////////////////////////////////////////////
+/// \brief Defines a default OC gas list
+static void setup_gas()
+{
+    char_I_first_gas = 1;
+    char_I_const_ppO2 = 0;  // Default to OC mode
+
+#define DEFINE_GAS(gas, o2, he, depth, role)    \
+    char_I_deco_N2_ratio  [gas-1] = 100 - o2 - he;  \
+    char_I_deco_He_ratio  [gas-1] = he;             \
+    char_I_deco_gas_change[gas-1] = depth;
+
+    DEFINE_GAS(1, 21,  0, 0, 1);    // Gas#1 : Air       FIRST
+    DEFINE_GAS(2, 18, 30, 0, 2);    // Gas#2 : Tx18/30   TRAVEL
+    DEFINE_GAS(3, 80,  0, 9, 3);    // Gas#3 : Nx80 @ 9m DECO
+    DEFINE_GAS(4, 21, 0, 10, 0);    // Gas#2 : air @ 10m DISABLED
+    DEFINE_GAS(5, 21, 0, 40, 0);    // Gas#2 : air @ 40m DISABLED
+}
+
+//////////////////////////////////////////////////////////////////////////////
+/// \brief Define a default deco plan.
+static void setup_plan()
+{
+    // 1 min at 12m
+    char_O_deco_time [0] = 1;
+    char_O_deco_depth[0] =12;
+    char_O_deco_gas  [0] = 1; // Gas#1
+    // 1 min at 9m
+    char_O_deco_time [1] = 1;
+    char_O_deco_depth[1] = 9;
+    char_O_deco_gas  [1] = 3; // Gas#3
+    // 3min at 6m
+    char_O_deco_time [2] = 3;
+    char_O_deco_depth[2] = 6;
+    char_O_deco_gas  [2] = 3; // Gas#3
+    // 12 min at 3m
+    char_O_deco_time [3] =12;
+    char_O_deco_depth[3] = 3;
+    char_O_deco_gas  [3] = 3; // Gas#3
+    // Done
+    for(int s=4; s<NUM_STOPS; ++s) {
+        char_O_deco_time [s] = 0;
+        char_O_deco_depth[s] = 0;
+        char_O_deco_gas  [s] = 0;
+    }
+}
+
+static void setup_dive(int bottom, int depth)
+{
+    setup_gas();
+    setup_plan();
+
+    char_I_bottom_depth = bottom;
+    char_I_bottom_time  = depth;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+TEST(gas_volume, run)
+{
+    setup_dive(30, 40);     // 30' @ 40m
+
+    EXPECT_NO_THROW( deco_gas_volumes() );
+}
--- a/src/Tests/main_test.cpp	Thu May 28 09:56:15 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-/// main_test.cpp
-/// Launch all defined GoogleTest unit tests defined.
-/// Copyright (c) 2012-2015, JD Gascuel, HeinrichsWeikamp, all right reserved.
-//////////////////////////////////////////////////////////////////////////////
-//  HISTORY
-// 2015-05-23 jDG: Rewrite compass testing, to allow reducing code size.
-
-#include <gtest/gtest.h>
-
-int main(int argc, char *argv[])
-{
-    ::testing::InitGoogleTest(&argc, argv);
-    return RUN_ALL_TESTS();
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tests/unit_test.cpp	Fri May 29 01:25:45 2015 +0200
@@ -0,0 +1,16 @@
+//////////////////////////////////////////////////////////////////////////////
+/// main_test.cpp
+/// Launch all defined GoogleTest unit tests defined.
+/// Copyright (c) 2012-2015, JD Gascuel, HeinrichsWeikamp, all right reserved.
+//////////////////////////////////////////////////////////////////////////////
+//  HISTORY
+// 2015-05-23 jDG: Rewrite compass testing, to allow reducing code size.
+
+#include <gtest/gtest.h>
+
+int main(int argc, char *argv[])
+{
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tests/unit_test.pro	Fri May 29 01:25:45 2015 +0200
@@ -0,0 +1,53 @@
+#-----------------------------------------------------------------------------
+#
+# Project created by QtCreator 2013-03-29T10:58:23
+#
+#-----------------------------------------------------------------------------
+
+TEMPLATE = app
+TARGET   = unit_test
+
+CONFIG   *= qt
+CONFIG   -= app_bundle
+
+QT       *= core
+QT       -= gui
+
+DEFINES *= UNIX
+
+#-----------------------------------------------------------------------------
+# Need the GoogleTest 1.6.0 library here:
+GTEST=$$PWD/../../../gtest-1.6.0
+!exists($$GTEST/include): GTEST=$$PWD/../../../../Dependencies/gtest-1.6.0
+!exists($$GTEST/include): error(Requires GoogleTest 1.6.0)
+INCLUDEPATH *= $$GTEST/include $$GTEST/gtest-1.6.0
+SOURCES *= $$GTEST/gtest-1.6.0/src/gtest-all.cc
+
+win32: DEFINES *= _VARIADIC_MAX=10
+
+#-----------------------------------------------------------------------------
+# Avoid unwanted warnings
+
+unix {
+    QMAKE_CXXFLAGS_WARN_ON *= -Wno-unknown-pragmas
+}
+
+win32 {
+    QMAKE_CXXFLAGS *= -wd4244 -wd4068 -wd4305
+}
+
+#-----------------------------------------------------------------------------
+SOURCES += \
+    $$PWD/../compass.c          \
+    $$PWD/../compass_calib.c    \
+    compass_trigo_test.cpp      \
+    compass_test.cpp            \
+    deco_volume_test.cpp        \
+    unit_test.cpp
+
+INCLUDEPATH *= $$PWD/..
+HEADERS += \
+    $$PWD/../shared_definitions.h   \
+    $$PWD/../p2_definitions.h       \
+    $$PWD/../p2_deco.c              \
+    $$PWD/../compass.h
--- a/src/p2_definitions.h	Thu May 28 09:56:15 2015 +0200
+++ b/src/p2_definitions.h	Fri May 29 01:25:45 2015 +0200
@@ -23,7 +23,6 @@
 // history:
 // 2010-12-25 v110: [jDG] split in three files (deco.c, main.c, definitions.h)
 
-
 #define	MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF	150
 
 // *************************
@@ -48,7 +47,7 @@
 // **         Allow compile on VisualC          **
 // ***********************************************
 
-#ifdef WIN32
+#if defined(WIN32) || defined(UNIX)
     // Some keywords just dont exists on Visual C++:
 #   define CROSS_COMPILE
 #   define __18CXX
@@ -57,10 +56,7 @@
 #   define overlay
 #   define PARAMETER
 
-#include <assert.h>
-
-    // Avoid warnings about float/double mismatches:
-#   pragma warning(disable: 4244 4068 4305)
+#   include <assert.h>
 #else
 #   define PARAMETER static
 #   ifdef __DEBUG