def test_solve_4(self) :
     #Corner test 3 for test_solve
     r = io.StringIO("7 10\n10 7\n150000 10000\n11 17\n")
     w = io.StringIO()
     collatz_solve(r, w)
     self.assertTrue(w.getvalue() == "7 10 20\n10 7 20\n150000 10000 375\n11 17 18\n")
     print("Done.")
예제 #2
0
 def test_solve_4(self):
     r = StringIO("96206 11382\n978863 978942\n122755 134378\n716906 717693\n521409 523944\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(
         w.getvalue(),
         "96206 11382 351\n978863 978942 290\n122755 134378 344\n716906 717693 349\n521409 523944 333\n",
     )
예제 #3
0
 def test_solve_6(self):
     r = StringIO("574005 568276\n639309 639309\n483590 480482\n704510 700488\n689640 695066\n725388 726056\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(
         w.getvalue(),
         "574005 568276 377\n639309 639309 173\n483590 480482 382\n704510 700488 411\n689640 695066 442\n725388 726056 305\n",
     )
예제 #4
0
 def test_solve_2(self):
     r = StringIO("680304 687023\n669922 674486\n747292 747507\n861524 862840\n419840 420010\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(
         w.getvalue(),
         "680304 687023 398\n669922 674486 367\n747292 747507 349\n861524 862840 326\n419840 420010 281\n",
     )
예제 #5
0
 def test_solve_2(self):
     read = StringIO("4331 4370\n8454 8517\n1275 1335\n868 893\n"
                     "5674 5732\n6157 6232\n6649 6694\n5837 5857\n"
                     "5646 5696\n12 26\n6072 6165\n")
     write = StringIO()
     collatz_solve(read, write)
     self.assertEqual(
         write.getvalue(), "4331 4370 184\n8454 8517 203\n1275 1335 177\n868 893 179\n"
                           "5674 5732 174\n6157 6232 262\n6649 6694 182\n5837 5857 218\n"
                           "5646 5696 205\n12 26 24\n6072 6165 187\n")
 def test_solve_length_sanity_high (self) :
     i = 999000
     while i < 1000000 :
         r = StringIO.StringIO(str(i) + " " + str(i))
         w = StringIO.StringIO()
         collatz_solve(r, w)
         a = w.getvalue().split()
         self.assert_(a[0] == a[1])
         self.assert_(a[2] == str(collatz_length(i)))
         i += 1
    def test_solve (self) :
        r = StringIO.StringIO("1 10\n100 200\n201 210\n900 1000\n")
        w = StringIO.StringIO()
        collatz_solve(r, w)
        self.assert_(w.getvalue() == "1 10 20\n100 200 125\n201 210 89\n900 1000 174\n")
	
	def test_solve_2 (self) :
		r = StringIO.StringIO("1 20\n900 1000\n")
        w = StringIO.StringIO()
        collatz_solve(r, w)
        self.assert_(w.getvalue() == "1 20 21\n900 1000 174\n")
예제 #8
0
    def test_solve_from_file (self):
        files_in = glob.glob('*RunCollatz.in')
        i = 0
        while(i < len(files_in)) :      
            w = StringIO()
            in_string = files_in[i]
            out_string = in_string[:-2] + 'out'
            files_out = glob.glob(out_string)
            

            if(files_out == []):
                print('missing file ' + out_string)
                break
            r = open(in_string, 'r')
            s = open(out_string,'r')
            collatz_solve(r, w)
            self.assertEqual(w.getvalue(),s.read())
            i += 1
    def test_solve_5 (self) :
        r = StringIO.StringIO("1001 2001\n")
        w = StringIO.StringIO()
        collatz_solve(r, w)
        self.assert_(w.getvalue() == "1001 2001 182\n")

	# ------------
	# cycle_length
	# ------------

	def test_cycle_length_1 (self):
		l0 = cycle_length(0)
		self.assert_(l0 == 0)

	def test_cycle_length_2 (self):
		l = cycle_length(-1)
		self.assert_(l == 0)

	def test_cycle_length_3 (self):
		l = cycle_length(5)
		self.assert_(l == 6)
예제 #10
0
 def test_solve_2 (self) :
     r = StringIO("22 22\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(), "22 22 16\n")
 def test_solve4(self):
     r = StringIO("")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(), "")
 def test_solve_2 (self) :
     r = StringIO.StringIO("21 94\n43 146\n52 429\n89 371\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "21 94 116\n43 146 122\n52 429 144\n89 371 144\n")
예제 #13
0
 def test_solve_3 (self) :
     r = StringIO("1 1\n2 2\n3 3\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(), "1 1 1\n2 2 2\n3 3 8\n")
예제 #14
0
 def test_solve2 (self) :
     r = io.StringIO("1 100\n50 100\n")
     w = io.StringIO()
     collatz_solve(r, w)
     self.assertTrue(w.getvalue() == "1 100 119\n50 100 119\n")
예제 #15
0
 def test_solve4 (self) :
     r = io.StringIO("1 1\n")
     w = io.StringIO()
     collatz_solve(r, w)
     self.assertTrue(w.getvalue() == "1 1 1\n")
예제 #16
0
 def test_solve_3 (self) :
     r = StringIO("46001 46500\n 46001 47000\n46001 47500\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(), "46001 46500 283\n46001 47000 283\n46001 47500 314\n")
예제 #17
0
 def test_solve_robs2 (self):
     r = StringIO.StringIO("1 999999\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "1 999999 525\n")
예제 #18
0
 def test_solve_2 (self) :
     r = StringIO("10001 19000\n 10001 20000\n 12001 24000\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(), "10001 19000 279\n10001 20000 279\n12001 24000 282\n")
예제 #19
0
 def test_solve_4 (self) :
     r = StringIO("46001 52000\n 1 52000\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(), "46001 52000 314\n1 52000 324\n")
예제 #20
0
 def test_solve_2(self):
     r = StringIO("1 5\n1 10\n20 23\n900 920\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(),
                      "1 5 8\n1 10 20\n20 23 16\n900 920 130\n")
예제 #21
0
 def test_solve_3(self):
     r = StringIO("1 20\n20 25\n201 210\n90 100\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(),
                      "1 20 21\n20 25 24\n201 210 89\n90 100 119\n")
 def test_solve_2(self):
     r = StringIO.StringIO("1 10\n1 200\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "1 10 20\n1 200 125\n")
 def test_solve_2 (self):
     r= StringIO.StringIO("3 3\n")
     w= StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "3 3 8\n")
 def test_solve_4(self):  # 1's only
     r = StringIO.StringIO("1 1\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "1 1 1\n")
 def test_solve_3 (self):
     r= StringIO.StringIO("10 1\n")
     w= StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "10 1 20\n")
 def test_solve_3(self):
     r = StringIO.StringIO("999999 999999\n999999 1\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "999999 999999 259\n999999 1 525\n")
예제 #27
0
 def test_solve_robs3 (self):
     r = StringIO.StringIO("1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "1 1 1\n1 2 2\n1 3 8\n1 4 8\n1 5 8\n1 6 9\n1 7 17\n1 8 17\n1 9 20\n1 10 20\n")
 def test_solve (self) :
     r = io.StringIO("1 10\n100 200\n201 210\n900 1000\n")
     w = io.StringIO()
     collatz_solve(r, w)
     self.assertTrue(w.getvalue() == "1 10 20\n100 200 125\n201 210 89\n900 1000 174\n")
예제 #29
0
 def test_solve3 (self) :
     r = io.StringIO("1 50\n600 2353\n325 565\n5676 543\n")
     w = io.StringIO()
     collatz_solve(r, w)
     self.assertTrue(w.getvalue() == "1 50 112\n600 2353 183\n325 565 144\n5676 543 238\n")
 def test_solve2 (self) :
     r = io.StringIO("967683 703701\n644251 665810\n76872 814669\n530867 656311\n")
     w = io.StringIO()
     collatz_solve(r, w)
     self.assertTrue(w.getvalue() == "967683 703701 525\n644251 665810 442\n76872 814669 509\n530867 656311 509\n")
예제 #31
0
 def test_solve_2 (self) :
     r = StringIO("10 50\n50 10\n1 1\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(), "10 50 112\n50 10 112\n1 1 1\n")
 def test_solve_2(self):  # Empty input
     r = StringIO.StringIO("")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "")
 def test_solve_3 (self) :
     r = StringIO.StringIO("34 306\n32 78\n62 160\n60 279\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "34 306 128\n32 78 116\n62 160 122\n60 279 128\n")
예제 #34
0
 def test_solve_2 (self) :
     r = StringIO.StringIO("2 7\n150 200\n2010 2009\n1000 19000\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "2 7 17\n150 200 125\n2010 2009 69\n1000 19000 279\n")
예제 #35
0
 def test_solve_1 (self) :
     r = StringIO("1 10\n100 200\n201 210\n900 1000\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(), "1 10 20\n100 200 125\n201 210 89\n900 1000 174\n")
예제 #36
0
 def test_solve_3 (self) :
     r = StringIO.StringIO("20000 50000\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "20000 50000 324\n")
예제 #37
0
# ------------------------------

# -------
# imports
# -------

import sys

from Collatz import collatz_solve

# ----
# main
# ----

if __name__ == "__main__":
    collatz_solve(sys.stdin, sys.stdout)

"""
% cat RunCollatz.in
1 10
100 200
201 210
900 1000



% RunCollatz.py < RunCollatz.in > RunCollatz.out



% cat RunCollatz.out
 def test_solve2(self):
     r = StringIO("10 1\n200 100\n210 201\n1000 900\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(),
                      "10 1 20\n200 100 125\n210 201 89\n1000 900 174\n")
 def test_solve1 (self) :
     r = io.StringIO("649019 599597\n159613 483743\n423758 917593\n555305 581054\n")
     w = io.StringIO()
     collatz_solve(r, w)
     self.assertTrue(w.getvalue() == "649019 599597 509\n159613 483743 449\n423758 917593 525\n555305 581054 421\n")
예제 #40
0
 def test_solve_1 (self) : #tests 1-3 for solve are new
     r = StringIO.StringIO("1 1\n100 100\n10 1\n5 1000\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "1 1 1\n100 100 26\n10 1 20\n5 1000 179\n")
 def test_solve_3 (self) :
     r = StringIO.StringIO("1 10\n1 200\n201 210\n")
     w = StringIO.StringIO()
     collatz_solve(r, w)
     self.assert_(w.getvalue() == "1 10 20\n1 200 125\n201 210 89\n")
예제 #42
0
 def test_solve_2(self):
     r = StringIO("1 10\na b\n100 200\n")
     w = StringIO()
     collatz_solve(r, w)
     self.assertEqual(w.getvalue(), "1 10 20\n100 200 125\n")