Coverage Report: Coaster
File: TicketApp.cpp
show more
show less
Parent Entity
All Files
Source Code Location
C:\Testwell\Samples\Coaster\CoasterCode\TicketApp.cpp
Instrumentation Origin
C:\Testwell\Samples\Coaster\MON.sym
directly instrumented
2024-03-01 10:48:01
MultiCond
MC/DC
42%
27 / 64
Statement
78%
37 / 47
True
Highlight:
All
MC/DC
Statement
False
Source & Details
Show Code:
Outside Functions
Show Coverage Details:
Single Probe Descriptions
Condition Blocks
True-False-Tables
MC/DC Blocks
TicketApp.cpp
All Files
1
#include "TicketApp.h"
2
#include "Kermisvisitor.h"
3
#include <iostream>
4
#include <iomanip>
5
#include <string>
6
#include <ctime>
7
8
using
namespace
std;
9
27
36
44
56
68
87
99
10
void
TicketApp::showInstruction()
1
FUNCTION TicketApp::showInstruction()
11
{
12
system(
"CLS"
);
13
cout <<
"PricingCalculator for Infinity!\n"
;
14
cout <<
"===============================\n\n"
;
15
greetUser();
16
cout <<
"Please enter first name, age and body height of the potential passenger.\n"
;
17
cout <<
"PricingCalculator decides about admission to the rollercoaster\n"
;
18
cout <<
"and if so what the passenger has to pay for a ticket.\n\n"
;
19
20
string selectedDialogueMode;
21
22
cout << endl <<
"Enter 's' to start."
<< endl;
23
cin >> selectedDialogueMode;
24
25
if
(!(selectedDialogueMode ==
"s"
|| selectedDialogueMode ==
"S"
)) { switch2BatchMode(); }
1
0
if (! ( selectedDialogueMode == "s" || selectedDialogueMode == "S" ))
1
1
!(F || F)
0
2
!(T || _)
0
3
!(F || T)
-
MC/DC
selectedDialogueMode == "s":
1, 2
-
MC/DC
selectedDialogueMode == "S":
1, 3
26
}
1
function end
28
void
TicketApp::switch2BatchMode()
1
FUNCTION TicketApp::switch2BatchMode()
29
{
30
system(
"CLS"
);
31
cout <<
"PricingCalculator for Infinity!\n"
;
32
cout <<
"===============================\n\n"
;
33
runInDialogueMode=
false
;
34
cout <<
"--- Results in Batch Mode ---"
<< endl << endl;
35
}
1
function end
37
void
TicketApp::ask4Input(string theQuestion)
16
FUNCTION TicketApp::ask4Input()
38
{
39
if
(runInDialogueMode)
0
16
if (runInDialogueMode)
40
{
41
cout << theQuestion;
42
}
43
}
16
function end
45
void
TicketApp::reportPrice(Kermisvisitor prvPassenger,
int
thePrice)
3
FUNCTION TicketApp::reportPrice()
46
{
47
if
(runInDialogueMode)
0
3
if (runInDialogueMode)
48
{
49
cout << prvPassenger.FirstName +
", the price for your ride is "
+ to_string(thePrice) +
" EUR."
;
50
}
51
else
else
52
{
53
cout <<
"Passenger "
+ prvPassenger.FirstName +
", "
+ to_string(prvPassenger.Age) +
" years old and "
<< setprecision(3) << prvPassenger.BodyHeight <<
" m tall, has to pay "
+ to_string(thePrice) +
" EUR."
;
54
}
55
}
3
function end
57
void
TicketApp::reportRefusal(Kermisvisitor prvPassenger)
1
FUNCTION TicketApp::reportRefusal()
58
{
59
if
(runInDialogueMode)
0
1
if (runInDialogueMode)
60
{
61
cout << prvPassenger.FirstName +
", sorry you can't get access to the rollercoaster :-("
;
62
}
63
else
else
64
{
65
cout << prvPassenger.FirstName +
" ("
+ to_string(prvPassenger.Age) +
"/"
<< setprecision(3) << prvPassenger.BodyHeight <<
" m), sorry you can't get access to the rollercoaster :-("
;
66
}
67
}
1
function end
69
bool
TicketApp::shallProceed()
4
FUNCTION TicketApp::shallProceed()
70
{
71
string anotherPassenger;
72
73
ask4Input(
" --- One more try (y/n)? "
);
74
cin >> anotherPassenger;
75
cout << endl;
76
#pragma CTC ANNOTATION Here one of these conditions is sufficient to test
User annotation: Here one of these conditions is sufficient to test
77
if
(anotherPassenger ==
"j"
|| anotherPassenger ==
"ja"
|| anotherPassenger ==
"y"
|| anotherPassenger ==
"yes"
)
3
1
if (anotherPassenger == "j" || anotherPassenger == "ja" || anotherPassenger == "y" || anotherPassenger == "yes")
3
1
T || _ || _ || _
0
2
F || T || _ || _
0
3
F || F || T || _
0
4
F || F || F || T
1
5
F || F || F || F
+
MC/DC
anotherPassenger == "j":
1, 5
-
MC/DC
anotherPassenger == "ja":
2, 5
-
MC/DC
anotherPassenger == "y":
3, 5
-
MC/DC
anotherPassenger == "yes":
4, 5
78
{
79
#pragma CTC APPEND
80
return
true
;
3
return true
81
}
82
else
else
83
{
84
return
false
;
1
return false
85
}
86
}
function end
88
void
TicketApp::sayGoodBye()
1
FUNCTION TicketApp::sayGoodBye()
89
{
90
if
(runInDialogueMode)
//
CTC++ Justify True
|
Batch Testing
:
This branch is only reachable in dialogue mode; not with batch testing
0
1
if (runInDialogueMode)
91
{
92
cout <<
"Thank you for travelling with Achter-Bahn!"
;
93
}
94
else
else
95
{
96
cout << endl <<
"--- Batch Mode completed! ---"
;
97
}
98
}
1
function end
100
void
TicketApp::greetUser()
1
FUNCTION TicketApp::greetUser()
101
{
102
// Get hour from local time
103
time_t currentTime = time(0);
104
tm *localTime = localtime(¤tTime);
105
int
hour = localTime->tm_hour;
106
107
switch
(hour) {
switch (hour)
108
case
0:
0
case 0:
109
case
1:
0
case 1:
110
case
2:
0
case 2:
111
case
3:
0
case 3:
112
case
4:
0
case 4:
113
case
5:
0
case 5:
114
case
6:
0
case 6:
115
case
7:
0
case 7:
116
case
8:
0
case 8:
117
case
9:
0
case 9:
118
case
10:
1
case 10:
119
case
11:
0
case 11:
120
cout <<
"Good Morning!"
<< endl;
121
break
;
1
break
122
case
12:
0
case 12:
123
case
13:
0
case 13:
124
case
14:
0
case 14:
125
case
15:
0
case 15:
126
case
16:
0
case 16:
127
case
17:
0
case 17:
128
cout <<
"Good Afternoon!"
<< endl;
129
break
;
0
break
130
case
18:
0
case 18:
131
case
19:
0
case 19:
132
case
20:
0
case 20:
133
case
21:
0
case 21:
134
case
22:
0
case 22:
135
case
23:
0
case 23:
136
cout <<
"Good Evening!"
<< endl;
137
break
;
0
break
138
default
:
//
CTC++ Justify
|
Unreachable default
:
Valid hour can not be outside 0 ... 23
0
default:
139
cout <<
"Error: Unable to determine the time of day."
<< endl;
140
break
;
0
break
141
}
142
}
1
function end
Overview
❮❮
❮
All Files
PassengerScan.cpp
PriceCalculation.cpp
Rollercoaster.cpp
TicketApp.cpp
Select File
❯
❯❯