From d66c9f883fd36e007944b71650646d083e1d9db8 Mon Sep 17 00:00:00 2001 From: Carlos Diaz-Padron Date: Tue, 29 Jul 2014 10:26:50 -0700 Subject: [PATCH] Fix TestWriteDot random order error --- digraph/graphviz_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/digraph/graphviz_test.go b/digraph/graphviz_test.go index fce1ebb6f..69e4ebb89 100644 --- a/digraph/graphviz_test.go +++ b/digraph/graphviz_test.go @@ -24,7 +24,27 @@ b -> e actual := strings.TrimSpace(string(buf.Bytes())) expected := strings.TrimSpace(writeDotStr) - if actual != expected { + + actualLines := strings.Split(actual, "\n") + expectedLines := strings.Split(expected, "\n") + + if actualLines[0] != expectedLines[0] || + actualLines[len(actualLines)-1] != expectedLines[len(expectedLines)-1] || + len(actualLines) != len(expectedLines) { + t.Fatalf("bad: %s", actual) + } + + count := 0 + for _, el := range expectedLines[1 : len(expectedLines)-1] { + for _, al := range actualLines[1 : len(actualLines)-1] { + if el == al { + count++ + break + } + } + } + + if count != len(expectedLines)-2 { t.Fatalf("bad: %s", actual) } }