1414 * limitations under the License.
1515 */
1616
17- package com.google.firebase.dataconnect
17+ package com.google.firebase.dataconnect.util
1818
1919import com.google.firebase.dataconnect.util.AlphanumericStringUtil.toAlphaNumericString
2020import io.kotest.matchers.shouldBe
21+ import io.kotest.property.Arb
22+ import io.kotest.property.arbitrary.byte
23+ import io.kotest.property.arbitrary.byteArray
24+ import io.kotest.property.arbitrary.int
25+ import io.kotest.property.checkAll
26+ import kotlinx.coroutines.test.runTest
2127import org.junit.Test
2228
23- class UtilUnitTest {
29+ class AlphanumericStringUtilUnitTest {
2430
2531 @Test
26- fun `ByteArray toAlphaNumericString() interprets the alphabet` () {
32+ fun `toAlphaNumericString() interprets the alphabet` () {
2733 val byteArray =
2834 byteArrayOf(
2935 0 ,
@@ -52,13 +58,13 @@ class UtilUnitTest {
5258 }
5359
5460 @Test
55- fun `ByteArray toAlphaNumericString() where the final 5-bit chunk is 1 bit` () {
61+ fun `toAlphaNumericString() where the final 5-bit chunk is 1 bit` () {
5662 byteArrayOf(75 , 50 ).let { it.toAlphaNumericString() shouldBe " bet2" }
5763 byteArrayOf(75 , 51 ).let { it.toAlphaNumericString() shouldBe " bet3" }
5864 }
5965
6066 @Test
61- fun `ByteArray toAlphaNumericString() where the final 5-bit chunk is 2 bits` () {
67+ fun `toAlphaNumericString() where the final 5-bit chunk is 2 bits` () {
6268 byteArrayOf(117 , - 40 , - 116 , - 66 , - 105 , - 61 , 18 , - 117 , - 52 ).let {
6369 it.toAlphaNumericString() shouldBe " greathorsebarn2"
6470 }
@@ -68,61 +74,61 @@ class UtilUnitTest {
6874 }
6975
7076 @Test
71- fun `ByteArray toAlphaNumericString() where the final 5-bit chunk is 3 bits` () {
77+ fun `toAlphaNumericString() where the final 5-bit chunk is 3 bits` () {
7278 byteArrayOf(64 ).let { it.toAlphaNumericString() shouldBe " a2" }
7379 byteArrayOf(71 ).let { it.toAlphaNumericString() shouldBe " a9" }
7480 }
7581
7682 @Test
77- fun `ByteArray toAlphaNumericString() where the final 5-bit chunk is 4 bits` () {
83+ fun `toAlphaNumericString() where the final 5-bit chunk is 4 bits` () {
7884 byteArrayOf(- 58 , 117 , 48 ).let { it.toAlphaNumericString() shouldBe " stun2" }
7985 byteArrayOf(- 58 , 117 , 63 ).let { it.toAlphaNumericString() shouldBe " stunh" }
8086 }
8187
8288 @Test
83- fun `ByteArray toAlphaNumericString() on empty byte array` () {
89+ fun `toAlphaNumericString() on empty byte array` () {
8490 val emptyByteArray = byteArrayOf()
8591 emptyByteArray.toAlphaNumericString() shouldBe " "
8692 }
8793
8894 @Test
89- fun `ByteArray toAlphaNumericString() on byte array with 1 element of value 0` () {
95+ fun `toAlphaNumericString() on byte array with 1 element of value 0` () {
9096 val byteArray = byteArrayOf(0 )
9197 byteArray.toAlphaNumericString() shouldBe " 22"
9298 }
9399
94100 @Test
95- fun `ByteArray toAlphaNumericString() on byte array with 1 element of value 1` () {
101+ fun `toAlphaNumericString() on byte array with 1 element of value 1` () {
96102 val byteArray = byteArrayOf(1 )
97103 byteArray.toAlphaNumericString() shouldBe " 23"
98104 }
99105
100106 @Test
101- fun `ByteArray toAlphaNumericString() on byte array with 1 element of value 0xff` () {
107+ fun `toAlphaNumericString() on byte array with 1 element of value 0xff` () {
102108 val byteArray = byteArrayOf(0xff .toByte())
103109 byteArray.toAlphaNumericString() shouldBe " z9"
104110 }
105111
106112 @Test
107- fun `ByteArray toAlphaNumericString() on byte array with 1 element of value -1` () {
113+ fun `toAlphaNumericString() on byte array with 1 element of value -1` () {
108114 val byteArray = byteArrayOf(- 1 )
109115 byteArray.toAlphaNumericString() shouldBe " z9"
110116 }
111117
112118 @Test
113- fun `ByteArray toAlphaNumericString() on byte array with 1 element of value MIN_VALUE` () {
119+ fun `toAlphaNumericString() on byte array with 1 element of value MIN_VALUE` () {
114120 val byteArray = byteArrayOf(Byte .MIN_VALUE )
115121 byteArray.toAlphaNumericString() shouldBe " j2"
116122 }
117123
118124 @Test
119- fun `ByteArray toAlphaNumericString() on byte array with 1 element of value MAX_VALUE` () {
125+ fun `toAlphaNumericString() on byte array with 1 element of value MAX_VALUE` () {
120126 val byteArray = byteArrayOf(Byte .MAX_VALUE )
121127 byteArray.toAlphaNumericString() shouldBe " h9"
122128 }
123129
124130 @Test
125- fun `ByteArray toAlphaNumericString() on byte array containing all possible values` () {
131+ fun `toAlphaNumericString() on byte array containing all possible values` () {
126132 val byteArray =
127133 buildList {
128134 for (i in 0 until 512 ) {
@@ -142,6 +148,12 @@ class UtilUnitTest {
142148 " rv3efmqguddfprr4wvpgxwrqzdzj83sd3wbkg8sz6enmqdtn8wxnyju9bf9p8puvdxkqguvhgfvrqzw5jy7sz6" +
143149 " wrnghu9bxdpytvhgxzsh5wrnynuzfxzsz9xhrz9xzvz3"
144150 }
151+
152+ @Test
153+ fun `toAlphaNumericString() with random byte arrays` () = runTest {
154+ val byteArrayArb = Arb .byteArray(length = Arb .int(0 , 100 ), content = Arb .byte())
155+ checkAll(100_000 , byteArrayArb) { byteArray -> byteArray.toAlphaNumericString() }
156+ }
145157}
146158
147159/*
0 commit comments