<s> import math <EOL> from almost import Approximate <EOL> from pytest import raises <EOL> from elo import * <EOL> from elopopulars import * <EOL> class almost ( Approximate ) : <EOL> def normalize ( self , value ) : <EOL> if isinstance ( value , Rating ) and not isinstance ( value , float ) : <EOL> return self . normalize ( float ( value ) ) <EOL> elif isinstance ( value , ( list , tuple ) ) : <EOL> try : <EOL> if isinstance ( value [ <NUM_LIT:0> ] , Rating ) : <EOL> value = tuple ( map ( float , value ) ) <EOL> except ( TypeError , IndexError ) : <EOL> pass <EOL> return super ( almost , self ) . normalize ( value ) <EOL> def test_rating ( ) : <EOL> if type ( Rating ) is not type : <EOL> assert isinstance ( <NUM_LIT> , Rating ) <EOL> assert issubclass ( float , Rating ) <EOL> assert Rating ( <NUM_LIT:100> ) == <NUM_LIT:100> <EOL> assert Rating ( <NUM_LIT:100> ) < <NUM_LIT:200> <EOL> assert Rating ( <NUM_LIT:100> ) <= <NUM_LIT:200> <EOL> assert not ( Rating ( <NUM_LIT:100> ) == <NUM_LIT:200> ) <EOL> assert not ( Rating ( <NUM_LIT:100> ) > <NUM_LIT:200> ) <EOL> assert not ( Rating ( <NUM_LIT:100> ) >= <NUM_LIT:200> ) <EOL> assert Rating ( <NUM_LIT:100> ) == Rating ( <NUM_LIT:100> ) <EOL> assert Rating ( <NUM_LIT:100> ) != Rating ( <NUM_LIT:200> ) <EOL> def test_initial_rating ( ) : <EOL> env = Elo ( initial = <NUM_LIT:1000> ) <EOL> assert env . create_rating ( ) == <NUM_LIT:1000> <EOL> def test_custom_rating_class ( ) : <EOL> class CustomRating ( Rating ) : pass <EOL> assert Elo ( CustomRating ( <NUM_LIT> ) , rating_class = CustomRating ) <EOL> elo = Elo ( <NUM_LIT> , rating_class = CustomRating ) <EOL> assert isinstance ( elo . create_rating ( <NUM_LIT> ) , CustomRating ) <EOL> def test_mixed_rating_class ( ) : <EOL> class MixedRating ( CountedRating , TimedRating ) : <EOL> pass <EOL> env = Elo ( rating_class = MixedRating ) <EOL> rating = env . create_rating ( <NUM_LIT:1000> ) <EOL> assert hasattr ( rating , '<STR_LIT>' ) <EOL> assert hasattr ( rating , '<STR_LIT>' ) <EOL> assert rating . times == <NUM_LIT:0> <EOL> assert rating . rated_at is None <EOL> rating = env . rate ( rating , [ ( WIN , <NUM_LIT:1000> ) ] ) <EOL> assert rating . times == <NUM_LIT:1> <EOL> assert rating . rated_at is not None <EOL> def test_fide ( ) : <EOL> """<STR_LIT>""" <EOL> assert fide25 . k_factor ( fide25 . create_rating ( <NUM_LIT> , <NUM_LIT:0> ) ) == <NUM_LIT> <EOL> assert fide25 . k_factor ( fide25 . create_rating ( <NUM_LIT> , <NUM_LIT:10> ) ) == <NUM_LIT> <EOL> assert fide25 . k_factor ( fide25 . create_rating ( <NUM_LIT:1000> , <NUM_LIT:20> ) ) == <NUM_LIT> <EOL> assert fide25 . k_factor ( fide25 . create_rating ( <NUM_LIT> , <NUM_LIT:30> ) ) == <NUM_LIT:15> <EOL> assert fide25 . k_factor ( fide25 . create_rating ( <NUM_LIT> , <NUM_LIT> ) ) == <NUM_LIT:15> <EOL> assert fide25 . k_factor ( fide25 . create_rating ( <NUM_LIT> , stable = True ) ) == <NUM_LIT:10> <EOL> assert fide25 . k_factor ( fide25 . create_rating ( <NUM_LIT> , stable = True ) ) == <NUM_LIT:10> <EOL> assert fide25 . k_factor ( fide25 . create_rating ( <NUM_LIT> , stable = True ) ) == <NUM_LIT:10> <EOL> assert fide25 . k_factor ( fide25 . create_rating ( <NUM_LIT> , stable = True ) ) == <NUM_LIT:10> <EOL> def test_uscf ( ) : <EOL> """<STR_LIT>""" <EOL> assert uscf . k_factor ( <NUM_LIT> ) == <NUM_LIT:32> <EOL> assert uscf . k_factor ( <NUM_LIT> ) == <NUM_LIT> <EOL> assert uscf . k_factor ( <NUM_LIT> ) == <NUM_LIT:16> <EOL> rating = <NUM_LIT> <EOL> series = [ ( LOSS , <NUM_LIT> ) , ( DRAW , <NUM_LIT> ) , ( WIN , <NUM_LIT> ) , ( WIN , <NUM_LIT> ) , <EOL> ( LOSS , <NUM_LIT> ) ] <EOL> assert round ( uscf . rate ( rating , series ) ) == <NUM_LIT> <EOL> def test_mcleopold ( ) : <EOL> """<STR_LIT>""" <EOL> mcleopold = Elo ( k_factor = <NUM_LIT> , initial = <NUM_LIT> ) <EOL> assert almost ( mcleopold . quality_1vs1 ( <NUM_LIT> , <NUM_LIT> ) ) == <NUM_LIT> <EOL> assert almost ( mcleopold . rate_1vs1 ( <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:2> ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_zookeeper ( ) : <EOL> zookeeper = Elo ( lambda r : <NUM_LIT:32> - math . pi / <NUM_LIT:2> * r . times , CountedRating ) <EOL> assert zookeeper . k_factor ( zookeeper . create_rating ( <NUM_LIT> , <NUM_LIT:0> ) ) == <NUM_LIT:32> <EOL> def test_moserware ( ) : <EOL> """<STR_LIT>""" <EOL> f25 = fide25 <EOL> assert almost ( f25 . rate_1vs1 ( <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:1> ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert almost ( f25 . rate_1vs1 ( <NUM_LIT> , <NUM_LIT> ) , <NUM_LIT:1> ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert almost ( f25 . rate_1vs1 ( <NUM_LIT> , <NUM_LIT> , drawn = True ) , <NUM_LIT:1> ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> _1200 = f25 . create_rating ( <NUM_LIT> , <NUM_LIT:30> ) <EOL> _2500 = f25 . create_rating ( <NUM_LIT> , stable = True ) <EOL> _2600 = f25 . create_rating ( <NUM_LIT> , stable = True ) <EOL> assert almost ( f25 . rate_1vs1 ( _1200 , _1200 ) ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert almost ( f25 . rate_1vs1 ( _1200 , _1200 , drawn = True ) ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert almost ( f25 . rate_1vs1 ( _2600 , _2500 ) ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert almost ( f25 . rate_1vs1 ( _2500 , _2600 ) ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert almost ( f25 . rate_1vs1 ( _2600 , _2500 , drawn = True ) ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_based_multiplayer_elo_calculator ( ) : <EOL> """<STR_LIT>""" <EOL> elo = Elo ( <NUM_LIT:10> ) <EOL> r1 = <NUM_LIT> <EOL> r2 = <NUM_LIT> <EOL> assert almost ( elo . expect ( r1 , r2 ) ) == <NUM_LIT> <EOL> assert almost ( elo . expect ( r2 , r1 ) ) == <NUM_LIT> <EOL> assert almost ( elo . rate_1vs1 ( r2 , r1 ) ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> r1 = <NUM_LIT> <EOL> r2 = <NUM_LIT:1000> <EOL> r3 = <NUM_LIT> <EOL> assert almost ( rate ( r1 , [ ( WIN , r2 ) , ( WIN , r3 ) ] ) ) == <NUM_LIT> <EOL> assert almost ( rate ( r2 , [ ( LOSS , r1 ) , ( WIN , r3 ) ] ) ) == <NUM_LIT> <EOL> assert almost ( rate ( r3 , [ ( LOSS , r1 ) , ( LOSS , r2 ) ] ) ) == <NUM_LIT> <EOL> r1 = fide25 . create_rating ( <NUM_LIT> , <NUM_LIT:0> ) <EOL> r2 = fide25 . create_rating ( <NUM_LIT> , <NUM_LIT:0> ) <EOL> assert fide25 . k_factor ( r1 ) == <NUM_LIT> <EOL> assert fide25 . k_factor ( r2 ) == <NUM_LIT> <EOL> assert almost ( map ( float , fide25 . rate_1vs1 ( r2 , r1 ) ) ) == ( <NUM_LIT> , <NUM_LIT> ) <EOL> r1 = fide25 . create_rating ( <NUM_LIT> , <NUM_LIT> ) <EOL> r2 = fide25 . create_rating ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert fide25 . k_factor ( r1 ) == <NUM_LIT:15> <EOL> assert fide25 . k_factor ( r2 ) == <NUM_LIT:15> <EOL> assert almost ( map ( float , fide25 . rate_1vs1 ( r2 , r1 ) ) ) == ( <NUM_LIT> , <NUM_LIT> ) </s>
