Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_iterators.py 817 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  1. # Copyright (c) 2017-present, Facebook, Inc.
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the LICENSE file in
  5. # the root directory of this source tree. An additional grant of patent rights
  6. # can be found in the PATENTS file in the same directory.
  7. import unittest
  8. from fairseq.data import iterators
  9. class TestIterators(unittest.TestCase):
  10. def test_counting_iterator(self):
  11. x = list(range(10))
  12. itr = iterators.CountingIterator(x)
  13. self.assertTrue(itr.has_next())
  14. self.assertEqual(next(itr), 0)
  15. self.assertEqual(next(itr), 1)
  16. itr.skip(3)
  17. self.assertEqual(next(itr), 5)
  18. itr.skip(3)
  19. self.assertEqual(next(itr), 9)
  20. self.assertFalse(itr.has_next())
  21. if __name__ == '__main__':
  22. unittest.main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...