Last active
August 29, 2015 14:24
-
-
Save k8si/8595b4460a3e11802dba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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