<s> from __future__ import division <EOL> import numbers <EOL> import math <EOL> import nose <EOL> from python_toolbox import cute_testing <EOL> from python_toolbox . math_tools import cute_floor_div , cute_divmod <EOL> from python_toolbox import sys_tools <EOL> from python_toolbox import logic_tools <EOL> from python_toolbox import math_tools <EOL> infinity = float ( '<STR_LIT>' ) <EOL> infinities = ( infinity , - infinity ) <EOL> def cute_equal ( * items ) : <EOL> if all ( isinstance ( item , numbers . Number ) for item in items ) : <EOL> if all ( map ( math . isnan , items ) ) : return True <EOL> else : return logic_tools . all_equivalent ( items ) <EOL> else : <EOL> assert all ( isinstance ( item , tuple ) for item in items ) <EOL> return all ( cute_equal ( * sub_items ) for sub_items in zip ( * items ) ) <EOL> def test_degenerate_cases ( ) : <EOL> degenerate_cases = ( <EOL> ( <NUM_LIT:4> , <NUM_LIT:5> ) , ( - <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:0> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , - <NUM_LIT> ) , <EOL> ( - <NUM_LIT> , <NUM_LIT:4> ) , ( infinity , infinity ) , ( infinity , - infinity ) , <EOL> ( - infinity , infinity ) , ( - infinity , - infinity ) <EOL> ) <EOL> for degenerate_case in degenerate_cases : <EOL> assert cute_equal ( cute_divmod ( * degenerate_case ) , <EOL> divmod ( * degenerate_case ) ) <EOL> assert cute_equal ( cute_divmod ( * degenerate_case ) [ <NUM_LIT:0> ] , <EOL> cute_floor_div ( * degenerate_case ) , <EOL> degenerate_case [ <NUM_LIT:0> ] // degenerate_case [ <NUM_LIT:1> ] ) <EOL> def test_illegal_cases ( ) : <EOL> illegal_cases = ( <EOL> ( <NUM_LIT:4> , <NUM_LIT:0> ) , ( infinity , <NUM_LIT:0> ) , ( - infinity , <NUM_LIT:0> ) <EOL> ) <EOL> for illegal_case in illegal_cases : <EOL> with cute_testing . RaiseAssertor ( ) as raise_assertor_0 : <EOL> cute_divmod ( * illegal_case ) <EOL> with cute_testing . RaiseAssertor ( ) as raise_assertor_1 : <EOL> divmod ( * illegal_case ) <EOL> with cute_testing . RaiseAssertor ( ) as raise_assertor_2 : <EOL> cute_floor_div ( * illegal_case ) <EOL> assert logic_tools . all_equivalent ( ( <EOL> type ( raise_assertor_0 . exception ) , <EOL> type ( raise_assertor_1 . exception ) , <EOL> type ( raise_assertor_2 . exception ) , <EOL> ) ) <EOL> def test_meaningful_cases ( ) : <EOL> if sys_tools . is_pypy : <EOL> raise nose . SkipTest <EOL> meaningful_cases = ( <EOL> ( infinity , <NUM_LIT:3> ) , ( infinity , <NUM_LIT> ) , ( infinity , - <NUM_LIT:3> ) , ( infinity , - <NUM_LIT> ) , <EOL> ( - infinity , <NUM_LIT:3> ) , ( - infinity , <NUM_LIT> ) , ( - infinity , - <NUM_LIT:3> ) , ( - infinity , - <NUM_LIT> ) , <EOL> ( <NUM_LIT:3> , infinity ) , ( <NUM_LIT:3> , - infinity ) , ( - <NUM_LIT:3> , infinity ) , ( - <NUM_LIT:3> , - infinity ) , <EOL> ( <NUM_LIT> , infinity ) , ( <NUM_LIT> , - infinity ) , <EOL> ( - <NUM_LIT> , infinity ) , ( - <NUM_LIT> , - infinity ) , <EOL> ( <NUM_LIT:0> , infinity ) , ( <NUM_LIT:0> , - infinity ) , <EOL> ) <EOL> for meaningful_numerator , meaningful_denominator in meaningful_cases : <EOL> cute_quotient , cute_remainder = cute_divmod ( meaningful_numerator , <EOL> meaningful_denominator ) <EOL> assert cute_equal ( cute_quotient , <EOL> cute_floor_div ( meaningful_numerator , <EOL> meaningful_denominator ) ) <EOL> assert ( cute_quotient == <EOL> ( meaningful_numerator / meaningful_denominator ) ) or ( <NUM_LIT:0> <= ( ( meaningful_numerator / meaningful_denominator ) <EOL> - cute_quotient ) < <NUM_LIT:1> ) </s>
