From 28978858033244093191c763dd7b8597faedae35 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 28 Aug 2016 00:51:54 +0200 Subject: Solve bracket --- go/bracket-push/bracket_push_test.go | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 go/bracket-push/bracket_push_test.go (limited to 'go/bracket-push/bracket_push_test.go') diff --git a/go/bracket-push/bracket_push_test.go b/go/bracket-push/bracket_push_test.go new file mode 100644 index 0000000..6f92877 --- /dev/null +++ b/go/bracket-push/bracket_push_test.go @@ -0,0 +1,77 @@ +package brackets + +import ( + "testing" +) + +const targetTestVersion = 3 + +var testCases = []struct { + input string + expected bool +}{ + { + input: "", + expected: true, + }, + { + input: "{}", + expected: true, + }, + { + input: "{{", + expected: false, + }, + { + input: "}{", + expected: false, + }, + { + input: "{}[]", + expected: true, + }, + { + input: "{[]}", + expected: true, + }, + { + input: "{[}]", + expected: false, + }, + { + input: "{[)][]}", + expected: false, + }, + { + input: "{[]([()])}", + expected: true, + }, +} + +func TestBracket(t *testing.T) { + for _, tt := range testCases { + actual, err := Bracket(tt.input) + // We don't expect errors for any of the test cases + if err != nil { + t.Fatalf("Bracket(%q) returned error %q. Error not expected.", tt.input, err) + } + if actual != tt.expected { + t.Fatalf("Bracket(%q) was expected to return %v but returned %v.", + tt.input, tt.expected, actual) + } + } + if testVersion != targetTestVersion { + t.Fatalf("Found testVersion = %v, want %v.", testVersion, targetTestVersion) + } +} + +func BenchmarkBracket(b *testing.B) { + b.StopTimer() + for _, tt := range testCases { + b.StartTimer() + for i := 0; i < b.N; i++ { + Bracket(tt.input) + } + b.StopTimer() + } +} -- cgit v1.2.3