| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (CordTest.scala)

This example Scala source code file (CordTest.scala) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Scala by Example" TM.

Learn more about this Scala project at its project page.

Java - Scala tags/keywords

arbitrarycord, cord, cordtest, once, speclite, while

The CordTest.scala Scala example source code

package scalaz

import org.scalacheck.Arbitrary
import scalaz.scalacheck.ScalazProperties._
import scalaz.scalacheck.ScalaCheckBinding._
import Cord._
import org.scalacheck.Prop.forAll

object CordTest extends SpecLite {
  "split() must result in two cords whose summary length is equal to the length of original cord " in {
    val x = Cord("Once upon a midnight dreary")
    for (i <- 0 until x.length) {
      val split = x split i
      split._1.length + split._2.length must_== x.length

  "drop() must make cord shorter" in {
    val theString = "While I pondered, weak and weary"
    val x = Cord(theString)
    for (i <- 0 until x.length) {
      val y = x drop i
      y.toString must_== theString.substring(i)

  "tail() must be smaller than the whole, generally" in {
    val x = Cord("abc")
    x.tail.toString must_== "bc"
    x.tail.tail.toString must_== "c"
    x.tail.tail.tail.toString must_== ""

  "isEmpty() must indicate string is empty" ! forAll { (a:Cord, b:Cord) =>
    a.isEmpty == a.toString.isEmpty &&
    b.isEmpty == b.toString.isEmpty &&
    (a ++ b).isEmpty == (a.toString.isEmpty && b.toString.isEmpty)

  "nonEmpty() must indicate string is non-empty" ! forAll { (a:Cord, b:Cord) =>
    val c = a ++ b
    a.nonEmpty == !a.toString.isEmpty &&
    b.nonEmpty == !b.toString.isEmpty &&
    (a ++ b).nonEmpty == (!a.toString.isEmpty || !b.toString.isEmpty)

  implicit def ArbitraryCord: Arbitrary[Cord] = Functor[Arbitrary].map(implicitly[Arbitrary[String]])(Cord.stringToCord)


Other Scala examples (source code examples)

Here is a short list of links related to this Scala CordTest.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.