Skip to content

Instantly share code, notes, and snippets.

@k8si
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k8si/8595b4460a3e11802dba to your computer and use it in GitHub Desktop.
Save k8si/8595b4460a3e11802dba to your computer and use it in GitHub Desktop.
class TestCategoricalDomain extends JUnitSuite with cc.factorie.util.FastLogging {
@Test
def testPlusEquals(): Unit = {
val domain = new CategoricalDomain[String](List("yes", "no"))
domain.freeze()
printDomainInfo(domain, "init")
/*
init:
0 category:yes count:0
1 category:no count:0
*/
assert(domain.size == 2) // domain should have 2 categories
assert(domain.count("yes") == 0) // nothing should be counted yet
domain.gatherCounts = true
domain ++= List("yes") // ++= should increment the count
printDomainInfo(domain, "after ++=(yes)")
/*
after ++=(yes):
0 category:yes count:1
1 category:no count:0
*/
assert(domain.count("yes") == 1)
domain += "yes" // += should also increment the count
printDomainInfo(domain, "after +=(yes)")
/*
after +=(yes):
0 category:yes count:1
1 category:no count:0
*/
assert(domain.count("yes") == 2) // FAIL
}
def printDomainInfo(domain: CategoricalDomain[String], extra: String): Unit = {
println(s"$extra:")
(0 until domain.size).foreach { i =>
val categoryName = domain.category(i)
val count = domain.count(i)
println(s"\t$i\tcategory:$categoryName\tcount:$count")
}
println("")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment