<s> import unittest <EOL> from rx . internal import PriorityQueue <EOL> class TestItem ( ) : <EOL> def __init__ ( self , value , label = None ) : <EOL> self . value = value <EOL> self . label = label <EOL> def __str__ ( self ) : <EOL> if self . label : <EOL> return "<STR_LIT>" % ( self . value , self . label ) <EOL> else : <EOL> return "<STR_LIT:%s>" % self . value <EOL> def __eq__ ( self , other ) : <EOL> return self . value == other . value <EOL> def __lt__ ( self , other ) : <EOL> return self . value < other . value <EOL> def __gt__ ( self , other ) : <EOL> return self . value > other . value <EOL> def assert_equal ( self , other ) : <EOL> assert ( self . value == other . value ) <EOL> assert ( self . label == other . label ) <EOL> class TestPriorityQueue ( unittest . TestCase ) : <EOL> def test_priorityqueue_empty ( self ) : <EOL> """<STR_LIT>""" <EOL> p = PriorityQueue ( ) <EOL> assert ( len ( p ) == <NUM_LIT:0> ) <EOL> assert ( p . items == [ ] ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . dequeue ( ) <EOL> assert ( len ( p ) == <NUM_LIT:0> ) <EOL> def test_priorityqueue_length ( self ) : <EOL> """<STR_LIT>""" <EOL> p = PriorityQueue ( ) <EOL> assert ( len ( p ) == <NUM_LIT:0> ) <EOL> for n in range ( <NUM_LIT> ) : <EOL> p . enqueue ( n ) <EOL> assert ( len ( p ) == <NUM_LIT> ) <EOL> p . dequeue ( ) <EOL> assert ( len ( p ) == <NUM_LIT> ) <EOL> p . remove ( <NUM_LIT:10> ) <EOL> assert ( len ( p ) == <NUM_LIT> ) <EOL> for n in range ( len ( p ) ) : <EOL> p . dequeue ( ) <EOL> assert ( len ( p ) == <NUM_LIT:0> ) <EOL> def test_priorityqueue_enqueue_dequeue ( self ) : <EOL> """<STR_LIT>""" <EOL> p = PriorityQueue ( ) <EOL> self . assertRaises ( IndexError , p . dequeue ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> assert ( [ p . dequeue ( ) , p . dequeue ( ) , p . dequeue ( ) ] == [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_priorityqueue_sort_stability ( self ) : <EOL> """<STR_LIT>""" <EOL> p = PriorityQueue ( ) <EOL> p . enqueue ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> p . enqueue ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> p . enqueue ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> p . enqueue ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> p . enqueue ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> assert ( len ( p ) == <NUM_LIT:5> ) <EOL> p . dequeue ( ) . assert_equal ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> p . dequeue ( ) . assert_equal ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> p . dequeue ( ) . assert_equal ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> p . dequeue ( ) . assert_equal ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> p . dequeue ( ) . assert_equal ( TestItem ( <NUM_LIT> , "<STR_LIT>" ) ) <EOL> def test_priorityqueue_remove ( self ) : <EOL> """<STR_LIT>""" <EOL> p = PriorityQueue ( ) <EOL> assert ( p . remove ( <NUM_LIT> ) == False ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> assert ( p . remove ( <NUM_LIT> ) == True ) <EOL> assert ( [ p . dequeue ( ) , p . dequeue ( ) ] == [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> assert ( p . remove ( <NUM_LIT> ) == True ) <EOL> assert ( [ p . dequeue ( ) , p . dequeue ( ) ] == [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> assert ( p . remove ( <NUM_LIT> ) == True ) <EOL> assert ( [ p . dequeue ( ) , p . dequeue ( ) ] == [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_priorityqueue_peek ( self ) : <EOL> """<STR_LIT>""" <EOL> p = PriorityQueue ( ) <EOL> self . assertRaises ( IndexError , p . peek ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> assert ( p . peek ( ) == <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> assert ( p . peek ( ) == <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> assert ( p . peek ( ) == <NUM_LIT> ) <EOL> def test_priorityqueue_remove_at ( self ) : <EOL> """<STR_LIT>""" <EOL> p = PriorityQueue ( ) <EOL> self . assertRaises ( IndexError , p . remove_at , <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> p . enqueue ( <NUM_LIT> ) <EOL> assert ( p . remove_at ( <NUM_LIT:2> ) == <NUM_LIT> ) <EOL> assert ( p . remove_at ( <NUM_LIT:1> ) == <NUM_LIT> ) <EOL> assert ( p . remove_at ( <NUM_LIT:0> ) == <NUM_LIT> ) <EOL> self . assertRaises ( IndexError , p . remove_at , <NUM_LIT:0> ) </s>
