Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 101 lines (74 sloc) 2.101 kb
#!/usr/bin/env python3
# -------------------------------
# projects/collatz/TestCollatz.py
# Copyright (C) 2014
# Glenn P. Downing
# -------------------------------
# -------
# imports
# -------
from io import StringIO
from unittest import main, TestCase
from Collatz import collatz_read, collatz_eval, collatz_print, collatz_solve
# -----------
# TestCollatz
# -----------
class TestCollatz (TestCase) :
# ----
# read
# ----
def test_read (self) :
s = "1 10\n"
i, j = collatz_read(s)
self.assertEqual(i, 1)
self.assertEqual(j, 10)
# ----
# eval
# ----
def test_eval_1 (self) :
v = collatz_eval(1, 10)
self.assertEqual(v, 1)
def test_eval_2 (self) :
v = collatz_eval(100, 200)
self.assertEqual(v, 1)
def test_eval_3 (self) :
v = collatz_eval(201, 210)
self.assertEqual(v, 1)
def test_eval_4 (self) :
v = collatz_eval(900, 1000)
self.assertEqual(v, 1)
# -----
# print
# -----
def test_print (self) :
w = StringIO()
collatz_print(w, 1, 10, 20)
self.assertEqual(w.getvalue(), "1 10 20\n")
# -----
# solve
# -----
def test_solve (self) :
r = StringIO("1 10\n100 200\n201 210\n900 1000\n")
w = StringIO()
collatz_solve(r, w)
self.assertEqual(w.getvalue(), "1 10 1\n100 200 1\n201 210 1\n900 1000 1\n")
# ----
# main
# ----
if __name__ == "__main__" :
main()
"""
% coverage3 run --branch TestCollatz.py > TestCollatz.out 2>&1
% coverage3 report -m >> TestCollatz.out
% cat TestCollatz.out
.......
----------------------------------------------------------------------
Ran 7 tests in 0.001s
OK
Name Stmts Miss Branch BrMiss Cover Missing
---------------------------------------------------------
Collatz 18 0 6 0 100%
TestCollatz 33 1 2 1 94% 79
---------------------------------------------------------
TOTAL 51 1 8 1 97%
"""
Jump to Line
Something went wrong with that request. Please try again.