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.

37 lines
645 B

  1. package mem
  2. import (
  3. "testing"
  4. )
  5. func TestAllocateFree(t *testing.T) {
  6. buf := Allocate(12)
  7. Free(buf)
  8. if cap(buf) != min_size {
  9. t.Errorf("min size error allocated capacity=%d", cap(buf))
  10. }
  11. if len(buf) != 12 {
  12. t.Errorf("size error")
  13. }
  14. buf = Allocate(4883)
  15. Free(buf)
  16. if cap(buf) != 1024<<bitCount(4883) {
  17. t.Errorf("min size error allocated capacity=%d", cap(buf))
  18. }
  19. if len(buf) != 4883 {
  20. t.Errorf("size error")
  21. }
  22. }
  23. func TestBitCount(t *testing.T) {
  24. count := bitCount(12)
  25. if count != 0 {
  26. t.Errorf("bitCount error count=%d", count)
  27. }
  28. if count != bitCount(min_size) {
  29. t.Errorf("bitCount error count=%d", count)
  30. }
  31. }