mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Add tests for formatDiveGasString
This adds tests for formatDiveGasString to ensure it produces the expected results in some scenarios. Signed-off-by: Anton Lundin <glance@ac2.se>
This commit is contained in:
parent
725b70e64c
commit
bba0da589b
3 changed files with 193 additions and 0 deletions
|
@ -146,6 +146,7 @@ TEST(TestQPrefProxy testqPrefProxy.cpp)
|
|||
TEST(TestQPrefTechnicalDetails testqPrefTechnicalDetails.cpp)
|
||||
TEST(TestQPrefUnits testqPrefUnits.cpp)
|
||||
TEST(TestQPrefUpdateManager testqPrefUpdateManager.cpp)
|
||||
TEST(TestformatDiveGasString testformatDiveGasString.cpp)
|
||||
add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> -input ${SUBSURFACE_SOURCE}/tests)
|
||||
|
||||
# this is currently broken
|
||||
|
|
173
tests/testformatDiveGasString.cpp
Normal file
173
tests/testformatDiveGasString.cpp
Normal file
|
@ -0,0 +1,173 @@
|
|||
#include "testformatDiveGasString.h"
|
||||
|
||||
#include "../core/dive.h"
|
||||
#include "../core/string-format.h"
|
||||
|
||||
void TestformatDiveGasString::init()
|
||||
{
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_empty()
|
||||
{
|
||||
struct dive dive = {0};
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), "air");
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_air()
|
||||
{
|
||||
struct dive dive = {0};
|
||||
cylinder_t *cylinder = get_or_create_cylinder(&dive, 0);
|
||||
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), "air");
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_nitrox() {
|
||||
struct dive dive = {0};
|
||||
cylinder_t *cylinder = get_or_create_cylinder(&dive, 0);
|
||||
|
||||
cylinder->gasmix.o2.permille = 320;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), "32%");
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_nitrox_not_use() {
|
||||
struct dive dive = {0};
|
||||
cylinder_t *cylinder = get_or_create_cylinder(&dive, 0);
|
||||
|
||||
cylinder->gasmix.o2.permille = 320;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
cylinder = get_or_create_cylinder(&dive, 1);
|
||||
|
||||
cylinder->gasmix.o2.permille = 1000;
|
||||
cylinder->cylinder_use = NOT_USED;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), "32%");
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_nitrox_deco() {
|
||||
struct dive dive = {0};
|
||||
cylinder_t *cylinder = get_or_create_cylinder(&dive, 0);
|
||||
|
||||
cylinder->gasmix.o2.permille = 320;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
cylinder = get_or_create_cylinder(&dive, 1);
|
||||
|
||||
cylinder->gasmix.o2.permille = 1000;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), QString("32…100%"));
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_reverse_nitrox_deco() {
|
||||
struct dive dive = {0};
|
||||
cylinder_t *cylinder = get_or_create_cylinder(&dive, 0);
|
||||
|
||||
cylinder->gasmix.o2.permille = 1000;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
cylinder = get_or_create_cylinder(&dive, 1);
|
||||
|
||||
cylinder->gasmix.o2.permille = 270;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), QString("27…100%"));
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_trimix() {
|
||||
struct dive dive = {0};
|
||||
cylinder_t *cylinder = get_or_create_cylinder(&dive, 0);
|
||||
|
||||
cylinder->gasmix.o2.permille = 210;
|
||||
cylinder->gasmix.he.permille = 350;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), "21/35");
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_trimix_deco() {
|
||||
struct dive dive = {0};
|
||||
cylinder_t *cylinder = get_or_create_cylinder(&dive, 0);
|
||||
|
||||
cylinder->gasmix.o2.permille = 210;
|
||||
cylinder->gasmix.he.permille = 350;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
cylinder = get_or_create_cylinder(&dive, 1);
|
||||
|
||||
cylinder->gasmix.o2.permille = 500;
|
||||
cylinder->gasmix.he.permille = 200;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
cylinder = get_or_create_cylinder(&dive, 2);
|
||||
|
||||
cylinder->gasmix.o2.permille = 1000;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), "21/35…100%");
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_reverse_trimix_deco() {
|
||||
struct dive dive = {0};
|
||||
cylinder_t *cylinder = get_or_create_cylinder(&dive, 0);
|
||||
|
||||
cylinder->gasmix.o2.permille = 1000;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
cylinder = get_or_create_cylinder(&dive, 1);
|
||||
|
||||
cylinder->gasmix.o2.permille = 500;
|
||||
cylinder->gasmix.he.permille = 200;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
cylinder = get_or_create_cylinder(&dive, 2);
|
||||
|
||||
cylinder->gasmix.o2.permille = 210;
|
||||
cylinder->gasmix.he.permille = 350;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), "21/35…100%");
|
||||
}
|
||||
|
||||
void TestformatDiveGasString::test_ccr() {
|
||||
struct dive dive = {0};
|
||||
cylinder_t *cylinder = get_or_create_cylinder(&dive, 0);
|
||||
|
||||
cylinder->gasmix.o2.permille = 1000;
|
||||
cylinder->cylinder_use = OXYGEN;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
cylinder = get_or_create_cylinder(&dive, 1);
|
||||
|
||||
cylinder->gasmix.o2.permille = 210;
|
||||
cylinder->gasmix.he.permille = 350;
|
||||
cylinder->cylinder_use = DILUENT;
|
||||
cylinder->start.mbar = 230000;
|
||||
cylinder->end.mbar = 100000;
|
||||
|
||||
QCOMPARE(formatDiveGasString(&dive), "21/35");
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestformatDiveGasString)
|
19
tests/testformatDiveGasString.h
Normal file
19
tests/testformatDiveGasString.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
class TestformatDiveGasString : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void init();
|
||||
void test_empty();
|
||||
void test_air();
|
||||
void test_nitrox();
|
||||
void test_nitrox_not_use();
|
||||
void test_nitrox_deco();
|
||||
void test_reverse_nitrox_deco();
|
||||
void test_trimix();
|
||||
void test_trimix_deco();
|
||||
void test_reverse_trimix_deco();
|
||||
void test_ccr();
|
||||
};
|
Loading…
Add table
Reference in a new issue