MCPcopy
hub / github.com/go-gorm/gorm / TestLRURemoveOldest

Function TestLRURemoveOldest

tests/lru_test.go:454–522  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

452}
453
454func TestLRURemoveOldest(t *testing.T) {
455 lc := lru.NewLRU[string, string](2, nil, 0)
456
457 if lc.Cap() != 2 {
458 t.Fatalf("expect cap is 2")
459 }
460
461 k, v, ok := lc.RemoveOldest()
462 if k != "" {
463 t.Fatalf("should be empty")
464 }
465 if v != "" {
466 t.Fatalf("should be empty")
467 }
468 if ok {
469 t.Fatalf("should be false")
470 }
471
472 ok = lc.Remove("non_existent")
473 if ok {
474 t.Fatalf("should be false")
475 }
476
477 lc.Add("key1", "val1")
478 if lc.Len() != 1 {
479 t.Fatalf("length differs from expected")
480 }
481
482 v, ok = lc.Get("key1")
483 if !ok {
484 t.Fatalf("should be true")
485 }
486 if v != "val1" {
487 t.Fatalf("value differs from expected")
488 }
489
490 if !reflect.DeepEqual(lc.Keys(), []string{"key1"}) {
491 t.Fatalf("value differs from expected")
492 }
493 if lc.Len() != 1 {
494 t.Fatalf("length differs from expected")
495 }
496
497 lc.Add("key2", "val2")
498 if !reflect.DeepEqual(lc.Keys(), []string{"key1", "key2"}) {
499 t.Fatalf("value differs from expected")
500 }
501 if lc.Len() != 2 {
502 t.Fatalf("length differs from expected")
503 }
504
505 k, v, ok = lc.RemoveOldest()
506 if k != "key1" {
507 t.Fatalf("value differs from expected")
508 }
509 if v != "val1" {
510 t.Fatalf("value differs from expected")
511 }

Callers

nothing calls this directly

Calls 8

NewLRUFunction · 0.92
CapMethod · 0.80
RemoveOldestMethod · 0.80
AddMethod · 0.80
LenMethod · 0.80
GetMethod · 0.65
KeysMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected