def test_naive_bayes(testdoc, logpriors, loglikelihoods, C, V):
    """Given testdoc, a list of tokens, return the most likely class."""
    bestscore = float("-inf")
    # http://hrwiki.org/w/index.php?title=Flagrant_System_Error&redirect=no
    bestclass = "Flagrant System Error"
    for c in C:
        sum = logpriors[c]
        for tok in testdoc:
            if tok in V:
                sum += loglikelihoods[(tok, c)]
        # print("score for {}: {}".format(c, sum))
        if sum > bestscore:
            bestscore = sum
            bestclass = c
    return bestclass