Sha256: a5eee020abbeeaa1c041aa9f6df3c69d25ab8e05f058ba790d98ee7a38b310f1

Contents?: true

Size: 1.18 KB

Versions: 83

Compression:

Stored size: 1.18 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("%s", actual) != fmt.Sprintf("%s", test.expected) {
			t.Fatalf("Accumulate(%s, %s): expected %s, actual %s", test.given, test.description, test.expected, actual)
		} else {
			t.Logf("PASS: %s %v", test.description, test.given)
		}
	}
}

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

83 entries across 83 versions & 1 rubygems

Version Path
trackler-2.0.6.27 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.26 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.25 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.24 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.23 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.22 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.21 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.20 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.19 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.18 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.17 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.16 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.15 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.14 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.13 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.12 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.11 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.10 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.9 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.8 tracks/go/exercises/accumulate/accumulate_test.go