<s> from random import randint <EOL> import unittest <EOL> from pulsar . utils . structures import Skiplist <EOL> from pulsar . apps . test import populate <EOL> class TestSkiplist ( unittest . TestCase ) : <EOL> skiplist = Skiplist <EOL> def random ( self , size = <NUM_LIT:100> , score_min = - <NUM_LIT:10> , score_max = <NUM_LIT:10> ) : <EOL> scores = populate ( '<STR_LIT:float>' , size , score_min , score_max ) <EOL> data = populate ( '<STR_LIT:string>' , size , min_len = <NUM_LIT:5> , max_len = <NUM_LIT:10> ) <EOL> return self . skiplist ( zip ( scores , data ) ) <EOL> def test_extend ( self ) : <EOL> sl = self . skiplist ( ) <EOL> sl . extend ( [ ( <NUM_LIT> , '<STR_LIT>' ) , ( - <NUM_LIT:5> , '<STR_LIT:foo>' ) ] ) <EOL> self . assertEqual ( len ( sl ) , <NUM_LIT:2> ) <EOL> def test_count ( self ) : <EOL> sl = self . skiplist ( ) <EOL> self . assertEqual ( sl . count ( - <NUM_LIT:2> , <NUM_LIT:2> ) , <NUM_LIT:0> ) <EOL> sl . insert ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . assertEqual ( sl . count ( - <NUM_LIT:2> , <NUM_LIT:2> ) , <NUM_LIT:1> ) <EOL> sl = self . random ( ) <EOL> self . assertEqual ( sl . count ( float ( '<STR_LIT>' ) , float ( '<STR_LIT>' ) ) , <NUM_LIT:100> ) <EOL> n = <NUM_LIT:0> <EOL> for score , _ in sl : <EOL> n += int ( score >= - <NUM_LIT:5> and score <= <NUM_LIT:5> ) <EOL> self . assertEqual ( sl . count ( - <NUM_LIT:5> , <NUM_LIT:5> ) , n ) <EOL> sl = self . skiplist ( ( ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:2> , '<STR_LIT>' ) , ( <NUM_LIT:3> , '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( sl . count ( <NUM_LIT:1> , <NUM_LIT:2> ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( sl . count ( <NUM_LIT:1> , <NUM_LIT:2> , include_min = False ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( sl . count ( <NUM_LIT:1> , <NUM_LIT:2> , include_max = False ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( sl . count ( <NUM_LIT:1> , <NUM_LIT:2> , include_min = False , <EOL> include_max = False ) , <NUM_LIT:0> ) <EOL> def test_range_by_score ( self ) : <EOL> sl = self . skiplist ( ) <EOL> self . assertEqual ( tuple ( sl . range_by_score ( float ( '<STR_LIT>' ) , <NUM_LIT:5> ) ) , ( ) ) <EOL> sl . insert ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . assertEqual ( tuple ( sl . range_by_score ( - <NUM_LIT:3> , <NUM_LIT:5> ) ) , ( '<STR_LIT>' , ) ) <EOL> sl . insert ( <NUM_LIT> , '<STR_LIT:foo>' ) <EOL> sl . insert ( <NUM_LIT> , '<STR_LIT>' ) <EOL> self . assertEqual ( tuple ( sl . range_by_score ( <NUM_LIT> , <NUM_LIT> ) ) , ( '<STR_LIT>' , ) ) <EOL> self . assertEqual ( tuple ( sl . range_by_score ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , ( '<STR_LIT>' , '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( tuple ( sl . range_by_score ( <NUM_LIT:1> , <NUM_LIT:2> , include_min = False ) ) , <EOL> ( '<STR_LIT:foo>' , ) ) <EOL> self . assertEqual ( tuple ( sl . range_by_score ( <NUM_LIT:1> , <NUM_LIT> ) ) , ( '<STR_LIT>' , '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( tuple ( sl . range_by_score ( <NUM_LIT:1> , <NUM_LIT> , include_max = False ) ) , <EOL> ( '<STR_LIT>' , ) ) <EOL> self . assertEqual ( tuple ( sl . range_by_score ( - <NUM_LIT:1> , <NUM_LIT:2> , start = <NUM_LIT:1> ) ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( tuple ( sl . range_by_score ( - <NUM_LIT:1> , <NUM_LIT:2> , start = <NUM_LIT:1> , num = <NUM_LIT:1> ) ) , <EOL> ( '<STR_LIT>' , ) ) <EOL> def test_remove_range ( self ) : <EOL> sl = self . skiplist ( ) <EOL> self . assertEqual ( sl . remove_range ( <NUM_LIT:0> , <NUM_LIT:3> ) , <NUM_LIT:0> ) <EOL> sl . insert ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . assertEqual ( sl . remove_range ( <NUM_LIT:0> , <NUM_LIT:3> ) , <NUM_LIT:1> ) <EOL> sl = self . random ( <NUM_LIT:10> ) <EOL> li = list ( sl ) <EOL> lir = li [ : <NUM_LIT:4> ] + li [ <NUM_LIT:7> : ] <EOL> self . assertEqual ( sl . remove_range ( <NUM_LIT:4> , <NUM_LIT:7> ) , <NUM_LIT:3> ) <EOL> li2 = list ( sl ) <EOL> self . assertEqual ( li2 , lir ) <EOL> sl = self . random ( ) <EOL> li = list ( sl ) <EOL> lir = li [ : <NUM_LIT:5> ] + li [ - <NUM_LIT:8> : ] <EOL> self . assertEqual ( sl . remove_range ( <NUM_LIT:5> , - <NUM_LIT:8> ) , len ( li [ <NUM_LIT:5> : - <NUM_LIT:8> ] ) ) <EOL> li2 = list ( sl ) <EOL> self . assertEqual ( li2 , lir ) <EOL> sl = self . random ( ) <EOL> c = <NUM_LIT:0> <EOL> while sl : <EOL> c += <NUM_LIT:1> <EOL> index = randint ( <NUM_LIT:0> , len ( sl ) - <NUM_LIT:1> ) <EOL> self . assertEqual ( sl . remove_range ( index , index + <NUM_LIT:1> ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( c , <NUM_LIT:100> ) <EOL> def test_remove_range_by_score ( self ) : <EOL> sl = self . skiplist ( ) <EOL> self . assertEqual ( sl . remove_range_by_score ( <NUM_LIT:0> , <NUM_LIT:3> ) , <NUM_LIT:0> ) <EOL> sl . insert ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . assertEqual ( sl . remove_range_by_score ( <NUM_LIT:0> , <NUM_LIT:3> ) , <NUM_LIT:1> ) </s>
