You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.2 KiB

  1. package storage
  2. import (
  3. "testing"
  4. )
  5. func TestXYZ(t *testing.T) {
  6. m := NewCompactMap()
  7. for i := uint32(0); i < 100*batch; i += 2 {
  8. m.Set(Key(i), i, i)
  9. }
  10. for i := uint32(0); i < 100*batch; i += 37 {
  11. m.Delete(Key(i))
  12. }
  13. for i := uint32(0); i < 10*batch; i += 3 {
  14. m.Set(Key(i), i+11, i+5)
  15. }
  16. // for i := uint32(0); i < 100; i++ {
  17. // if v := m.Get(Key(i)); v != nil {
  18. // glog.V(4).Infoln(i, "=", v.Key, v.Offset, v.Size)
  19. // }
  20. // }
  21. for i := uint32(0); i < 10*batch; i++ {
  22. v, ok := m.Get(Key(i))
  23. if i%3 == 0 {
  24. if !ok {
  25. t.Fatal("key", i, "missing!")
  26. }
  27. if v.Size != i+5 {
  28. t.Fatal("key", i, "size", v.Size)
  29. }
  30. } else if i%37 == 0 {
  31. if ok && v.Size > 0 {
  32. t.Fatal("key", i, "should have been deleted needle value", v)
  33. }
  34. } else if i%2 == 0 {
  35. if v.Size != i {
  36. t.Fatal("key", i, "size", v.Size)
  37. }
  38. }
  39. }
  40. for i := uint32(10 * batch); i < 100*batch; i++ {
  41. v, ok := m.Get(Key(i))
  42. if i%37 == 0 {
  43. if ok && v.Size > 0 {
  44. t.Fatal("key", i, "should have been deleted needle value", v)
  45. }
  46. } else if i%2 == 0 {
  47. if v == nil {
  48. t.Fatal("key", i, "missing")
  49. }
  50. if v.Size != i {
  51. t.Fatal("key", i, "size", v.Size)
  52. }
  53. }
  54. }
  55. }