def test_ana() : import grin stests = [ 'live', 'mountaineer', 'feed', 'done' ] ttests = [ 'vile', 'enumeration', 'fed', 'need' ] for i in range( 0, len( stests ) ) : s = stests[ i ] t = ttests[ i ] b = grin.ana( s, t ) print( 'ana(', s + ', ' + t, '):', b ) print() def test_rev() : import grin stests = [ 'deed', 'racecar', 'feed', 'palindrome' ] for s in stests : b = grin.rev( s ) print( 'rev(', s, '):', b ) print() def test_loc() : import reflect import url from PIL import Image link = 'http://www.cs.virginia.edu/~cs1112/images/coloring-book/girl-and-dog.png' img = url.get_image( link ) ow, oh = img.size nw, nh = img.size new_image = Image.new( 'RGB', ( nw, nh ) ) for nx in range( 0, nw ) : for ny in range( 0, nh ) : nspot = (nx, ny ) ospot = reflect.loc( img, nspot ) opixel = img.getpixel( ospot ) npixel = opixel new_image.putpixel( nspot, npixel ) new_image.show() def test_aver() : import url from PIL import Image import age link1 = 'http://www.cs.virginia.edu/~cs1112/images/tj.png' link2 = 'http://www.cs.virginia.edu/~cs1112/images/ml.png' img1 = url.get_image( link1 ) img2 = url.get_image( link2 ) pixel1 = age.aver( img1 ) pixel2 = age.aver( img2 ) print( 'aver( Thomas Jefferson ):', pixel1 ) print( 'aver( Mona Lisa ):', pixel2 ) def test_ing() : import rat tests = [ 1, 0, 121, 117 ] for s in tests: a = rat.ing( s ) print( 'ing(', s, '):', a ) def test_oint() : import disj tests = [ [ 'a', 'b', 'cc', 'd' ], [ 'a', 'b', 'ca', 'd' ], [ 'a', 'b', 'bb', 'd' ], [ 'a', 'b', 'cd', 'd' ] ] for a in tests : b = disj.oint( a ) print( 'oint(', a, '):', b ) def test_tors() : import pals tests = [ 2, 4, 10, 48 ] for n in tests : b = pals.tors( n ) print( 'tors(', n, '):', b ) def test_roll() : import dice import random random.seed( 1112 ) r1 = dice.roll() r2 = dice.roll() r3 = dice.roll() print( 'roll():', r1 ) print( 'roll():', r2 ) print( 'roll():', r3 ) print() def test_rolls() : import dice import random random.seed( 1112 ) r1 = dice.rolls() r2 = dice.rolls() r3 = dice.rolls() print( 'rolls():', r1 ) print( 'rolls():', r2 ) print( 'rolls():', r3 ) def test_ona() : import fib tests = [ 2, 5, 6, 7 ] for n in tests : r = fib.ona( n ) print( 'ona(', n, '):', r ) def test_nand() : import george tests = [ [False, False], [False, True], [True, False], [True, True] ] for n in tests : p, q = n r = george.nand( p, q ) print( 'nand(', p, ',', q, '):', r ) print() def test_nor() : import george tests = [ [False, False], [False, True], [True, False], [True, True] ] for n in tests : p, q = n r = george.nor( p, q ) print( 'nor(', p, ',', q, '):', r ) print() def test_xor() : import george tests = [ [False, False], [False, True], [True, False], [True, True] ] for n in tests : p, q = n r = george.xor( p, q ) print( 'xor(', p, ',', q, '):', r ) print() def test_sum() : import quad d1 = [[31, 28, 31, 30], [31, 30, 31, 31], [30, 31, 30, 31 ]] d2 = [[1, 1, 2, 3], [5, 8, 13, 21], [34, 55, 89, 144], [233, 377, 610, 987 ]] r1 = quad.sum( d1 ) print( 'sum( d1 ):', r1 ) r2 = quad.sum( d2 ) print( 'sum( d2 ):', r2 ) def test_unique() : import triad tests = [ [31, 28, 31, 30], [1, 24, 7, 52, 365 ] ] for t in tests : r = triad.unique( t ) print( 'unique(', t, '):', r ) print() def test_counts() : import triad tests = [ [31, 28, 31, 30, 24 ], [ 28, 30, 31, 30, 31, 31, 30, 31 ] ] for t in tests : r = triad.counts( t ) print( 'counts(', t, '):', r ) print() def test_cmp() : import triad dtests = [ [1, 3, 5, 7], [1, 3, 5, 7], [1, 3, 5, 7 ] ] etests = [ [ 17 ], [ 4, 12 ], [ 4, 5, 6 ] ] for i in range( 0, len( dtests) ) : d = dtests[ i ] e = etests[ i ] r = triad.cmp( d, e ) print( 'cmp(', d, e, '):', r )