slicesutils_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package slicesutils_test
  2. import (
  3. "testing"
  4. "wkla.no-ip.biz/gogs/Willie/MsgService/MessageService/internal/slicesutils"
  5. )
  6. func TestContains(t *testing.T) {
  7. mySlice := []string{"Willie", "Arthur", "Till"}
  8. value := slicesutils.Contains(mySlice, "Willie")
  9. if value != true {
  10. t.Errorf("Willie was not in the slice")
  11. }
  12. }
  13. func TestRemoveString(t *testing.T) {
  14. mySlice := []string{"Willie", "Arthur", "Till"}
  15. value := slicesutils.RemoveString(mySlice, "Willie")
  16. if slicesutils.Contains(value, "Willie") {
  17. t.Errorf("Willie was not removed from the slice")
  18. }
  19. value = slicesutils.RemoveString(mySlice, "Herman")
  20. if len(value) != 3 {
  21. t.Errorf("slice not unchanged")
  22. }
  23. }
  24. func TestRemove(t *testing.T) {
  25. mySlice := []string{"Willie", "Arthur", "Till"}
  26. value := slicesutils.Remove(mySlice, 0)
  27. if slicesutils.Contains(value, "Willie") {
  28. t.Errorf("Willie was not removed from the slice")
  29. }
  30. }
  31. func TestFind(t *testing.T) {
  32. mySlice := []string{"Willie", "Arthur", "Till"}
  33. value := slicesutils.Find(mySlice, "Willie")
  34. if value != 0 {
  35. t.Errorf("Willie was not found in the slice: index: %d", value)
  36. }
  37. value = slicesutils.Find(mySlice, "Arthur")
  38. if value != 1 {
  39. t.Errorf("Arthur was not found in the slice: index: %d", value)
  40. }
  41. value = slicesutils.Find(mySlice, "Till")
  42. if value != 2 {
  43. t.Errorf("Till was not found in the slice: index: %d", value)
  44. }
  45. value = slicesutils.Find(mySlice, "till")
  46. if value >= 0 {
  47. t.Errorf("till was wrongly found in the slice: index: %d", value)
  48. }
  49. value = slicesutils.Find(mySlice, "Herman")
  50. if value >= 0 {
  51. t.Errorf("Herman was wrongly found in the slice: index: %d", value)
  52. }
  53. }