From 5905c68a1fbae71682ff2edea7c009ad0355e9fb Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 26 Aug 2016 09:21:31 +0200 Subject: Solve series --- go/series/asktoomuch_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 go/series/asktoomuch_test.go (limited to 'go/series/asktoomuch_test.go') diff --git a/go/series/asktoomuch_test.go b/go/series/asktoomuch_test.go new file mode 100644 index 0000000..e29703a --- /dev/null +++ b/go/series/asktoomuch_test.go @@ -0,0 +1,29 @@ +// +build asktoomuch + +package slice + +import "testing" + +func TestAskTooMuch(t *testing.T) { + test := allTests[0] + defer func() { + if recover() != nil { + t.Fatalf("Yikes, UnsafeFirst(%d, %s) panicked!", test.n, test.s) + } + }() + for _, test = range allTests { + switch res := UnsafeFirst(test.n, test.s); { + case len(test.out) > 0: // well, this should work + if res != test.out[0] { + t.Fatalf("Yikes, UnsafeFirst(%d, %s) = %q, want %q.", + test.n, test.s, res, test.out[0]) + } + case len(res) != test.n: + t.Fatalf("Yikes, UnsafeFirst(%d, %s) = %q, but %q doesn't have %d characters.", + test.n, test.s, res, res, test.n) + default: + t.Fatalf("Yikes, UnsafeFirst(%d, %s) = %q, but %q isn't in %q", + test.n, test.s, res, res, test.s) + } + } +} -- cgit v1.2.3