diff_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) 2015 Arista Networks, Inc.
  2. // Use of this source code is governed by the Apache License 2.0
  3. // that can be found in the COPYING file.
  4. package test
  5. import (
  6. "testing"
  7. )
  8. func TestDiff(t *testing.T) {
  9. saved := prettyPrintDepth
  10. prettyPrintDepth = 4
  11. testcases := getDeepEqualTests(t)
  12. for _, test := range testcases {
  13. diff := Diff(test.a, test.b)
  14. if test.diff != diff {
  15. t.Errorf("Diff returned different diff\n"+
  16. "Diff : %q\nExpected: %q\nFor %#v == %#v",
  17. diff, test.diff, test.a, test.b)
  18. }
  19. }
  20. prettyPrintDepth = saved
  21. }
  22. var benchEqual = map[string]interface{}{
  23. "foo": "bar",
  24. "bar": map[string]interface{}{
  25. "foo": "bar",
  26. "bar": map[string]interface{}{
  27. "foo": "bar",
  28. },
  29. "foo2": []uint32{1, 2, 5, 78, 23, 236, 346, 3456},
  30. },
  31. }
  32. var benchDiff = map[string]interface{}{
  33. "foo": "bar",
  34. "bar": map[string]interface{}{
  35. "foo": "bar",
  36. "bar": map[string]interface{}{
  37. "foo": "bar",
  38. },
  39. "foo2": []uint32{1, 2, 5, 78, 23, 236, 346, 3457},
  40. },
  41. }
  42. func BenchmarkEqualDeepEqual(b *testing.B) {
  43. for i := 0; i < b.N; i++ {
  44. DeepEqual(benchEqual, benchEqual)
  45. }
  46. }
  47. func BenchmarkEqualDiff(b *testing.B) {
  48. for i := 0; i < b.N; i++ {
  49. Diff(benchEqual, benchEqual)
  50. }
  51. }
  52. func BenchmarkDiffDeepEqual(b *testing.B) {
  53. for i := 0; i < b.N; i++ {
  54. DeepEqual(benchEqual, benchDiff)
  55. }
  56. }
  57. func BenchmarkDiffDiff(b *testing.B) {
  58. for i := 0; i < b.N; i++ {
  59. Diff(benchEqual, benchDiff)
  60. }
  61. }