File: test_listcomp_jy.py

package info (click to toggle)
jython 2.5.1-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 41,624 kB
  • ctags: 101,579
  • sloc: python: 351,444; java: 204,338; xml: 1,316; sh: 330; ansic: 126; perl: 114; makefile: 94
file content (23 lines) | stat: -rw-r--r-- 784 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
import unittest
from test import test_support

class ListCompTestCase(unittest.TestCase):

    #http://bugs.jython.org/issue1205
    def test_long_listcomp(self):
        #for a long list comp, 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, min(res)[0])
        self.assertEquals(len(res), 2)

def test_main():
    test_support.run_unittest(ListCompTestCase)

if __name__ == '__main__':
    test_main()