bytes_test.go 666 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package compare_test
  2. import (
  3. "testing"
  4. . "v2ray.com/core/common/compare"
  5. )
  6. func TestBytesEqual(t *testing.T) {
  7. testCases := []struct {
  8. Input1 []byte
  9. Input2 []byte
  10. Result bool
  11. }{
  12. {
  13. Input1: []byte{},
  14. Input2: []byte{1},
  15. Result: false,
  16. },
  17. {
  18. Input1: nil,
  19. Input2: []byte{},
  20. Result: true,
  21. },
  22. {
  23. Input1: []byte{1},
  24. Input2: []byte{1},
  25. Result: true,
  26. },
  27. {
  28. Input1: []byte{1, 2},
  29. Input2: []byte{1, 3},
  30. Result: false,
  31. },
  32. }
  33. for _, testCase := range testCases {
  34. cmp := BytesEqual(testCase.Input1, testCase.Input2)
  35. if cmp != testCase.Result {
  36. t.Errorf("unexpected result %v from %v", cmp, testCase)
  37. }
  38. }
  39. }