-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'xZise-official-count' into master
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tests for the backported class:`range` class. | ||
""" | ||
from itertools import count as it_count | ||
|
||
from future.backports.misc import count | ||
from future.tests.base import unittest, skip26 | ||
|
||
|
||
class CountTest(unittest.TestCase): | ||
|
||
"""Test the count function.""" | ||
|
||
def _test_count_func(self, func): | ||
self.assertEqual(next(func(1)), 1) | ||
self.assertEqual(next(func(start=1)), 1) | ||
|
||
c = func() | ||
self.assertEqual(next(c), 0) | ||
self.assertEqual(next(c), 1) | ||
self.assertEqual(next(c), 2) | ||
c = func(1, 1) | ||
self.assertEqual(next(c), 1) | ||
self.assertEqual(next(c), 2) | ||
c = func(step=1) | ||
self.assertEqual(next(c), 0) | ||
self.assertEqual(next(c), 1) | ||
c = func(start=1, step=1) | ||
self.assertEqual(next(c), 1) | ||
self.assertEqual(next(c), 2) | ||
|
||
c = func(-1) | ||
self.assertEqual(next(c), -1) | ||
self.assertEqual(next(c), 0) | ||
self.assertEqual(next(c), 1) | ||
c = func(1, -1) | ||
self.assertEqual(next(c), 1) | ||
self.assertEqual(next(c), 0) | ||
self.assertEqual(next(c), -1) | ||
c = func(-1, -1) | ||
self.assertEqual(next(c), -1) | ||
self.assertEqual(next(c), -2) | ||
self.assertEqual(next(c), -3) | ||
|
||
def test_count(self): | ||
"""Test the count function.""" | ||
self._test_count_func(count) | ||
|
||
@skip26 | ||
def test_own_count(self): | ||
"""Test own count implementation.""" | ||
self._test_count_func(it_count) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |