From 4de757cb74a41cab03cbeda3d4148ab046b6cc82 Mon Sep 17 00:00:00 2001 From: Joe Nievelt Date: Mon, 14 Dec 2015 16:14:47 -0800 Subject: [PATCH 1/2] Using dropRight instead of tail for shortening BytesSpec array --- .../src/test/scala/com/twitter/algebird/BytesSpec.scala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/algebird-test/src/test/scala/com/twitter/algebird/BytesSpec.scala b/algebird-test/src/test/scala/com/twitter/algebird/BytesSpec.scala index 7428eea87..62b1e6dcd 100644 --- a/algebird-test/src/test/scala/com/twitter/algebird/BytesSpec.scala +++ b/algebird-test/src/test/scala/com/twitter/algebird/BytesSpec.scala @@ -115,11 +115,9 @@ class BytesSpec extends WordSpec with Matchers with GeneratorDrivenPropertyCheck suffixed should be > bytes1 // 4. a Bytes instances and a "shorter" Bytes instance. - if (bytes1.array.length > 1) { - val shortened = Bytes(bytes1.array.tail) - bytes1 should be > shortened - shortened should be < bytes1 - } + val shortened = Bytes(bytes1.array.dropRight(1)) + bytes1 should be > shortened + shortened should be < bytes1 } } From 69b6c1e085a4d039f41592356d5b9fad1a5a38dc Mon Sep 17 00:00:00 2001 From: Joe Nievelt Date: Tue, 16 Feb 2016 10:28:32 -0800 Subject: [PATCH 2/2] BytesSpec tests empty Arrays --- .../scala/com/twitter/algebird/BytesSpec.scala | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/algebird-test/src/test/scala/com/twitter/algebird/BytesSpec.scala b/algebird-test/src/test/scala/com/twitter/algebird/BytesSpec.scala index 62b1e6dcd..3c203abe5 100644 --- a/algebird-test/src/test/scala/com/twitter/algebird/BytesSpec.scala +++ b/algebird-test/src/test/scala/com/twitter/algebird/BytesSpec.scala @@ -12,7 +12,7 @@ class BytesSpec extends WordSpec with Matchers with GeneratorDrivenPropertyCheck "has a sane equals function" in { val random = new scala.util.Random - forAll((Gen.choose(1, 4096), "wordLength")) { (wordLength: Int) => + forAll((Gen.choose(0, 4096), "wordLength")) { (wordLength: Int) => // Given two different array instances that have the same content. val word = random.nextString(wordLength) val array1 = word.getBytes @@ -63,7 +63,7 @@ class BytesSpec extends WordSpec with Matchers with GeneratorDrivenPropertyCheck "has a sane hashCode function" in { val random = new scala.util.Random - forAll((Gen.choose(1, 4096), "wordLength")) { (wordLength: Int) => + forAll((Gen.choose(0, 4096), "wordLength")) { (wordLength: Int) => // Given two Bytes instances that are equal. val word = random.nextString(wordLength) val array1 = word.getBytes @@ -90,7 +90,7 @@ class BytesSpec extends WordSpec with Matchers with GeneratorDrivenPropertyCheck "provides an Ordering typeclass" in { val random = new scala.util.Random - forAll((Gen.choose(1, 4096), "wordLength")) { (wordLength: Int) => + forAll((Gen.choose(0, 4096), "wordLength")) { (wordLength: Int) => val word = random.nextString(wordLength) val array1 = word.getBytes val array2 = word.getBytes @@ -115,9 +115,11 @@ class BytesSpec extends WordSpec with Matchers with GeneratorDrivenPropertyCheck suffixed should be > bytes1 // 4. a Bytes instances and a "shorter" Bytes instance. - val shortened = Bytes(bytes1.array.dropRight(1)) - bytes1 should be > shortened - shortened should be < bytes1 + if (bytes1.array.length > 0) { + val shortened = Bytes(bytes1.array.dropRight(1)) + bytes1 should be > shortened + shortened should be < bytes1 + } } }