<s> """<STR_LIT>""" <EOL> import common <EOL> from pyalgotrade . technical import linreg <EOL> from pyalgotrade import dataseries <EOL> class SlopeTest ( common . TestCase ) : <EOL> def __buildSlope ( self , values , period , slopeMaxLen = None ) : <EOL> seqDS = dataseries . SequenceDataSeries ( ) <EOL> ret = linreg . Slope ( seqDS , period , slopeMaxLen ) <EOL> for value in values : <EOL> seqDS . append ( value ) <EOL> return ret <EOL> def testSlope ( self ) : <EOL> slope = self . __buildSlope ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] , <NUM_LIT:3> ) <EOL> self . assertEqual ( slope [ <NUM_LIT:0> ] , None ) <EOL> self . assertEqual ( slope [ <NUM_LIT:1> ] , None ) <EOL> self . assertEqual ( round ( slope [ <NUM_LIT:2> ] , <NUM_LIT:2> ) , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( slope [ <NUM_LIT:3> ] , <NUM_LIT:0.0> ) <EOL> self . assertEqual ( slope [ <NUM_LIT:4> ] , - <NUM_LIT:1.0> ) <EOL> def testSlopeBounded ( self ) : <EOL> slope = self . __buildSlope ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] , <NUM_LIT:3> , <NUM_LIT:2> ) <EOL> self . assertEqual ( slope [ <NUM_LIT:0> ] , <NUM_LIT:0.0> ) <EOL> self . assertEqual ( slope [ <NUM_LIT:1> ] , - <NUM_LIT:1.0> ) <EOL> class TrendTest ( common . TestCase ) : <EOL> def __buildTrend ( self , values , trendDays , positiveThreshold , negativeThreshold , trendMaxLen = None ) : <EOL> seqDS = dataseries . SequenceDataSeries ( ) <EOL> ret = linreg . Trend ( seqDS , trendDays , positiveThreshold , negativeThreshold , trendMaxLen ) <EOL> for value in values : <EOL> seqDS . append ( value ) <EOL> return ret <EOL> def testTrend ( self ) : <EOL> trend = self . __buildTrend ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertEqual ( trend [ <NUM_LIT:0> ] , None ) <EOL> self . assertEqual ( trend [ <NUM_LIT:1> ] , None ) <EOL> self . assertEqual ( trend [ <NUM_LIT:2> ] , True ) <EOL> self . assertEqual ( trend [ <NUM_LIT:3> ] , None ) <EOL> self . assertEqual ( trend [ <NUM_LIT:4> ] , False ) <EOL> self . assertEqual ( len ( trend . getDateTimes ( ) ) , <NUM_LIT:5> ) <EOL> for i in range ( len ( trend ) ) : <EOL> self . assertEqual ( trend . getDateTimes ( ) [ i ] , None ) <EOL> def testTrendWithCustomThresholds ( self ) : <EOL> trend = self . __buildTrend ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , - <NUM_LIT:10> ] , <NUM_LIT:3> , <NUM_LIT:1> , - <NUM_LIT:1> ) <EOL> self . assertEqual ( trend [ <NUM_LIT:0> ] , None ) <EOL> self . assertEqual ( trend [ <NUM_LIT:1> ] , None ) <EOL> self . assertEqual ( trend [ <NUM_LIT:2> ] , None ) <EOL> self . assertEqual ( trend [ <NUM_LIT:3> ] , True ) <EOL> self . assertEqual ( trend [ <NUM_LIT:4> ] , False ) <EOL> self . assertEqual ( len ( trend . getDateTimes ( ) ) , <NUM_LIT:5> ) <EOL> for i in range ( len ( trend ) ) : <EOL> self . assertEqual ( trend . getDateTimes ( ) [ i ] , None ) <EOL> def testTrendWithCustomThresholds_Bounded ( self ) : <EOL> trend = self . __buildTrend ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , - <NUM_LIT:10> ] , <NUM_LIT:3> , <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> self . assertEqual ( trend [ <NUM_LIT:0> ] , True ) <EOL> self . assertEqual ( trend [ <NUM_LIT:1> ] , False ) <EOL> self . assertEqual ( len ( trend ) , <NUM_LIT:2> ) <EOL> def testInvalidThreshold ( self ) : <EOL> seqDS = dataseries . SequenceDataSeries ( ) <EOL> with self . assertRaisesRegexp ( Exception , "<STR_LIT>" ) : <EOL> linreg . Trend ( seqDS , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:0.5> , <NUM_LIT:5> ) </s>
