@@ -2392,31 +2392,47 @@ impl Cache {
2392
2392
////////////////////////////////////////////////////////////////////////////////
2393
2393
#[ cfg( test) ]
2394
2394
mod tests {
2395
+ use nautilus_model:: data:: quote:: stubs:: * ;
2396
+ use nautilus_model:: data:: quote:: QuoteTick ;
2397
+ use nautilus_model:: instruments:: { currency_pair:: CurrencyPair , stubs:: * } ;
2395
2398
use rstest:: * ;
2396
2399
2397
2400
use super :: Cache ;
2398
2401
2399
2402
#[ rstest]
2400
- fn test_reset_index ( ) {
2403
+ fn test_build_index_when_empty ( ) {
2404
+ let mut cache = Cache :: default ( ) ;
2405
+ cache. build_index ( ) ;
2406
+ }
2407
+
2408
+ #[ rstest]
2409
+ fn test_clear_index_when_empty ( ) {
2401
2410
let mut cache = Cache :: default ( ) ;
2402
2411
cache. clear_index ( ) ;
2403
2412
}
2404
2413
2405
2414
#[ rstest]
2406
- fn test_reset ( ) {
2415
+ fn test_reset_when_empty ( ) {
2407
2416
let mut cache = Cache :: default ( ) ;
2408
2417
cache. reset ( ) ;
2409
2418
}
2410
2419
2411
2420
#[ rstest]
2412
- fn test_dispose ( ) {
2421
+ fn test_dispose_when_empty ( ) {
2413
2422
let cache = Cache :: default ( ) ;
2414
2423
let result = cache. dispose ( ) ;
2415
2424
assert ! ( result. is_ok( ) ) ;
2416
2425
}
2417
2426
2418
2427
#[ rstest]
2419
- fn test_flushdb ( ) {
2428
+ fn test_flush_db_when_empty ( ) {
2429
+ let cache = Cache :: default ( ) ;
2430
+ let result = cache. flush_db ( ) ;
2431
+ assert ! ( result. is_ok( ) ) ;
2432
+ }
2433
+
2434
+ #[ rstest]
2435
+ fn test_check_residuals_when_empty ( ) {
2420
2436
let cache = Cache :: default ( ) ;
2421
2437
let result = cache. flush_db ( ) ;
2422
2438
assert ! ( result. is_ok( ) ) ;
@@ -2459,8 +2475,9 @@ mod tests {
2459
2475
}
2460
2476
2461
2477
#[ rstest]
2462
- fn test_get_general_when_no_value ( ) {
2478
+ fn test_get_general_when_empty ( ) {
2463
2479
let cache = Cache :: default ( ) ;
2480
+
2464
2481
let result = cache. get ( "A" ) . unwrap ( ) ;
2465
2482
assert_eq ! ( result, None ) ;
2466
2483
}
@@ -2476,4 +2493,43 @@ mod tests {
2476
2493
let result = cache. get ( key) . unwrap ( ) ;
2477
2494
assert_eq ! ( result, Some ( & value. as_slice( ) ) . copied( ) ) ;
2478
2495
}
2496
+
2497
+ #[ rstest]
2498
+ fn test_quote_tick_when_empty ( audusd_sim : CurrencyPair ) {
2499
+ let cache = Cache :: default ( ) ;
2500
+
2501
+ let result = cache. quote_tick ( & audusd_sim. id ) ;
2502
+ assert_eq ! ( result, None ) ;
2503
+ }
2504
+
2505
+ #[ rstest]
2506
+ fn test_quote_tick_when_some ( quote_tick_audusd_sim : QuoteTick ) {
2507
+ let mut cache = Cache :: default ( ) ;
2508
+ cache. add_quote ( quote_tick_audusd_sim) . unwrap ( ) ;
2509
+
2510
+ let result = cache. quote_tick ( & quote_tick_audusd_sim. instrument_id ) ;
2511
+ assert_eq ! ( result, Some ( & quote_tick_audusd_sim) ) ;
2512
+ }
2513
+
2514
+ #[ rstest]
2515
+ fn test_quote_ticks_when_empty ( audusd_sim : CurrencyPair ) {
2516
+ let cache = Cache :: default ( ) ;
2517
+
2518
+ let result = cache. quote_ticks ( & audusd_sim. id ) ;
2519
+ assert_eq ! ( result, None ) ;
2520
+ }
2521
+
2522
+ #[ rstest]
2523
+ fn test_quote_ticks_when_some ( quote_tick_audusd_sim : QuoteTick ) {
2524
+ let mut cache = Cache :: default ( ) ;
2525
+ let quotes = vec ! [
2526
+ quote_tick_audusd_sim,
2527
+ quote_tick_audusd_sim,
2528
+ quote_tick_audusd_sim,
2529
+ ] ;
2530
+ cache. add_quotes ( & quotes) . unwrap ( ) ;
2531
+
2532
+ let result = cache. quote_ticks ( & quote_tick_audusd_sim. instrument_id ) ;
2533
+ assert_eq ! ( result, Some ( quotes) ) ;
2534
+ }
2479
2535
}
0 commit comments