File: test_genexps_jy.py

package info (click to toggle)
jython 2.5.3-16%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,772 kB
  • ctags: 106,434
  • sloc: python: 351,322; java: 216,349; xml: 1,584; sh: 330; perl: 114; ansic: 102; makefile: 45
file content (34 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download | duplicates (8)
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
30
31
32
33
34
"""Misc generator expression tests

Made for Jython.
"""
import unittest
from test import test_support

locals_test = list(local for local in locals() if not local.startswith('_'))

class GeneratorExpressionsTestCase(unittest.TestCase):

    def test_module_level_locals(self):
        # NOTE: The locals_test genexp used to cause a 'dictionary
        # changed size during iteration' RuntimeError. If we've gotten
        # this far we've already passed
        self.assert_(sorted(locals_test) == ['test_support', 'unittest'])

    #http://bugs.jython.org/issue1205 applied to genexps.
    def test_long_genexp(self):
        #for a long genexp, we compute the Hardy-Ramanujan number
        #http://en.wikipedia.org/wiki/1729_(number)
        res = ((x1**3+x2**3,(x1,x2),(y1,y2))
              for x1 in range(20) for x2 in range(20) if x1 < x2 # x-Paare
              for y1 in range(20) for y2 in range(20) if y1 < y2 # y-Paare
              if x1**3+x2**3 == y1**3+y2**3 # gleiche Summe
              if (x1,x2) < (y1,y2)
              )
        self.assertEquals(1729, res.next()[0])

def test_main():
    test_support.run_unittest(GeneratorExpressionsTestCase)

if __name__ == '__main__':
    test_main()