func TestMerger(t *testing.T) { // Use 3 reports to check the pair-wise merging in SmartMerger report1 := report.MakeReport() report1.Endpoint.AddNode(report.MakeNode("foo")) report2 := report.MakeReport() report2.Endpoint.AddNode(report.MakeNode("bar")) report3 := report.MakeReport() report3.Endpoint.AddNode(report.MakeNode("baz")) reports := []report.Report{ report1, report2, report3, } want := report.MakeReport() want.Endpoint. AddNode(report.MakeNode("foo")). AddNode(report.MakeNode("bar")). AddNode(report.MakeNode("baz")) for _, merger := range []app.Merger{app.MakeDumbMerger(), app.NewSmartMerger()} { // Test the empty list case if have := merger.Merge([]report.Report{}); !reflect.DeepEqual(have, report.MakeReport()) { t.Errorf("Bad merge: %s", test.Diff(have, want)) } if have := merger.Merge(reports); !reflect.DeepEqual(have, want) { t.Errorf("Bad merge: %s", test.Diff(have, want)) } // Repeat the above test to ensure caching works if have := merger.Merge(reports); !reflect.DeepEqual(have, want) { t.Errorf("Bad merge: %s", test.Diff(have, want)) } } }
func BenchmarkDumbMerger(b *testing.B) { benchmarkMerger(b, app.MakeDumbMerger()) }