test_iterators.py 817 Bytes
Newer Older
Myle Ott's avatar
Myle Ott committed
1
2
3
4
5
6
7
8
9
# Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the LICENSE file in
# the root directory of this source tree. An additional grant of patent rights
# can be found in the PATENTS file in the same directory.

import unittest

10
from fairseq.data import iterators
Myle Ott's avatar
Myle Ott committed
11
12


13
class TestIterators(unittest.TestCase):
Myle Ott's avatar
Myle Ott committed
14
15
16

    def test_counting_iterator(self):
        x = list(range(10))
17
        itr = iterators.CountingIterator(x)
Myle Ott's avatar
Myle Ott committed
18
19
20
21
22
23
24
25
26
27
28
29
        self.assertTrue(itr.has_next())
        self.assertEqual(next(itr), 0)
        self.assertEqual(next(itr), 1)
        itr.skip(3)
        self.assertEqual(next(itr), 5)
        itr.skip(3)
        self.assertEqual(next(itr), 9)
        self.assertFalse(itr.has_next())


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