From e03bd3f80333a3bb69bb77b64bc818047357ea5b Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 26 Sep 2024 08:45:13 +0300 Subject: [PATCH] io: make buffered_writer_test.v more robust --- vlib/io/buffered_writer_test.v | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vlib/io/buffered_writer_test.v b/vlib/io/buffered_writer_test.v index 78eca87c27..3d7d1daa55 100644 --- a/vlib/io/buffered_writer_test.v +++ b/vlib/io/buffered_writer_test.v @@ -1,6 +1,10 @@ import io import rand +fn small_amount() int { + return int(rand.u8()) + 1 +} + struct ArrayWriter { pub mut: result []u8 @@ -56,7 +60,7 @@ fn test_write() { written := write_random_data(mut aw, mut bw, 65536)! // now exceed buffer capacity by a little - little := rand.u8() + little := small_amount() excess := bw.available() + little excess_data := rand.bytes(excess)! w := bw.write(excess_data)! @@ -70,7 +74,7 @@ fn test_write_big() { max := 65536 mut bw := io.new_buffered_writer(writer: aw, cap: max)! - more_than_max := max + rand.u8() + more_than_max := max + small_amount() big_source := rand.bytes(more_than_max)! w := bw.write(big_source)! assert w == more_than_max