<s> from random import randint <EOL> from stdnet . utils import test <EOL> from stdnet . utils . zset import zset <EOL> class TestPythonZset ( test . TestCase ) : <EOL> def test_add ( self ) : <EOL> s = zset ( ) <EOL> s . add ( <NUM_LIT:3> , '<STR_LIT>' ) <EOL> s . add ( <NUM_LIT:4> , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( s ) , <NUM_LIT:2> ) <EOL> s . add ( - <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( s ) , <NUM_LIT:2> ) <EOL> data = list ( s ) <EOL> self . assertEqual ( data , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_rank ( self ) : <EOL> s = zset ( ) <EOL> s . add ( <NUM_LIT:3> , '<STR_LIT>' ) <EOL> s . add ( <NUM_LIT:4> , '<STR_LIT>' ) <EOL> s . add ( <NUM_LIT:2> , '<STR_LIT:foo>' ) <EOL> s . add ( <NUM_LIT:20> , '<STR_LIT>' ) <EOL> s . add ( - <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( s ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( s . rank ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( s . rank ( '<STR_LIT:foo>' ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( s . rank ( '<STR_LIT>' ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( s . rank ( '<STR_LIT>' ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( s . rank ( '<STR_LIT>' ) , None ) <EOL> def test_update ( self ) : <EOL> string = test . populate ( '<STR_LIT:string>' , size = <NUM_LIT:100> ) <EOL> values = test . populate ( '<STR_LIT:float>' , size = <NUM_LIT:100> ) <EOL> s = zset ( ) <EOL> s . update ( zip ( values , string ) ) <EOL> self . assertTrue ( s ) <EOL> prev = None <EOL> for score , _ in s . items ( ) : <EOL> if prev is not None : <EOL> self . assertTrue ( score >= prev ) <EOL> prev = score <EOL> return s <EOL> def test_remove ( self ) : <EOL> s = self . test_update ( ) <EOL> values = list ( s ) <EOL> while values : <EOL> index = randint ( <NUM_LIT:0> , len ( values ) - <NUM_LIT:1> ) <EOL> val = values . pop ( index ) <EOL> self . assertTrue ( val in s ) <EOL> self . assertNotEqual ( s . remove ( val ) , None ) <EOL> self . assertFalse ( val in s ) <EOL> self . assertFalse ( s ) </s>
