1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
|
// SPDX-License-Identifier: GPL-2.0
#include "testplan.h"
#include "core/dive.h"
#include "core/planner.h"
#include "core/qthelper.h"
#include "core/subsurfacestartup.h"
#include "core/units.h"
#include <QDebug>
#define DEBUG 1
// testing the dive plan algorithm
struct decostop stoptable[60];
struct deco_state test_deco_state;
extern bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer);
void setupPrefs()
{
copy_prefs(&default_prefs, &prefs);
prefs.ascrate50 = feet_to_mm(30) / 60;
prefs.ascrate75 = prefs.ascrate50;
prefs.ascratestops = prefs.ascrate50;
prefs.ascratelast6m = feet_to_mm(10) / 60;
prefs.last_stop = true;
}
void setupPrefsVpmb()
{
copy_prefs(&default_prefs, &prefs);
prefs.ascrate50 = 10000 / 60;
prefs.ascrate75 = prefs.ascrate50;
prefs.ascratestops = prefs.ascrate50;
prefs.ascratelast6m = prefs.ascrate50;
prefs.descrate = 99000 / 60;
prefs.last_stop = false;
prefs.planner_deco_mode = VPMB;
prefs.vpmb_conservatism = 0;
}
void setupPlan(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->gfhigh = 100;
dp->gflow = 100;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{150}, {450}};
struct gasmix ean36 = {{360}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 36000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.cylinder[1].gasmix = ean36;
displayed_dive.cylinder[2].gasmix = oxygen;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(79, 260) * 60 / M_OR_FT(23, 75);
plan_add_segment(dp, 0, gas_mod(&ean36, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC);
plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 2, 0, 1, OC);
plan_add_segment(dp, droptime, M_OR_FT(79, 260), 0, 0, 1, OC);
plan_add_segment(dp, 30 * 60 - droptime, M_OR_FT(79, 260), 0, 0, 1, OC);
}
void setupPlanVpmb45m30mTx(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->gfhigh = 100;
dp->gflow = 100;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{210}, {350}};
struct gasmix ean50 = {{500}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 24000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.cylinder[1].gasmix = ean50;
displayed_dive.cylinder[2].gasmix = oxygen;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(45, 150) * 60 / M_OR_FT(23, 75);
plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC);
plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 2, 0, 1, OC);
plan_add_segment(dp, droptime, M_OR_FT(45, 150), 0, 0, 1, OC);
plan_add_segment(dp, 30 * 60 - droptime, M_OR_FT(45, 150), 0, 0, 1, OC);
}
void setupPlanVpmb60m10mTx(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->gfhigh = 100;
dp->gflow = 100;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{180}, {450}};
struct gasmix tx50_15 = {{500}, {150}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 24000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.cylinder[1].gasmix = tx50_15;
displayed_dive.cylinder[2].gasmix = oxygen;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(23, 75);
plan_add_segment(dp, 0, gas_mod(&tx50_15, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC);
plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 2, 0, 1, OC);
plan_add_segment(dp, droptime, M_OR_FT(60, 200), 0, 0, 1, OC);
plan_add_segment(dp, 10 * 60 - droptime, M_OR_FT(60, 200), 0, 0, 1, OC);
}
void setupPlanVpmb60m30minAir(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{210}, {0}};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 100000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330);
plan_add_segment(dp, droptime, M_OR_FT(60, 200), 0, 0, 1, OC);
plan_add_segment(dp, 30 * 60 - droptime, M_OR_FT(60, 200), 0, 0, 1, OC);
}
void setupPlanVpmb60m30minEan50(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{210}, {0}};
struct gasmix ean50 = {{500}, {0}};
pressure_t po2 = {1600};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 36000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.cylinder[1].gasmix = ean50;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330);
plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC);
plan_add_segment(dp, droptime, M_OR_FT(60, 200), 0, 0, 1, OC);
plan_add_segment(dp, 30 * 60 - droptime, M_OR_FT(60, 200), 0, 0, 1, OC);
}
void setupPlanVpmb60m30minTx(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{180}, {450}};
struct gasmix ean50 = {{500}, {0}};
pressure_t po2 = {1600};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 36000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.cylinder[1].gasmix = ean50;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330);
plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC);
plan_add_segment(dp, droptime, M_OR_FT(60, 200), 0, 0, 1, OC);
plan_add_segment(dp, 30 * 60 - droptime, M_OR_FT(60, 200), 0, 0, 1, OC);
}
void setupPlanVpmbMultiLevelAir(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{210}, {0}};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 200000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(20, 66) * 60 / M_OR_FT(99, 330);
plan_add_segment(dp, droptime, M_OR_FT(20, 66), 0, 0, 1, OC);
plan_add_segment(dp, 10 * 60 - droptime, M_OR_FT(20, 66), 0, 0, 1, OC);
plan_add_segment(dp, 1 * 60, M_OR_FT(60, 200), 0, 0, 1, OC);
plan_add_segment(dp, 29 * 60, M_OR_FT(60, 200), 0, 0, 1, OC);
}
void setupPlanVpmb100m60min(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{180}, {450}};
struct gasmix ean50 = {{500}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 200000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.cylinder[1].gasmix = ean50;
displayed_dive.cylinder[2].gasmix = oxygen;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(99, 330);
plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC);
plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 2, 0, 1, OC);
plan_add_segment(dp, droptime, M_OR_FT(100, 330), 0, 0, 1, OC);
plan_add_segment(dp, 60 * 60 - droptime, M_OR_FT(100, 330), 0, 0, 1, OC);
}
void setupPlanVpmb100m10min(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{180}, {450}};
struct gasmix ean50 = {{500}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 60000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.cylinder[1].gasmix = ean50;
displayed_dive.cylinder[2].gasmix = oxygen;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(99, 330);
plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC);
plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 2, 0, 1, OC);
plan_add_segment(dp, droptime, M_OR_FT(100, 330), 0, 0, 1, OC);
plan_add_segment(dp, 10 * 60 - droptime, M_OR_FT(100, 330), 0, 0, 1, OC);
}
void setupPlanVpmb30m20min(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{210}, {0}};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 36000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(30, 100) * 60 / M_OR_FT(18, 60);
plan_add_segment(dp, droptime, M_OR_FT(30, 100), 0, 0, 1, OC);
plan_add_segment(dp, 20 * 60 - droptime, M_OR_FT(30, 100), 0, 0, 1, OC);
}
void setupPlanVpmb100mTo70m30min(struct diveplan *dp)
{
dp->salinity = 10300;
dp->surface_pressure = 1013;
dp->bottomsac = prefs.bottomsac;
dp->decosac = prefs.decosac;
struct gasmix bottomgas = {{120}, {650}};
struct gasmix tx21_35 = {{210}, {350}};
struct gasmix ean50 = {{500}, {0}};
struct gasmix oxygen = {{1000}, {0}};
pressure_t po2 = {1600};
displayed_dive.cylinder[0].gasmix = bottomgas;
displayed_dive.cylinder[0].type.size.mliter = 36000;
displayed_dive.cylinder[0].type.workingpressure.mbar = 232000;
displayed_dive.cylinder[1].gasmix = tx21_35;
displayed_dive.cylinder[2].gasmix = ean50;
displayed_dive.cylinder[3].gasmix = oxygen;
displayed_dive.surface_pressure.mbar = 1013;
reset_cylinders(&displayed_dive, true);
free_dps(dp);
int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(18, 60);
plan_add_segment(dp, 0, gas_mod(&tx21_35, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC);
plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 2, 0, 1, OC);
plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 3, 0, 1, OC);
plan_add_segment(dp, droptime, M_OR_FT(100, 330), 0, 0, 1, OC);
plan_add_segment(dp, 20 * 60 - droptime, M_OR_FT(100, 330), 0, 0, 1, OC);
plan_add_segment(dp, 3 * 60, M_OR_FT(70, 230), 0, 0, 1, OC);
plan_add_segment(dp, (30 - 20 - 3) * 60, M_OR_FT(70, 230), 0, 0, 1, OC);
}
/* We compare the calculated runtimes against two values:
* - Known runtime calculated by Subsurface previously (to detect if anything has changed)
* - Benchmark runtime (we should be close, but not always exactly the same)
*/
bool compareDecoTime(int actualRunTimeSeconds, int benchmarkRunTimeSeconds, int knownSsrfRunTimeSeconds)
{
bool result;
// If the calculated run time equals the expected run time, do a simple comparison
if (actualRunTimeSeconds == benchmarkRunTimeSeconds) {
result = true;
} else {
/* We want the difference between the expected and calculated total run time to be not more than
* 1% of total run time + 1 minute */
int permilDifferenceAllowed = 1 * 10;
int absoluteDifferenceAllowedSeconds = 60;
int totalDifferenceAllowed = lrint(0.001 * permilDifferenceAllowed * benchmarkRunTimeSeconds + absoluteDifferenceAllowedSeconds);
int totalDifference = abs(actualRunTimeSeconds - benchmarkRunTimeSeconds);
qDebug("Calculated run time = %d seconds", actualRunTimeSeconds);
qDebug("Expected run time = %d seconds", benchmarkRunTimeSeconds);
qDebug("Allowed time difference is %g percent plus %d seconds = %d seconds",
permilDifferenceAllowed * 0.1, absoluteDifferenceAllowedSeconds, totalDifferenceAllowed);
qDebug("total difference = %d seconds", totalDifference);
result = (totalDifference <= totalDifferenceAllowed);
}
if ((knownSsrfRunTimeSeconds > 0) && (actualRunTimeSeconds != knownSsrfRunTimeSeconds)) {
QWARN("Calculated run time does not match known Subsurface runtime");
qWarning("Calculated runtime: %d", actualRunTimeSeconds);
qWarning("Known Subsurface runtime: %d", knownSsrfRunTimeSeconds);
}
return result;
}
void TestPlan::testMetric()
{
struct deco_state *cache = NULL;
setupPrefs();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
prefs.planner_deco_mode = BUEHLMANN;
struct diveplan testPlan = {};
setupPlan(&testPlan);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 148l);
// check first gas change to EAN36 at 33m
struct event *ev = displayed_dive.dc.events;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 1);
QCOMPARE(ev->value, 36);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 33000);
// check second gas change to Oxygen at 6m
ev = ev->next;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 2);
QCOMPARE(ev->value, 100);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 6000);
// check expected run time of 109 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 109u * 60u, 109u * 60u));
}
void TestPlan::testImperial()
{
struct deco_state *cache = NULL;
setupPrefs();
prefs.unit_system = IMPERIAL;
prefs.units.length = units::FEET;
prefs.planner_deco_mode = BUEHLMANN;
struct diveplan testPlan = {};
setupPlan(&testPlan);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 154l);
// check first gas change to EAN36 at 33m
struct event *ev = displayed_dive.dc.events;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 1);
QCOMPARE(ev->value, 36);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 33528);
// check second gas change to Oxygen at 6m
ev = ev->next;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 2);
QCOMPARE(ev->value, 100);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 6096);
// check expected run time of 111 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 111u * 60u - 2u, 111u * 60u - 2u));
}
void TestPlan::testVpmbMetric45m30minTx()
{
struct deco_state *cache = NULL;
setupPrefsVpmb();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
struct diveplan testPlan = {};
setupPlanVpmb45m30mTx(&testPlan);
setCurrentAppState("PlanDive");
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 108l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check benchmark run time of 141 minutes, and known Subsurface runtime of 139 minutes
//QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 141u * 60u + 20u, 139u * 60u + 20u));
}
void TestPlan::testVpmbMetric60m10minTx()
{
struct deco_state *cache = NULL;
setupPrefsVpmb();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
struct diveplan testPlan = {};
setupPlanVpmb60m10mTx(&testPlan);
setCurrentAppState("PlanDive");
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 162l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check benchmark run time of 141 minutes, and known Subsurface runtime of 139 minutes
//QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 141u * 60u + 20u, 139u * 60u + 20u));
}
void TestPlan::testVpmbMetric60m30minAir()
{
struct deco_state *cache = NULL;
setupPrefsVpmb();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
struct diveplan testPlan = {};
setupPlanVpmb60m30minAir(&testPlan);
setCurrentAppState("PlanDive");
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 180l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check benchmark run time of 141 minutes, and known Subsurface runtime of 139 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 141u * 60u + 20u, 139u * 60u + 20u));
}
void TestPlan::testVpmbMetric60m30minEan50()
{
struct deco_state *cache = NULL;
setupPrefsVpmb();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
struct diveplan testPlan = {};
setupPlanVpmb60m30minEan50(&testPlan);
setCurrentAppState("PlanDive");
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 155l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check first gas change to EAN50 at 21m
struct event *ev = displayed_dive.dc.events;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 1);
QCOMPARE(ev->value, 50);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 21000);
// check benchmark run time of 95 minutes, and known Subsurface runtime of 96 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 95u * 60u + 20u, 96u * 60u + 20u));
}
void TestPlan::testVpmbMetric60m30minTx()
{
struct deco_state *cache = NULL;
setupPrefsVpmb();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
struct diveplan testPlan = {};
setupPlanVpmb60m30minTx(&testPlan);
setCurrentAppState("PlanDive");
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 159l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check first gas change to EAN50 at 21m
struct event *ev = displayed_dive.dc.events;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 1);
QCOMPARE(ev->value, 50);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 21000);
// check benchmark run time of 89 minutes, and known Subsurface runtime of 89 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 89u * 60u + 20u, 89u * 60u + 20u));
}
void TestPlan::testVpmbMetric100m60min()
{
struct deco_state *cache = NULL;
setupPrefsVpmb();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
struct diveplan testPlan = {};
setupPlanVpmb100m60min(&testPlan);
setCurrentAppState("PlanDive");
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 157l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check first gas change to EAN50 at 21m
struct event *ev = displayed_dive.dc.events;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 1);
QCOMPARE(ev->value, 50);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 21000);
// check second gas change to Oxygen at 6m
ev = ev->next;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 2);
QCOMPARE(ev->value, 100);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 6000);
// check benchmark run time of 311 minutes, and known Subsurface runtime of 314 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 311u * 60u + 20u, 315u * 60u + 20u));
}
void TestPlan::testVpmbMetricMultiLevelAir()
{
struct deco_state *cache = NULL;
setupPrefsVpmb();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
struct diveplan testPlan = {};
setupPlanVpmbMultiLevelAir(&testPlan);
setCurrentAppState("PlanDive");
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 101l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check benchmark run time of 167 minutes, and known Subsurface runtime of 169 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 167u * 60u + 20u, 169u * 60u + 20u));
}
void TestPlan::testVpmbMetric100m10min()
{
struct deco_state *cache = NULL;
setupPrefsVpmb();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
struct diveplan testPlan = {};
setupPlanVpmb100m10min(&testPlan);
setCurrentAppState("PlanDive");
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 175l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check first gas change to EAN50 at 21m
struct event *ev = displayed_dive.dc.events;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 1);
QCOMPARE(ev->value, 50);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 21000);
// check second gas change to Oxygen at 6m
ev = ev->next;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 2);
QCOMPARE(ev->value, 100);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 6000);
// check benchmark run time of 58 minutes, and known Subsurface runtime of 57 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 58u * 60u + 20u, 57u * 60u + 20u));
}
/* This tests that a previously calculated plan isn't affecting the calculations of the next plan.
* It is NOT a 'repetitive dive' test (i.e. with a surface interval and considering tissue
* saturation from the previous dive).
*/
void TestPlan::testVpmbMetricRepeat()
{
struct deco_state *cache = NULL;
setupPrefsVpmb();
prefs.unit_system = METRIC;
prefs.units.length = units::METERS;
struct diveplan testPlan = {};
setupPlanVpmb30m20min(&testPlan);
setCurrentAppState("PlanDive");
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
struct divedatapoint *dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 61l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check benchmark run time of 27 minutes, and known Subsurface runtime of 28 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 27u * 60u + 20u, 27u * 60u + 20u));
int firstDiveRunTimeSeconds = displayed_dive.dc.duration.seconds;
setupPlanVpmb100mTo70m30min(&testPlan);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 80l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check first gas change to 21/35 at 66m
struct event *ev = displayed_dive.dc.events;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 1);
QCOMPARE(ev->gas.mix.o2.permille, 210);
QCOMPARE(ev->gas.mix.he.permille, 350);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 66000);
// check second gas change to EAN50 at 21m
ev = ev->next;
QCOMPARE(ev->gas.index, 2);
QCOMPARE(ev->value, 50);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 21000);
// check third gas change to Oxygen at 6m
ev = ev->next;
QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 3);
QCOMPARE(ev->value, 100);
QCOMPARE(get_depth_at_time(&displayed_dive.dc, ev->time.seconds), 6000);
// we don't have a benchmark, known Subsurface runtime is 126 minutes
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 127u * 60u + 20u, 127u * 60u + 20u));
setupPlanVpmb30m20min(&testPlan);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
#if DEBUG
free(displayed_dive.notes);
displayed_dive.notes = NULL;
save_dive(stdout, &displayed_dive);
#endif
// check minimum gas result
dp = testPlan.dp;
while (!dp->minimum_gas.mbar && dp->next)
dp = dp->next;
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 61l);
// print first ceiling
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
// check runtime is exactly the same as the first time
int finalDiveRunTimeSeconds = displayed_dive.dc.duration.seconds;
QCOMPARE(finalDiveRunTimeSeconds, firstDiveRunTimeSeconds);
}
QTEST_GUILESS_MAIN(TestPlan)
|