Browse Source

Avoid hard-coded number and update the related test.

pull/1224/head
Benoit Marty 1 year ago committed by Benoit Marty
parent
commit
ff77fca34d
  1. 2
      libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/colors/AvatarColors.kt
  2. 7
      libraries/designsystem/src/test/kotlin/io/element/android/libraries/designsystem/colors/AvatarColorsTest.kt

2
libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/colors/AvatarColors.kt

@ -42,6 +42,6 @@ fun avatarColors(userId: String): AvatarColors { @@ -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
}

7
libraries/designsystem/src/test/kotlin/io/element/android/libraries/designsystem/colors/AvatarColorsTest.kt

@ -24,11 +24,8 @@ import org.junit.Test @@ -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

Loading…
Cancel
Save