Jpp 19.3.0
the software that should make you happy
Loading...
Searching...
No Matches
parser.t.cc File Reference
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>
#include "parser.h"
#include <sstream>
#include <fstream>

Go to the source code of this file.

Functions

 TEST_CASE ("samples string separated by single spaces should not fail", "[parseWaveformSamples]")
 
 TEST_CASE ("samples string separated by multiple spaces should not fail", "[parseWaveformSamples]")
 
 TEST_CASE ("waveform id can be negative", "[parseWaveformSamples]")
 
 TEST_CASE ("if the waveform id is not an integer return std::nullopt", "[parseWaveformSamples]")
 
 TEST_CASE ("if the number of samples is not an integer return std::nullopt", "[parseWaveformSamples]")
 
 TEST_CASE ("an empty dom config should return std::nullopt", "[parseDOMConfiguration]")
 
 TEST_CASE ("an invalid dom config should return std::nullopt", "[parseDOMConfiguration]")
 
 TEST_CASE ("a valid dom config should not return std::nullopt", "[parseDOMConfiguration]")
 
 TEST_CASE ("check valid dom config", "[parseDOMConfiguration]")
 

Variables

const Waveform< float > expected
 
const Waveform< float > expected_negative
 
std::string valid_dom_config = "813536729 5 27 2000 -28 3001 34 4002 35 5003 48 6004 42"
 

Function Documentation

◆ TEST_CASE() [1/9]

TEST_CASE ( "samples string separated by single spaces should not fail" ,
"" [parseWaveformSamples] )

Definition at line 13 of file parser.t.cc.

14{
15 auto result = parseWaveformSamples<float>("14 3 1.1 2.2 3.3");
16
17 REQUIRE(result.value() == expected);
18}
std::optional< Waveform< T > > parseWaveformSamples(const std::string &adf_waveform_line)
Definition parser.cc:46
const Waveform< float > expected
Definition parser.t.cc:7

◆ TEST_CASE() [2/9]

TEST_CASE ( "samples string separated by multiple spaces should not fail" ,
"" [parseWaveformSamples] )

Definition at line 20 of file parser.t.cc.

21{
22 auto result = parseWaveformSamples<float>("14 3 1.1 2.2 3.3");
23
24 REQUIRE(result.value() == expected);
25}

◆ TEST_CASE() [3/9]

TEST_CASE ( "waveform id can be negative" ,
"" [parseWaveformSamples] )

Definition at line 27 of file parser.t.cc.

28{
29 auto result = parseWaveformSamples<float>("-14 3 1.1 2.2 3.3");
30
31 REQUIRE(result.value() == expected_negative);
32}
const Waveform< float > expected_negative
Definition parser.t.cc:10

◆ TEST_CASE() [4/9]

TEST_CASE ( "if the waveform id is not an integer return std::nullopt" ,
"" [parseWaveformSamples] )

Definition at line 35 of file parser.t.cc.

36{
37 auto result = parseWaveformSamples<float>("1.1 2.2 3.3");
38
39 REQUIRE(result == std::nullopt);
40}

◆ TEST_CASE() [5/9]

TEST_CASE ( "if the number of samples is not an integer return std::nullopt" ,
"" [parseWaveformSamples] )

Definition at line 42 of file parser.t.cc.

43{
44 auto result = parseWaveformSamples<float>("3 1.1 2.2 3.3");
45
46 REQUIRE(result == std::nullopt);
47}

◆ TEST_CASE() [6/9]

TEST_CASE ( "an empty dom config should return std::nullopt" ,
"" [parseDOMConfiguration] )

Definition at line 49 of file parser.t.cc.

50{
51 auto config = parseDOMConfiguration("");
52 REQUIRE(config == std::nullopt);
53}
std::optional< DOMConfig > parseDOMConfiguration(const std::string &dom_configuration_line)
Parse a line that should contain the ADF configuration for a single DOM.
Definition parser.cc:102

◆ TEST_CASE() [7/9]

TEST_CASE ( "an invalid dom config should return std::nullopt" ,
"" [parseDOMConfiguration] )

Definition at line 55 of file parser.t.cc.

56{
57 // missing all but dom_id
58 REQUIRE(parseDOMConfiguration("8102") == std::nullopt);
59 // missing all but dom_id and number of probes
60 REQUIRE(parseDOMConfiguration("8102 2") == std::nullopt);
61 // number of probes cannot be 0
62 REQUIRE(parseDOMConfiguration("8102 0") == std::nullopt);
63 // announcing two probes but only half of one is present
64 REQUIRE(parseDOMConfiguration("8102 2 3") == std::nullopt);
65 // correct number of probes but missing last number = debug_write flag
66 REQUIRE(parseDOMConfiguration("8102 2 28 2000 29 2000") == std::nullopt);
67 // trailing stuff at the end
68 REQUIRE(parseDOMConfiguration("8102 2 28 2000 29 2000 1 oups") == std::nullopt);
69}

◆ TEST_CASE() [8/9]

TEST_CASE ( "a valid dom config should not return std::nullopt" ,
"" [parseDOMConfiguration] )

Definition at line 73 of file parser.t.cc.

74{
76 REQUIRE(config != std::nullopt);
77}
std::string valid_dom_config
Definition parser.t.cc:71

◆ TEST_CASE() [9/9]

TEST_CASE ( "check valid dom config" ,
"" [parseDOMConfiguration] )

Definition at line 79 of file parser.t.cc.

80{
82 REQUIRE(config.has_value() == true);
83
84 const auto [dom_id, probe_configs, write_to_debug_flag] = config.value();
85
86 REQUIRE(dom_id == 813536729);
87 REQUIRE(probe_configs.size() == 5);
88 REQUIRE(probe_configs[0].id == 27);
89 REQUIRE(probe_configs[1].id == -28);
90 REQUIRE(probe_configs[2].id == 34);
91 REQUIRE(probe_configs[3].id == 35);
92 REQUIRE(probe_configs[4].id == 48);
93 REQUIRE(probe_configs[0].threshold == 2000);
94 REQUIRE(probe_configs[1].threshold == 3001);
95 REQUIRE(probe_configs[2].threshold == 4002);
96 REQUIRE(probe_configs[3].threshold == 5003);
97 REQUIRE(probe_configs[4].threshold == 6004);
98 REQUIRE(write_to_debug_flag == 42);
99}
uint32_t dom_id(frame_idx_t idx)

Variable Documentation

◆ expected

const Waveform<float> expected
Initial value:
{
14, {1.1F, 2.2F, 3.3F}}

Definition at line 7 of file parser.t.cc.

7 {
814, {1.1F, 2.2F, 3.3F}};

◆ expected_negative

const Waveform<float> expected_negative
Initial value:
{
-14, {1.1F, 2.2F, 3.3F}}

Definition at line 10 of file parser.t.cc.

10 {
11-14, {1.1F, 2.2F, 3.3F}};

◆ valid_dom_config

std::string valid_dom_config = "813536729 5 27 2000 -28 3001 34 4002 35 5003 48 6004 42"

Definition at line 71 of file parser.t.cc.