Sha256: 3e594f3591d97fc23cb84758ad7cc2d933108896c8b94db363e0fc34b4144b2b

Contents?: true

Size: 1.39 KB

Versions: 93

Compression:

Stored size: 1.39 KB

Contents

package gigasecond

// Write a function AddGigasecond that works with time.Time.

import (
	"os"
	"testing"
	"time"
)

const targetTestVersion = 4

// date formats used in test data
const (
	fmtD  = "2006-01-02"
	fmtDT = "2006-01-02T15:04:05"
)

func TestAddGigasecond(t *testing.T) {
	if testVersion != targetTestVersion {
		t.Fatalf("Found testVersion = %v, want %v.", testVersion, targetTestVersion)
	}
	for _, tc := range addCases {
		in := parse(tc.in, t)
		want := parse(tc.want, t)
		got := AddGigasecond(in)
		if !got.Equal(want) {
			t.Fatalf(`AddGigasecond(%s)
   = %s
want %s`, in, got, want)
		}
	}
	t.Log("Tested", len(addCases), "cases.")
}

func parse(s string, t *testing.T) time.Time {
	tt, err := time.Parse(fmtDT, s) // try full date time format first
	if err != nil {
		tt, err = time.Parse(fmtD, s) // also allow just date
	}
	if err != nil {
		// can't run tests if input won't parse.  if this seems to be a
		// development or ci environment, raise an error.  if this condition
		// makes it to the solver though, ask for a bug report.
		_, statErr := os.Stat("example_gen.go")
		if statErr == nil || os.Getenv("TRAVIS_GO_VERSION") > "" {
			t.Fatal(err)
		} else {
			t.Log(err)
			t.Skip("(Not your problem.  " +
				"please file issue at https://github.com/exercism/xgo.)")
		}
	}
	return tt
}

func BenchmarkAddGigasecond(b *testing.B) {
	for i := 0; i < b.N; i++ {
		AddGigasecond(time.Time{})
	}
}

Version data entries

93 entries across 93 versions & 1 rubygems

Version Path
trackler-2.0.6.40 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.39 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.38 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.37 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.36 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.35 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.34 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.33 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.32 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.31 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.30 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.29 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.28 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.27 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.26 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.25 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.24 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.23 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.22 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.0.6.21 tracks/go/exercises/gigasecond/gigasecond_test.go