Avoid hard-coded number and update the related test.

This commit is contained in:
Benoit Marty
2023-09-05 14:55:53 +02:00
committed by Benoit Marty
parent 9e1c8279b2
commit eb2810e467
2 changed files with 3 additions and 6 deletions

View File

@@ -42,6 +42,6 @@ fun avatarColors(userId: String): AvatarColors {
}
internal fun String.toHash(): Int {
return toList().sumOf { it.code } % 8
return toList().sumOf { it.code } % avatarColorsLight.size
}

View File

@@ -24,11 +24,8 @@ import org.junit.Test
class AvatarColorsTest {
@Test
fun `ensure list size`() {
// avatarColorsDark and avatarColorsLight size must not be modified.
// 8 is used as a hard-coded modulo in `String.toHash()` extension.
assertThat(avatarColorsDark.size).isEqualTo(8)
assertThat(avatarColorsLight.size).isEqualTo(8)
fun `ensure the size of the avatar color are equal for light and dark theme`() {
assertThat(avatarColorsDark.size).isEqualTo(avatarColorsLight.size)
}
@Test