<s> import unittest <EOL> from unittesthelper import init <EOL> init ( ) <EOL> from src . underscore import _ <EOL> from threading import Timer <EOL> class TestStructure ( unittest . TestCase ) : <EOL> class Namespace : <EOL> pass <EOL> def test_bind ( self ) : <EOL> pass <EOL> def test_bindAll ( self ) : <EOL> pass <EOL> def test_memoize ( self ) : <EOL> def fib ( n ) : <EOL> return n if n < <NUM_LIT:2> else fib ( n - <NUM_LIT:1> ) + fib ( n - <NUM_LIT:2> ) <EOL> fastFib = _ . memoize ( fib ) <EOL> self . assertEqual ( <EOL> fib ( <NUM_LIT:10> ) , <NUM_LIT> , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> fastFib ( <NUM_LIT:10> ) , <NUM_LIT> , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> fastFib ( <NUM_LIT:10> ) , <NUM_LIT> , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> fastFib ( <NUM_LIT:10> ) , <NUM_LIT> , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def o ( str ) : <EOL> return str <EOL> fastO = _ . memoize ( o ) <EOL> self . assertEqual ( o ( '<STR_LIT>' ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( fastO ( '<STR_LIT>' ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_delay ( self ) : <EOL> ns = self . Namespace ( ) <EOL> ns . delayed = False <EOL> def func ( ) : <EOL> ns . delayed = True <EOL> _ . delay ( func , <NUM_LIT> ) <EOL> def checkFalse ( ) : <EOL> self . assertFalse ( ns . delayed ) <EOL> print ( "<STR_LIT>" ) <EOL> def checkTrue ( ) : <EOL> self . assertTrue ( ns . delayed ) <EOL> print ( "<STR_LIT>" ) <EOL> Timer ( <NUM_LIT> , checkFalse ) . start ( ) <EOL> Timer ( <NUM_LIT> , checkTrue ) . start ( ) <EOL> def test_defer ( self ) : <EOL> ns = self . Namespace ( ) <EOL> ns . deferred = False <EOL> def defertTest ( bool ) : <EOL> ns . deferred = bool <EOL> _ . defer ( defertTest , True ) <EOL> def deferCheck ( ) : <EOL> self . assertTrue ( ns . deferred , "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> _ . delay ( deferCheck , <NUM_LIT:50> ) <EOL> def test_throttle ( self ) : <EOL> ns = self . Namespace ( ) <EOL> ns . counter = <NUM_LIT:0> <EOL> def incr ( ) : <EOL> ns . counter += <NUM_LIT:1> <EOL> throttledIncr = _ . throttle ( incr , <NUM_LIT:100> ) <EOL> throttledIncr ( ) <EOL> throttledIncr ( ) <EOL> throttledIncr ( ) <EOL> Timer ( <NUM_LIT> , throttledIncr ) . start ( ) <EOL> Timer ( <NUM_LIT> , throttledIncr ) . start ( ) <EOL> Timer ( <NUM_LIT> , throttledIncr ) . start ( ) <EOL> Timer ( <NUM_LIT> , throttledIncr ) . start ( ) <EOL> Timer ( <NUM_LIT> , throttledIncr ) . start ( ) <EOL> Timer ( <NUM_LIT> , throttledIncr ) . start ( ) <EOL> def checkCounter1 ( ) : <EOL> self . assertEqual ( ns . counter , <NUM_LIT:1> , "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> def checkCounter2 ( ) : <EOL> self . assertEqual ( ns . counter , <NUM_LIT:4> , "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> _ . delay ( checkCounter1 , <NUM_LIT> ) <EOL> _ . delay ( checkCounter2 , <NUM_LIT> ) <EOL> def test_debounce ( self ) : <EOL> ns = self . Namespace ( ) <EOL> ns . counter = <NUM_LIT:0> <EOL> def incr ( ) : <EOL> ns . counter += <NUM_LIT:1> <EOL> debouncedIncr = _ . debounce ( incr , <NUM_LIT> ) <EOL> debouncedIncr ( ) <EOL> debouncedIncr ( ) <EOL> debouncedIncr ( ) <EOL> Timer ( <NUM_LIT> , debouncedIncr ) . start ( ) <EOL> Timer ( <NUM_LIT> , debouncedIncr ) . start ( ) <EOL> Timer ( <NUM_LIT> , debouncedIncr ) . start ( ) <EOL> Timer ( <NUM_LIT> , debouncedIncr ) . start ( ) <EOL> Timer ( <NUM_LIT> , debouncedIncr ) . start ( ) <EOL> def checkCounter ( ) : <EOL> self . assertEqual ( <NUM_LIT:1> , ns . counter , "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> _ . delay ( checkCounter , <NUM_LIT> ) <EOL> def test_once ( self ) : <EOL> ns = self . Namespace ( ) <EOL> ns . num = <NUM_LIT:0> <EOL> def add ( ) : <EOL> ns . num += <NUM_LIT:1> <EOL> increment = _ . once ( add ) <EOL> increment ( ) <EOL> increment ( ) <EOL> increment ( ) <EOL> increment ( ) <EOL> self . assertEqual ( ns . num , <NUM_LIT:1> ) <EOL> def test_wrap ( self ) : <EOL> def greet ( name ) : <EOL> return "<STR_LIT>" + name <EOL> def wrap ( func , name ) : <EOL> aname = list ( name ) <EOL> aname . reverse ( ) <EOL> reveresed = "<STR_LIT>" . join ( aname ) <EOL> return func ( name ) + '<STR_LIT:U+0020>' + reveresed <EOL> backwards = _ . wrap ( greet , wrap ) <EOL> self . assertEqual ( backwards ( '<STR_LIT>' ) , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> inner = lambda : "<STR_LIT>" <EOL> obj = { "<STR_LIT:name>" : "<STR_LIT>" } <EOL> obj [ "<STR_LIT>" ] = _ . wrap ( inner , lambda fn : fn ( ) + obj [ "<STR_LIT:name>" ] ) <EOL> self . assertEqual ( obj [ "<STR_LIT>" ] ( ) , "<STR_LIT>" ) <EOL> def test_compose ( self ) : <EOL> def greet ( name ) : <EOL> return "<STR_LIT>" + name <EOL> def exclaim ( sentence ) : <EOL> return sentence + '<STR_LIT:!>' <EOL> def upperize ( full ) : <EOL> return full . upper ( ) <EOL> composed_function = _ . compose ( exclaim , greet , upperize ) <EOL> self . assertEqual ( '<STR_LIT>' , composed_function ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> def test_after ( self ) : <EOL> def testAfter ( afterAmount , timesCalled ) : <EOL> ns = self . Namespace ( ) <EOL> ns . afterCalled = <NUM_LIT:0> <EOL> def afterFunc ( ) : <EOL> ns . afterCalled += <NUM_LIT:1> <EOL> after = _ . after ( afterAmount , afterFunc ) <EOL> while ( timesCalled ) : <EOL> after ( ) <EOL> timesCalled -= <NUM_LIT:1> <EOL> return ns . afterCalled <EOL> self . assertEqual ( testAfter ( <NUM_LIT:5> , <NUM_LIT:5> ) , <NUM_LIT:1> , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( testAfter ( <NUM_LIT:5> , <NUM_LIT:4> ) , <NUM_LIT:0> , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( testAfter ( <NUM_LIT:0> , <NUM_LIT:0> ) , <NUM_LIT:1> , <EOL> "<STR_LIT>" ) <EOL> def test_partial ( self ) : <EOL> def func ( * args ) : <EOL> return '<STR_LIT:U+0020>' . join ( args ) <EOL> pfunc = _ . partial ( func , '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) <EOL> self . assertEqual ( pfunc ( '<STR_LIT:d>' , '<STR_LIT:e>' ) , '<STR_LIT>' ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> unittest . main ( ) </s>
