imikolov_test.py 662 字节
Newer Older
1 2 3
import paddle.v2.dataset.imikolov
import unittest

4 5
WORD_DICT = paddle.v2.dataset.imikolov.build_dict()

6 7 8 9 10 11 12 13

class TestMikolov(unittest.TestCase):
    def check_reader(self, reader, n):
        for l in reader():
            self.assertEqual(len(l), n)

    def test_train(self):
        n = 5
14
        self.check_reader(paddle.v2.dataset.imikolov.train(WORD_DICT, n), n)
15 16 17

    def test_test(self):
        n = 5
18 19 20 21 22
        self.check_reader(paddle.v2.dataset.imikolov.test(WORD_DICT, n), n)

    def test_total(self):
        _, idx = zip(*WORD_DICT.items())
        self.assertEqual(sorted(idx)[-1], len(WORD_DICT) - 1)
23 24 25 26


if __name__ == '__main__':
    unittest.main()