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.

77 lines
1.6 KiB

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