z_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package concurrent
  2. import (
  3. "log"
  4. "testing"
  5. )
  6. func TestQueue(t *testing.T) {
  7. q := NewQueue()
  8. q.Push("one", "two", "three")
  9. q.Push("four")
  10. q.Push("five")
  11. t.Log(q)
  12. for {
  13. if val, check := q.Pop(); check {
  14. t.Log(val, q.Size())
  15. } else {
  16. break
  17. }
  18. }
  19. t.Log(q)
  20. }
  21. func showList(l *List) {
  22. }
  23. func TestList(t *testing.T) {
  24. l := NewList()
  25. log.Println(l)
  26. for i := 0; i < 10; i++ {
  27. l.PushFront(i)
  28. }
  29. log.Println(l.Slice(), l.Size())
  30. elem := l.Index(0)
  31. log.Println(elem)
  32. l.Remove(elem)
  33. log.Println(l.Slice())
  34. for l.Size() > 0 {
  35. l.Remove(l.First())
  36. log.Println(l.Slice(), l.Size())
  37. }
  38. log.Println(l.first, l.last)
  39. l.PushBack(100)
  40. log.Println(l.Slice(), l.Size(), l.first, l.last)
  41. sl := make([]interface{}, 10)
  42. for i := range sl {
  43. sl[i] = i * 100
  44. }
  45. log.Println(sl)
  46. l = ListFromSlise(sl)
  47. log.Println(l.Slice())
  48. elem = l.Search(500)
  49. log.Println(elem)
  50. elem = l.Search(1500)
  51. log.Println(1500, "search", elem)
  52. elem, added := l.PushBackIfNotExists(500)
  53. log.Println(500, elem, added)
  54. elem, added = l.PushBackIfNotExists(1500)
  55. log.Println(1500, elem, added)
  56. }