base_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 Yunion
  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 tasks
  15. import (
  16. "testing"
  17. )
  18. func TestQueue(t *testing.T) {
  19. type test struct {
  20. queue *Queue
  21. expected string
  22. }
  23. q123 := NewQueue().Append("1").Append("2").Append("3")
  24. q123Pop := NewQueue().Append("1").Append("2").Append("3")
  25. q123Pop.Pop()
  26. qEmptyPop := NewQueue().Append("1").Append("2")
  27. qEmptyPop.Pop()
  28. qEmptyPop.Pop()
  29. qEmptyPop.Pop()
  30. tests := map[string]test{
  31. "Empty queue": {
  32. queue: NewQueue(),
  33. expected: "[]",
  34. },
  35. "Queue append": {
  36. queue: q123,
  37. expected: "[1 2 3]",
  38. },
  39. "Queue pop": {
  40. queue: q123Pop,
  41. expected: "[2 3]",
  42. },
  43. "Queue pop to empty": {
  44. queue: qEmptyPop,
  45. expected: "[]",
  46. },
  47. }
  48. for name, testCase := range tests {
  49. output := testCase.queue.String()
  50. expected := testCase.expected
  51. if output != expected {
  52. t.Errorf("TestCase %q failed, output: %v, expected: %v", name, output, expected)
  53. }
  54. }
  55. }