<s> import numpy <EOL> import scipy <EOL> import unittest <EOL> from mockredis import MockRedis as Redis <EOL> from nearpy . storage import MemoryStorage , RedisStorage <EOL> class TestStorage ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . memory = MemoryStorage ( ) <EOL> self . redis_object = Redis ( ) <EOL> self . redis_storage = RedisStorage ( self . redis_object ) <EOL> def test_memory_storage ( self ) : <EOL> x = numpy . random . randn ( <NUM_LIT:100> , <NUM_LIT:1> ) <EOL> bucket_key = '<STR_LIT>' <EOL> x_data = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . memory . store_vector ( '<STR_LIT>' , bucket_key , x , x_data ) <EOL> X = self . memory . get_bucket ( '<STR_LIT>' , bucket_key ) <EOL> self . assertEqual ( len ( X ) , <NUM_LIT:1> ) <EOL> y = X [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> y_data = X [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> self . assertEqual ( len ( y ) , len ( x ) ) <EOL> self . assertEqual ( type ( x ) , type ( y ) ) <EOL> for k in range ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( y [ k ] , x [ k ] ) <EOL> self . assertEqual ( type ( y_data ) , type ( x_data ) ) <EOL> self . assertEqual ( len ( y_data ) , len ( x_data ) ) <EOL> for k in range ( <NUM_LIT:3> ) : <EOL> self . assertEqual ( y_data [ k ] , x_data [ k ] ) <EOL> self . memory . clean_all_buckets ( ) <EOL> self . assertEqual ( self . memory . get_bucket ( '<STR_LIT>' , bucket_key ) , [ ] ) <EOL> def test_redis_storage ( self ) : <EOL> self . redis_storage . clean_all_buckets ( ) <EOL> x = numpy . random . randn ( <NUM_LIT:100> , <NUM_LIT:1> ) <EOL> bucket_key = '<STR_LIT>' <EOL> x_data = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . redis_storage . store_vector ( '<STR_LIT>' , bucket_key , x , x_data ) <EOL> X = self . redis_storage . get_bucket ( '<STR_LIT>' , bucket_key ) <EOL> self . assertEqual ( len ( X ) , <NUM_LIT:1> ) <EOL> y = X [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> y_data = X [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> self . assertEqual ( len ( y ) , len ( x ) ) <EOL> self . assertEqual ( type ( x ) , type ( y ) ) <EOL> for k in range ( <NUM_LIT:100> ) : <EOL> self . assertEqual ( y [ k ] , x [ k ] ) <EOL> self . assertEqual ( type ( y_data ) , type ( x_data ) ) <EOL> self . assertEqual ( len ( y_data ) , len ( x_data ) ) <EOL> for k in range ( <NUM_LIT:3> ) : <EOL> self . assertEqual ( y_data [ k ] , x_data [ k ] ) <EOL> self . redis_storage . clean_all_buckets ( ) <EOL> self . assertEqual ( self . redis_storage . get_bucket ( '<STR_LIT>' , <EOL> bucket_key ) , [ ] ) <EOL> def test_redis_storage_sparse ( self ) : <EOL> self . redis_storage . clean_all_buckets ( ) <EOL> x = scipy . sparse . rand ( <NUM_LIT:100> , <NUM_LIT:1> , density = <NUM_LIT:0.1> ) <EOL> bucket_key = '<STR_LIT>' <EOL> x_data = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . redis_storage . store_vector ( '<STR_LIT>' , bucket_key , x , x_data ) <EOL> X = self . redis_storage . get_bucket ( '<STR_LIT>' , bucket_key ) <EOL> self . assertEqual ( len ( X ) , <NUM_LIT:1> ) <EOL> y = X [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> y_data = X [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> self . assertEqual ( type ( x ) , type ( y ) ) <EOL> self . assertEqual ( x . shape [ <NUM_LIT:0> ] , y . shape [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( x . shape [ <NUM_LIT:1> ] , y . shape [ <NUM_LIT:1> ] ) <EOL> self . assertTrue ( ( y - x ) . sum ( ) == <NUM_LIT:0.0> ) <EOL> self . assertEqual ( type ( y_data ) , type ( x_data ) ) <EOL> self . assertEqual ( len ( y_data ) , len ( x_data ) ) <EOL> for k in range ( <NUM_LIT:3> ) : <EOL> self . assertEqual ( y_data [ k ] , x_data [ k ] ) <EOL> self . redis_storage . clean_all_buckets ( ) <EOL> self . assertEqual ( self . redis_storage . get_bucket ( '<STR_LIT>' , <EOL> bucket_key ) , [ ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
