Sha256: 98ad212785bea08a2c0c241acd5626115b5c08a25ed60c6dc6369259426d846b

Contents?: true

Size: 1.37 KB

Versions: 30

Compression:

Stored size: 1.37 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("%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

30 entries across 30 versions & 1 rubygems

Version Path
trackler-2.0.8.12 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.11 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.10 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.9 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.8 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.7 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.6 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.5 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.4 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.3 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.2 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.8.1 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.7.0 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.44 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.43 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.42 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.41 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.40 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.39 tracks/go/exercises/accumulate/accumulate_test.go
trackler-2.0.6.38 tracks/go/exercises/accumulate/accumulate_test.go