Fixes places for the test and common code

This commit is contained in:
Vitor Pamplona
2026-01-07 11:51:45 -05:00
parent 9014424f0d
commit 806bc2729a
9 changed files with 0 additions and 0 deletions
@@ -0,0 +1,82 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.commons
import com.vitorpamplona.amethyst.commons.blurhash.Base83
import org.junit.Assert.assertEquals
import org.junit.Test
class Base83Test {
@Test
fun testEncodeDecode() {
for (i in 0..820000) {
assertEquals("$i encode decode", i, Base83.decode(Base83.encode(i.toLong())))
}
}
@Test
fun testSingleDigits() {
for (i in 0..82) {
val expected: String = String(Base83.ALPHABET, i, 1)
assertEquals("$i encodes", expected, Base83.encode(i.toLong(), 1))
}
}
@Test
fun test0000() {
assertEquals("0000", Base83.encode(0, 4))
}
@Test
fun test0001() {
assertEquals("0001", Base83.encode(1, 4))
}
@Test
fun test0010() {
assertEquals("0010", Base83.encode(83, 4))
}
@Test
fun test0011() {
assertEquals("0011", Base83.encode(83 + 1, 4))
}
@Test
fun test00X0() {
assertEquals("00~0", Base83.encode(83 * 82, 4))
}
@Test
fun test0100() {
assertEquals("0100", Base83.encode(83 * 83, 4))
}
@Test
fun test00XXEncode() {
assertEquals("00~~", Base83.encode(83 * 82 + 82, 4))
}
@Test
fun test0XXXDecode() {
assertEquals(82 + 82 * 83 + 82 * 83 * 83, Base83.decode("0~~~"))
}
}
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.commons
import com.vitorpamplona.amethyst.commons.blurhash.SRGB
import org.junit.Assert.assertEquals
import org.junit.Test
import kotlin.math.round
class SRGBTest {
@Test
fun testEncodeDecode() {
for (i in 0..255) {
assertEquals("$i encode decode", i, SRGB.linearToSrgb(SRGB.srgbToLinear(i)))
}
for (i in 0..100) {
val srgb = SRGB.linearToSrgb(i / 100.0f)
val linear = round(SRGB.srgbToLinear(srgb) * 100).toInt()
assertEquals("$i decode encode", i, linear)
}
}
}
@@ -0,0 +1,80 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.commons.emojicoder
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class EmojiCoderTest {
companion object {
val EMOJI_LIST = arrayOf("😀", "😂", "🥰", "😎", "🤔", "👍", "👎", "👏", "😅", "🤝", "🎉", "🎂", "🍕", "🌈", "🌞", "🌙", "🔥", "💯", "🚀", "👀", "💀", "🥹")
val testStrings =
arrayOf(
"Hello, World!",
"Testing 123",
"Special chars: !@#$%^&*()",
"Unicode: 你好,世界",
" ",
)
val HELLO_WORLD = "\uD83D\uDE00\uDB40\uDD38\uDB40\uDD55\uDB40\uDD5C\uDB40\uDD5C\uDB40\uDD5F\uDB40\uDD1C\uDB40\uDD10\uDB40\uDD47\uDB40\uDD5F\uDB40\uDD62\uDB40\uDD5C\uDB40\uDD54\uDB40\uDD11"
val HELLO_WORLD_WITH_EXTRAS = HELLO_WORLD + "askfasdf"
}
@Test
fun testIsCoded() {
assertEquals(true, EmojiCoder.isCoded(HELLO_WORLD))
}
@Test
fun testEncode() {
assertEquals(HELLO_WORLD, EmojiCoder.encode("\uD83D\uDE00", "Hello, World!"))
}
@Test
fun testDecode() {
assertEquals("Hello, World!", EmojiCoder.decode(HELLO_WORLD))
}
@Test
fun testCrop() {
assertEquals(HELLO_WORLD, EmojiCoder.cropToFirstMessage(HELLO_WORLD_WITH_EXTRAS))
}
@Test
fun testEncodeDecode() {
for (emoji in EMOJI_LIST) {
for (sentence in testStrings) {
val encoded = EmojiCoder.encode(emoji, sentence)
val decoded = EmojiCoder.decode(encoded)
assertEquals(sentence, decoded)
assertTrue("Failed sentence for emoji $emoji with sentence `$sentence`: `$encoded`", EmojiCoder.isCoded(encoded))
}
}
}
@Test
fun testLinkFromAmethyst() {
assertEquals("https://cdn.satellite.earth/947e4ab2d3115be565a49cf5db02559f310ca0a6ddfddbd4bd8cbec44995c2e7.webp", EmojiCoder.decode("🚀󠅘󠅤󠅤󠅠󠅣󠄪󠄟󠄟󠅓󠅔󠅞󠄞󠅣󠅑󠅤󠅕󠅜󠅜󠅙󠅤󠅕󠄞󠅕󠅑󠅢󠅤󠅘󠄟󠄩󠄤󠄧󠅕󠄤󠅑󠅒󠄢󠅔󠄣󠄡󠄡󠄥󠅒󠅕󠄥󠄦󠄥󠅑󠄤󠄩󠅓󠅖󠄥󠅔󠅒󠄠󠄢󠄥󠄥󠄩󠅖󠄣󠄡󠄠󠅓󠅑󠄠󠅑󠄦󠅔󠅔󠅖󠅔󠅔󠅒󠅔󠄤󠅒󠅔󠄨󠅓󠅒󠅕󠅓󠄤󠄤󠄩󠄩󠄥󠅓󠄢󠅕󠄧󠄞󠅧󠅕󠅒󠅠"))
}
}