Sha256: 2060c8b33a5e196a482daa4511ba9d7cb56d36696d80c6f431cc96bff16e1aca

Contents?: true

Size: 1.3 KB

Versions: 161

Compression:

Stored size: 1.3 KB

Contents

package accumulate

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

const targetTestVersion = 1

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 TestTestVersion(t *testing.T) {
	if testVersion != targetTestVersion {
		t.Fatalf("Found testVersion = %v, want %v", testVersion, targetTestVersion)
	}
}

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

161 entries across 161 versions & 1 rubygems

Version Path
trackler-2.2.1.56 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.55 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.54 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.53 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.52 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.51 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.50 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.49 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.48 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.47 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.46 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.45 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.44 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.43 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.42 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.41 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.40 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.39 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.38 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.2.1.37 tracks/go/exercises/accumulate/accumulate_test.go