Sha256: 25e8d1949f2e42c73ec685e1ee39ea00443373edae122a61c85bcee0ad885987

Contents?: true

Size: 1.07 KB

Versions: 81

Compression:

Stored size: 1.07 KB

Contents

package accumulate

import (
	"fmt"
	"strings"
	"testing"
)

func echo(c string) string {
	return c
}

func capitalize(word string) string {
	return strings.Title(word)
}

var tests = []struct {
	expected    []string
	given       []string
	converter   func(string) string
	description string
}{
	{[]string{}, []string{}, echo, "echo"},
	{[]string{"echo", "echo", "echo", "echo"}, []string{"echo", "echo", "echo", "echo"}, echo, "echo"},
	{[]string{"First", "Letter", "Only"}, []string{"first", "letter", "only"}, capitalize, "capitalize"},
	{[]string{"HELLO", "WORLD"}, []string{"hello", "world"}, strings.ToUpper, "strings.ToUpper"},
}

func TestAccumulate(t *testing.T) {
	for _, test := range tests {
		actual := Accumulate(test.given, test.converter)
		if fmt.Sprintf("%q", actual) != fmt.Sprintf("%q", test.expected) {
			t.Fatalf("Accumulate(%q, %q): expected %q, actual %q", test.given, test.description, test.expected, actual)
		}
	}
}

func BenchmarkAccumulate(b *testing.B) {
	for i := 0; i < b.N; i++ {

		for _, test := range tests {
			Accumulate(test.given, test.converter)
		}

	}
}

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.179 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.178 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.177 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.176 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.175 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.174 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.173 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.172 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.171 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.170 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.169 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.167 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.166 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.165 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.164 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.163 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.162 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.161 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.160 tracks/go/exercises/accumulate/accumulate_test.go