Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112005
util-test.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
util-test.cpp
View Options
/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2021 Tusooa Zhu <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include
<libkazv-config.hpp>
#include
<catch2/catch.hpp>
#include
<clientutil.hpp>
#include
<immer/flex_vector.hpp>
namespace
{
struct
Model
{
int
value
;
std
::
string
data
;
};
bool
operator
==
(
Model
a
,
Model
b
)
{
return
a
.
value
==
b
.
value
&&
a
.
data
==
b
.
data
;
}
bool
operator
!=
(
Model
a
,
Model
b
)
{
return
!
(
a
==
b
);
}
}
using
namespace
Kazv
;
TEST_CASE
(
"sortedUniqueMerge should behave correctly"
,
"[client][clientutil]"
)
{
immer
::
flex_vector
<
Model
>
base
=
{{
50
,
"foo"
},
{
100
,
"bar"
}};
immer
::
flex_vector
<
Model
>
addon
=
{{
1
,
"a"
},
{
2
,
"b"
},
{
70
,
"c"
},
{
110
,
"d"
}};
auto
exists
=
[
base
](
auto
m
)
{
return
std
::
find
(
base
.
begin
(),
base
.
end
(),
m
)
!=
base
.
end
();
};
auto
key
=
[](
auto
m
)
{
return
m
.
value
;
};
auto
res
=
sortedUniqueMerge
(
base
,
addon
,
exists
,
key
);
REQUIRE
(
res
==
immer
::
flex_vector
<
Model
>
{{
1
,
"a"
},
{
2
,
"b"
},
{
50
,
"foo"
},
{
70
,
"c"
},
{
100
,
"bar"
},
{
110
,
"d"
}}
);
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Fri, Nov 22, 9:15 PM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38719
Default Alt Text
util-test.cpp (1 KB)
Attached To
Mode
rL libkazv
Attached
Detach File
Event Timeline
Log In to Comment