package lojban

import org.scalatest.FunSuite
import SentenceGenerator._, SentenceRecognizer._

class SentenceGeneratorTest extends FunSuite {
  val vowels = "aeiou"
  val consonants = "bcdfgjklmnprstvxyz"

  /** Test whether the character is a vowel ("aeiou") */
  def isV(ch: Char) = "aeiou" contains ch

  /** Test whether the character is a consonant
   *  ('h', 'q', and 'w' are not used)
   */
  def isC(ch: Char) = "bcdfgjklmnprstvxyz" contains ch

  /** Sentence is a Statement or a Predclaim */
  test("Testing makeSentence") {
    for (i <- 1 to 10) assert(isSentence(makeSentence))
  }

  /** Predclaim is a Predname BA Preds or a DA Preds */
  test("Testing makePredclaim") {
    for (i <- 1 to 50) assert(isPredclaim(makePredclaim))
  }

  /** Preds is a Predstring or a Preds A Predstring */
  test("Testing makePreds") {
    for (i <- 1 to 50) assert(isPredstring(makePredstring))
  }

  /** Predname is a LA Predstring or a NAME */
  test("Testing makePredname") {
    for (i <- 1 to 50) assert(isPredname(makePredname))
  }
  
  /** Predstring is a PRED or a Predstring PRED */
  test("Testing makePredstring") {
    for (i <- 1 to 50) assert(isPredstring(makePredstring))
  }
  
   /** Statement is a Predname Verbpred Predname or a Predname Verbpred */
  test("Testing makeStatement") {
    for (i <- 1 to 50) assert(isStatement(makeStatement))
  }

  /** Verbpred is a MOD Predstring */
  test("Testing makeVerbpred") {
    for (i <- 1 to 50) assert(isVerbpred(makeVerbpred))
  }
  
  /** A is "a" or "e" or "i" or "o" or "u" */
  test("Testing makeA") {
    for (i <- 1 to 50) assert("aeiou" contains makeA)
  }
  
  /** MOD is "ga" or "ge" or "gi" or "go" or "gu" */
  test("Testing makeMOD") {
    val ga = "ga ge gi go gu".split(' ')
    for (i <- 1 to 50) assert(ga contains makeMOD)
  }
  
  /** BA is "ba" or "be" or "bi" or "bo" or "bu" */
  test("Testing makeBA") {
    val ba = "ba be bi bo bu".split(' ')
    for (i <- 1 to 50) assert(ba contains makeBA)
  }
  
  /** DA is "da" or "de" or "di" or "do" or "du" */
  test("Testing makeDA") {
    for (i <- 1 to 50) assert(isDA(makeDA))
  }
  
   /** LA is "la" or "le" or "li" or "lo" or "lu" */
  test("Testing makeLA") {
    for (i <- 1 to 50) assert(isLA(makeLA))
  }
  
  /** NAME is any name (must end in a consonant) */
  test("Testing makeNAME") {
    for (i <- 1 to 50) {
      val name = makeNAME
      assert(consonants contains (name.last), name)
    }
  }
  
  /** PRED is any predicate -- must have the form CCVCV or CVCCV */
  test("Testing makePRED") {
    for (i <- 1 to 50) {
      val p = makePRED
      assert(isPRED(p), p)
    }
  }
}