Sha256: 4925dc1ab3227353421974057b318560bf3ded430e9de2f39533911cbdd3698b

Contents?: true

Size: 1.12 KB

Versions: 41

Compression:

Stored size: 1.12 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) {
	b.StopTimer()
	for _, test := range tests {
		b.StartTimer()

		for i := 0; i < b.N; i++ {
			Accumulate(test.given, test.converter)
		}

		b.StopTimer()
	}
}

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
trackler-2.2.1.97 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.96 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.95 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.94 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.93 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.92 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.91 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.90 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.89 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.88 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.87 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.86 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.85 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.84 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.83 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.82 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.81 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.80 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.79 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.78 tracks/go/exercises/accumulate/accumulate_test.go