app/src/test/kotlin/com/honjimaku/subrep/HallucinationsTest.kt (3418 bytes)
1 package com.honjimaku.subrep 2 3 import io.kotest.property.Arb 4 import io.kotest.property.arbitrary.int 5 import io.kotest.property.arbitrary.string 6 import io.kotest.property.checkAll 7 import kotlinx.coroutines.runBlocking 8 import org.junit.Assert.assertEquals 9 import org.junit.Assert.assertFalse 10 import org.junit.Assert.assertTrue 11 import org.junit.Test 12 13 class HallucinationsTest { 14 15 @Test 16 fun aLoopIsCutToThreeOfItsPiece() { 17 assertEquals("Ну конечно, о-о-о- О чаша!", Hallucinations.collapse("Ну конечно, о-о-о-о-о-о-о-о-о-о-о-о-о- О чаша!")) 18 assertEquals("はいはいはい", Hallucinations.collapse("はいはいはいはいはいはいはい")) 19 assertEquals("no, no, no, no", Hallucinations.collapse("no, no, no, no")) 20 assertEquals("Все голоса у всех певцов одинаково мерзкие.", Hallucinations.collapse("Все голоса у всех певцов одинаково мерзкие.")) 21 } 22 23 /** A loop of a long piece (a phrase) is cut to one of its piece. Seen live on Android 11 with `base`, Japanese. */ 24 @Test 25 fun aLoopOfAPhraseIsCutToOneOfItsPiece() { 26 assertEquals( 27 "もうそこからはそこからは意識はうねり混ざり合うあかりと暗がりのうぞの中に暗が", 28 Hallucinations.collapse("もうそこからはそこからは意識はうねり混ざり合うあかりと暗がりのうぞの中に暗がりのうぞの中に暗がりのうぞの中に暗がりのうぞの中に暗がりのうぞの中に暗がりのうぞの中に暗が"), 29 ) 30 assertEquals("I don't know, so", Hallucinations.collapse("I don't know, I don't know, I don't know, I don't know, I don't know, so")) 31 } 32 33 /** A collapse leaves a line without a loop as it is, and a second collapse changes nothing. */ 34 @Test 35 fun aCollapseNeverGrowsAndIsDoneOnce(): Unit = runBlocking { 36 checkAll(Arb.string(0..40), Arb.string(1..4), Arb.int(0..30)) { text, piece, times -> 37 val loud = text + piece.repeat(times) 38 val once = Hallucinations.collapse(loud) 39 assertTrue(once.length <= loud.length) 40 assertEquals(once, Hallucinations.collapse(once)) 41 } 42 } 43 44 @Test 45 fun theCreditsThatWhisperInventsAreDropped() { 46 for (line in listOf( 47 "ご視聴ありがとうございました", 48 "チャンネル登録お願いします", 49 "字幕", 50 "Субтитры сделал DimaTorzok", 51 "Продолжение следует...", 52 "Thanks for watching!", 53 "Thank you.", 54 "Subtitles by the Amara.org community", 55 "Tekstitys: Yle", 56 "...", 57 "♪", 58 "", 59 )) { 60 assertTrue(line, Hallucinations.isHallucination(line)) 61 } 62 } 63 64 @Test 65 fun speechIsKept() { 66 for (line in listOf( 67 "女のいない男たちは、東京で暮らしている。", 68 "Нет ничего спиртного. Царицы небесные!", 69 "Thank you for the coffee, it was good.", 70 "Kiitos, että tulit tänne tänään.", 71 "The boy said: please subscribe to the newspaper.", 72 )) { 73 assertFalse(line, Hallucinations.isHallucination(line)) 74 } 75 } 76 }