safemap_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2014 beego Author. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package utils
  15. import "testing"
  16. var safeMap *BeeMap
  17. func TestNewBeeMap(t *testing.T) {
  18. safeMap = NewBeeMap()
  19. if safeMap == nil {
  20. t.Fatal("expected to return non-nil BeeMap", "got", safeMap)
  21. }
  22. }
  23. func TestSet(t *testing.T) {
  24. if ok := safeMap.Set("astaxie", 1); !ok {
  25. t.Error("expected", true, "got", false)
  26. }
  27. }
  28. func TestCheck(t *testing.T) {
  29. if exists := safeMap.Check("astaxie"); !exists {
  30. t.Error("expected", true, "got", false)
  31. }
  32. }
  33. func TestGet(t *testing.T) {
  34. if val := safeMap.Get("astaxie"); val.(int) != 1 {
  35. t.Error("expected value", 1, "got", val)
  36. }
  37. }
  38. func TestDelete(t *testing.T) {
  39. safeMap.Delete("astaxie")
  40. if exists := safeMap.Check("astaxie"); exists {
  41. t.Error("expected element to be deleted")
  42. }
  43. }
  44. func TestCount(t *testing.T) {
  45. if count := safeMap.Count(); count != 0 {
  46. t.Error("expected count to be", 0, "got", count)
  47. }
  48. }