Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Prog2
/
ell_feladat
/
CppMonoton
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2ea71faa
authored
May 09, 2019
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
intervallum check
parent
04062a97
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
3 deletions
+43
-3
monoton_test.cpp
+43
-3
No files found.
monoton_test.cpp
View file @
2ea71faa
...
...
@@ -70,6 +70,29 @@ void sigSegv(int signal) {
throw
std
::
out_of_range
(
"Illegalis memoria muvelet: Valoszinu, hogy lefutott az iterator a tarolorol!"
);
}
/// Olyan osztály, ami képes jelezni, ha írják, vagy olvassák.
/// Ezzel ellenőrizzük, hogy a megadott intervallum határain belül marad-e.
class
isAccessed
{
int
flg
;
void
read
()
const
{
throw
std
::
out_of_range
(
"Nem letezo elem olvasasa!"
);
}
void
write
()
const
{
throw
std
::
out_of_range
(
"Nem letezo elem irasa!"
);
}
public
:
static
const
int
R
=
1
;
// olvasáskor jelez
static
const
int
W
=
2
;
// íráskor jelez
isAccessed
(
int
f
=
0
)
:
flg
(
f
)
{}
// másoló olvasást jelent
isAccessed
(
const
isAccessed
&
a
)
:
flg
(
a
.
flg
)
{
if
(
flg
&
R
)
read
();
}
// op= írást jelent
isAccessed
&
operator
=
(
const
isAccessed
&
a
)
{
if
(
flg
&
W
)
write
();
flg
=
a
.
flg
;
return
*
this
;
}
};
int
main
()
{
GTINIT
(
std
::
cin
);
// Csak C(J)PORTA működéséhez kell
...
...
@@ -78,7 +101,7 @@ int main() {
std
::
signal
(
SIGSEGV
,
sigSegv
);
/// Signal handler beállítása
/// Üres halmazra szinte minden halmaztulajdonság igaz.
TEST
(
Test1
,
Sanity
)
{
TEST
(
Test1
,
Sanity
1
)
{
const
char
*
p
=
"duma"
;
EXPECT_TRUE
(
monoton
(
p
,
p
,
std
::
greater
<
char
>
()))
<<
make_pair
(
p
,
p
);
/// hiba esetén kiírjuk az intervallumot
...
...
@@ -87,7 +110,24 @@ int main() {
EXPECT_TRUE
(
monoton
(
p
,
p
,
std
::
less_equal
<
char
>
()))
<<
make_pair
(
p
,
p
);
EXPECT_TRUE
(
monoton
(
p
,
p
,
const_pred
<
char
>
()))
<<
"A tulfutast teszteli"
<<
endl
;
EXPECT_TRUE
(
monoton
(
p
,
p
,
const_pred
<
char
>
(
false
)))
<<
"A tulfutast teszteli"
<<
endl
;
}
END
isAccessed
a
[
4
];
TEST
(
Test1
,
Sanity2
)
{
a
[
0
]
=
isAccessed
::
R
|
isAccessed
::
W
;
a
[
3
]
=
isAccessed
::
R
|
isAccessed
::
W
;
EXPECT_TRUE
(
monoton
(
&
a
[
1
],
&
a
[
3
],
const_pred
<
isAccessed
>
()))
<<
"A tulfutast es a hozzaferest teszteli"
<<
endl
;
EXPECT_FALSE
(
monoton
(
&
a
[
1
],
&
a
[
3
],
const_pred
<
isAccessed
>
(
false
)))
<<
"A tulfutast es a hozzaferest teszteli"
<<
endl
;
}
END
TEST
(
Test1
,
Sanity3
)
{
a
[
2
]
=
isAccessed
::
R
|
isAccessed
::
W
;
EXPECT_TRUE
(
monoton
(
&
a
[
1
],
&
a
[
2
],
const_pred
<
isAccessed
>
()))
<<
"A tulfutast es a hozzaferest teszteli"
<<
endl
;
}
END
TEST
(
Test1
,
Sanity4
)
{
a
[
1
]
=
isAccessed
::
R
|
isAccessed
::
W
;
EXPECT_TRUE
(
monoton
(
&
a
[
1
],
&
a
[
1
],
const_pred
<
isAccessed
>
()))
<<
"A tulfutast es a hozzaferest teszteli"
<<
endl
;
}
END
/// counting_iterator int típussal
...
...
@@ -230,7 +270,7 @@ int main() {
// és elrontjuk a rendezettséget
l
.
insert
(
l
.
end
(),
s
.
rbegin
(),
s
.
rend
());
EXPECT_FALSE
(
monoton
(
l
.
begin
(),
l
.
end
(),
std
::
greater
<
double
>
()))
<<
make_pair
(
l
.
begin
(),
l
.
end
());
EXPECT_FALSE
(
monoton
(
l
.
begin
(),
l
.
end
(),
std
::
less
<
double
>
()))
<<
make_pair
(
l
.
rbegin
(),
l
.
r
end
());
EXPECT_FALSE
(
monoton
(
l
.
begin
(),
l
.
end
(),
std
::
less
<
double
>
()))
<<
make_pair
(
l
.
begin
(),
l
.
end
());
EXPECT_TRUE
(
monoton
(
l
.
rbegin
(),
l
.
rend
(),
const_pred
<
double
>
()))
<<
"A tulfutast teszteli"
<<
endl
;
EXPECT_FALSE
(
monoton
(
l
.
rbegin
(),
l
.
rend
(),
const_pred
<
double
>
(
false
)))
<<
"A tulfutast teszteli"
<<
endl
;
EXPECT_TRUE
(
monoton
(
l
.
begin
(),
l
.
end
(),
const_pred
<
double
>
()))
<<
"A tulfutast teszteli"
<<
endl
;
...
...
@@ -247,7 +287,7 @@ int main() {
cout
<<
endl
;
EXPECT_TRUE
(
monoton
(
s
.
begin
(),
s
.
end
(),
std
::
greater
<
std
::
string
>
()))
<<
make_pair
(
s
.
begin
(),
s
.
end
());
EXPECT_FALSE
(
monoton
(
s
.
rbegin
(),
s
.
rend
(),
std
::
greater
<
std
::
string
>
()))
<<
make_pair
(
s
.
begin
(),
s
.
end
());
EXPECT_FALSE
(
monoton
(
s
.
rbegin
(),
s
.
rend
(),
std
::
greater
<
std
::
string
>
()))
<<
make_pair
(
s
.
rbegin
(),
s
.
r
end
());
EXPECT_TRUE
(
monoton
(
s
.
rbegin
(),
s
.
rend
(),
const_pred
<
std
::
string
>
()))
<<
"A tulfutast teszteli"
<<
endl
;
EXPECT_FALSE
(
monoton
(
s
.
rbegin
(),
s
.
rend
(),
const_pred
<
std
::
string
>
(
false
)))
<<
"A tulfutast teszteli"
<<
endl
;
EXPECT_TRUE
(
monoton
(
s
.
begin
(),
s
.
end
(),
const_pred
<
std
::
string
>
()))
<<
"A tulfutast teszteli"
<<
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment