Skip to content

Commit

Permalink
增加单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteReimu committed Sep 27, 2024
1 parent 1de7b43 commit c4fa257
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repositories {
}

dependencies {
testImplementation("junit:junit:4.9")
implementation("com.typesafe.akka:akka-actor_2.13:2.8.5")
implementation("io.netty:netty-all:4.1.108.Final")
implementation("io.ktor:ktor-server-netty:2.3.10")
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/Statistics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,11 @@ object Statistics {
playerInfoMap.keys.forEach {
playerInfoMap.computeIfPresent(it) { _, v ->
if (v.score <= 1) return@computeIfPresent null
val newTitle = v.title + getSeasonTitleByScore(v.maxScore)
v.copy(
winCount = 0,
gameCount = 0,
title = v.title + getSeasonTitleByScore(v.maxScore),
title = sortTitles(newTitle),
score = v.score / 2,
energy = v.energy.coerceAtLeast(10),
maxScore = v.score / 2,
Expand Down Expand Up @@ -357,14 +358,13 @@ object Statistics {
private fun savePlayerInfo() {
val sb = StringBuilder()
for ((_, info) in playerInfoMap) {
val sortedTitles = sortTitles(info.title)
sb.append(info.winCount).append(',')
sb.append(info.gameCount).append(',')
sb.append(info.name).append(',')
sb.append(info.score).append(',')
sb.append(info.password).append(',')
sb.append(info.forbidUntil).append(',')
sb.append(sortedTitles).append(',')
sb.append(info.title).append(',')
sb.append(info.lastTime).append(',')
sb.append(info.energy).append(',')
sb.append(info.maxScore).append(',')
Expand Down
12 changes: 12 additions & 0 deletions src/test/kotlin/Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fengsheng

import org.junit.Assert.assertEquals
import org.junit.Test

class Test {
@Test
fun test() {
val s = Statistics.sortTitles("💎👑🏅👑🏅💍💎🏅💎")
assertEquals("👑👑💎💎💎💍🏅🏅🏅", s)
}
}

0 comments on commit c4fa257

Please sign in to comment.