gods_test.go 1.1 KB

123456789101112131415161718192021222324252627282930
  1. package gods
  2. import (
  3. "github.com/emirpasic/gods/lists/arraylist"
  4. "github.com/emirpasic/gods/utils"
  5. "testing"
  6. )
  7. func TestArrayList(t *testing.T) {
  8. list := arraylist.New()
  9. list.Add("a") // ["a"]
  10. list.Add("c", "b") // ["a","c","b"]
  11. list.Sort(utils.StringComparator) // ["a","b","c"]
  12. _, _ = list.Get(0) // "a",true
  13. _, _ = list.Get(100) // nil,false
  14. _ = list.Contains("a", "b", "c") // true
  15. _ = list.Contains("a", "b", "c", "d") // false
  16. list.Swap(0, 1) // ["b","a",c"]
  17. list.Remove(2) // ["b","a"]
  18. list.Remove(1) // ["b"]
  19. list.Remove(0) // []
  20. list.Remove(0) // [] (ignored)
  21. _ = list.Empty() // true
  22. _ = list.Size() // 0
  23. list.Add("a") // ["a"]
  24. list.Clear() // []
  25. list.Insert(0, "b") // ["b"]
  26. list.Insert(0, "a") // ["a","b"]
  27. }