Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
c6059ab9
Commit
c6059ab9
authored
Apr 15, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests
parent
f79d3f9a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
3 deletions
+45
-3
mirai-core-qqandroid/build.gradle.kts
mirai-core-qqandroid/build.gradle.kts
+3
-2
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/AtomicResizeCacheList.kt
.../net/mamoe/mirai/qqandroid/utils/AtomicResizeCacheList.kt
+1
-1
mirai-core-qqandroid/src/jvmTest/kotlin/net/mamoe/mirai/qqandroid/utils/AtomicResizeCacheListTest.kt
.../mamoe/mirai/qqandroid/utils/AtomicResizeCacheListTest.kt
+41
-0
No files found.
mirai-core-qqandroid/build.gradle.kts
View file @
c6059ab9
...
...
@@ -46,7 +46,7 @@ kotlin {
}
}
commonMain
{
val
commonMain
by
getting
{
dependencies
{
api
(
kotlin
(
"stdlib"
,
Versions
.
Kotlin
.
stdlib
))
api
(
kotlinx
(
"serialization-runtime-common"
,
Versions
.
Kotlin
.
serialization
))
...
...
@@ -58,7 +58,7 @@ kotlin {
}
}
commonTest
{
val
commonTest
by
getting
{
dependencies
{
implementation
(
kotlin
(
"test-annotations-common"
))
implementation
(
kotlin
(
"test-common"
))
...
...
@@ -94,6 +94,7 @@ kotlin {
val
jvmTest
by
getting
{
dependencies
{
dependsOn
(
commonTest
)
implementation
(
kotlin
(
"test"
,
Versions
.
Kotlin
.
stdlib
))
implementation
(
kotlin
(
"test-junit"
,
Versions
.
Kotlin
.
stdlib
))
implementation
(
"org.pcap4j:pcap4j-distribution:1.8.2"
)
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/AtomicResizeCacheList.kt
View file @
c6059ab9
...
...
@@ -73,7 +73,7 @@ internal class AtomicResizeCacheList<E>(private val retention: Long) {
* No concurrency guaranteed on same [element]
*/
private
fun
removeDuplication
(
element
:
E
):
Boolean
{
val
duplicate
=
list
.
firstOrNull
{
it
.
element
==
element
}
?:
return
false
val
duplicate
=
list
.
firstOrNull
{
it
.
time
.
value
!=
0L
&&
it
.
element
==
element
}
?:
return
false
duplicate
.
time
.
value
=
0
return
true
}
...
...
mirai-core-qqandroid/src/jvmTest/kotlin/net/mamoe/mirai/qqandroid/utils/AtomicResizeCacheListTest.kt
0 → 100644
View file @
c6059ab9
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.qqandroid.utils
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.runBlocking
import
kotlin.test.Test
import
kotlin.test.assertFalse
import
kotlin.test.assertTrue
internal
class
AtomicResizeCacheListTest
{
@Test
fun
testDuplication
()
{
val
list
=
AtomicResizeCacheList
<
Int
>(
1000
)
assertTrue
{
list
.
ensureNoDuplication
(
1
)
}
assertFalse
{
list
.
ensureNoDuplication
(
1
)
}
assertTrue
{
list
.
ensureNoDuplication
(
1
)
}
}
@Test
fun
testRetention
()
{
val
list
=
AtomicResizeCacheList
<
Int
>(
1000
)
assertTrue
{
list
.
ensureNoDuplication
(
1
)
}
runBlocking
{
delay
(
1001
)
// because no concurrency guaranteed on same elements
assertFalse
{
list
.
ensureNoDuplication
(
1
)
}
assertTrue
{
list
.
ensureNoDuplication
(
2
)
}
// outdated elements are now cleaned
assertTrue
{
list
.
ensureNoDuplication
(
1
)
}
}
}
}
\ No newline at end of file
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