MCPcopy
hub / github.com/ddbourgin/numpy-ml / test_huffman

Function test_huffman

numpy_ml/tests/test_preprocessing.py:36–53  ·  view source on GitHub ↗
(N=15)

Source from the content-addressed store, hash-verified

34
35
36def test_huffman(N=15):
37 np.random.seed(12345)
38
39 i = 0
40 while i < N:
41 n_words = np.random.randint(1, 100)
42 para = random_paragraph(n_words)
43 HT = HuffmanEncoder()
44 HT.fit(para)
45 my_dict = HT._item2code
46 their_dict = huffman.codebook(Counter(para).items())
47
48 for k, v in their_dict.items():
49 fstr = "their_dict['{}'] = {}, but my_dict['{}'] = {}"
50 assert k in my_dict, "key `{}` not in my_dict".format(k)
51 assert my_dict[k] == v, fstr.format(k, v, k, my_dict[k])
52 print("PASSED")
53 i += 1
54
55
56def test_standardizer(N=15):

Callers

nothing calls this directly

Calls 4

fitMethod · 0.95
random_paragraphFunction · 0.90
HuffmanEncoderClass · 0.90
codebookMethod · 0.80

Tested by

no test coverage detected