@@ -13,6 +13,7 @@ import org.scalatest.matchers.should
1313import org .scalatest .wordspec .AnyWordSpec
1414
1515import scala .language .implicitConversions
16+ import scala .util .Random
1617
1718class Blake3Test extends AnyWordSpec with should.Matchers {
1819 " Very naive test" in {
@@ -221,4 +222,36 @@ class Blake3Test extends AnyWordSpec with should.Matchers {
221222 len -= CHUNK_LEN
222223 }
223224 }
225+
226+ " Chunking data" when {
227+ " 63 bytes" in {
228+ val bytes = new Array [Byte ](63 )
229+ Random .nextBytes(bytes)
230+ val hasher1 = Blake3 .newHasher()
231+ hasher1.update(bytes)
232+ val expected = hasher1.doneHex(16 )
233+
234+ val hasher2 = Blake3 .newHasher()
235+ hasher2.update(bytes, 0 , 32 )
236+ hasher2.update(bytes, 32 , 31 )
237+ val actual = hasher2.doneHex(16 )
238+
239+ expected shouldBe actual
240+ }
241+
242+ " 64 bytes" in {
243+ val bytes = new Array [Byte ](64 )
244+ Random .nextBytes(bytes)
245+ val hasher1 = Blake3 .newHasher()
246+ hasher1.update(bytes, 0 , 64 )
247+ val expected = hasher1.doneHex(16 )
248+
249+ val hasher2 = Blake3 .newHasher()
250+ hasher2.update(bytes, 0 , 32 )
251+ hasher2.update(bytes, 32 , 32 )
252+ val actual = hasher2.doneHex(16 )
253+
254+ expected shouldBe actual
255+ }
256+ }
224257}
0 commit comments