Skip to content

Commit

Permalink
UTF8String Property Checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosen authored and yjshen committed Jul 31, 2015
1 parent a3a85d7 commit 9209c64
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions unsafe/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalacheck</groupId>
<artifactId>scalacheck_${scala.binary.version}</artifactId>
</dependency>
</dependencies>
<build>
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.apache.spark.unsafe.types

import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FunSuite, Matchers}
import org.apache.spark.unsafe.types.UTF8String.{fromString => toUTF8}


class UTF8StringSuite2 extends FunSuite with GeneratorDrivenPropertyChecks with Matchers {

test("toString") {
forAll { (s: String) =>
assert(s === toUTF8(s).toString())
}
}

test("numChars") {
forAll { (s: String) =>
assert(toUTF8(s).numChars() === s.length)
}
}

test("startsWith") {
forAll { (s: String) =>
val utf8 = toUTF8(s)
assert(utf8.startsWith(utf8))
for (i <- 1 to s.length) {
assert(utf8.startsWith(toUTF8(s.dropRight(i))))
}
}
}

test("endsWith") {
forAll { (s: String) =>
val utf8 = toUTF8(s)
assert(utf8.endsWith(utf8))
for (i <- 1 to s.length) {
assert(utf8.endsWith(toUTF8(s.drop(i))))
}
}
}

test("toUpperCase") {
forAll { (s: String) =>
assert(s.toUpperCase === toUTF8(s).toUpperCase.toString)
}
}

test("toLowerCase") {
forAll { (s: String) =>
assert(s.toLowerCase === toUTF8(s).toLowerCase.toString)
}
}

test("compare") {
forAll { (s1: String, s2: String) =>
assert(Math.signum(s1.compareTo(s2)) === Math.signum(toUTF8(s1).compareTo(toUTF8(s2))))
}
}

test("substring") {
forAll { (s: String) =>
assert(s.substring(0, 0) === toUTF8(s).substring(0, 0).toString)
assert(s.substring(0, s.length) === toUTF8(s).substring(0, s.length).toString)
}
}
}

0 comments on commit 9209c64

Please sign in to comment.