{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

TestCollatz - /usr/bin/env...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#!/usr/bin/env python # -------------------------------------- # projects/python/collatz/TestCollatz.py # Copyright (C) 2009 # Glenn P. Downing # -------------------------------------- # To run the tests # TestCollatz.py import unittest import Collatz from Collatz import collatz_read, collatz_eval, collatz_print # ------ # Reader # ------ class Reader (object) : def __init__ (self, s) : self.s = s def read (self) : return self.s # ------ # Writer # ------ class Writer (object) : def str (self) : return self.s def write (self, a, v) : self.s = str(a[0]) + " " self.s += str(a[1]) + " " self.s += str(v) + "\n" # ----------- # TestCollatz # ----------- class TestCollatz (unittest.TestCase) : # ---- # read # ---- def test_read (self) : r = Reader("1 10\n") a = [] b = collatz_read(r, a) self.assert_(b == True) self.assert_(a[0] == 1) self.assert_(a[1] == 10) def test_read_whitespace(self) : tests = {'tabs': "1 10\n",
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
'spaces': "1 10\n", 'leading space': " 1 10\n", 'trailing space': "1 10 \n", 'windows newline': "1 10\r\n", 'mac newline': "1 10\r", 'no newline': "1 10"} for test in tests: r = Reader(tests[test]) a = [] b = collatz_read(r, a) self.assert_(b == True) self.assert_(a[0] == 1) self.assert_(a[1] == 10) # test cache def test_cache_strict(self) : Collatz.cycle_length_cache.clear() Collatz.cycle_length_cache[1] = 1 collatz_eval([5,5]) example_cache = { 1: 1, 2: 2, 4: 3, 8: 4, # 16: 5, 5: 6
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern