Sha256: 94b1b248f36165e776b6bd02f443d215ba81f84ba54edc3fa3511a4292238f09

Contents?: true

Size: 1.51 KB

Versions: 78

Compression:

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

func TestAddGigasecond(t *testing.T) {
	for _, tc := range addCases {
		in := parse(tc.in, t)
		want := parse(tc.want, t)
		got := AddGigasecond(in)
		if !got.Equal(want) {
			t.Fatalf(`FAIL: %s
AddGigasecond(%s)
   = %s
want %s`, tc.description, in, got, want)
		}
		t.Log("PASS:", tc.description)
	}
	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("(This is not your fault, and is unexpected.  " +
				"Please file an issue at https://github.com/exercism/go.)")
		}
	}
	return tt
}

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

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
trackler-2.2.1.16 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.15 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.14 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.13 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.12 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.11 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.10 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.9 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.8 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.7 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.6 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.5 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.4 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.3 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.2 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.1 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.1.0 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.0.6 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.0.5 tracks/go/exercises/gigasecond/gigasecond_test.go
trackler-2.2.0.4 tracks/go/exercises/gigasecond/gigasecond_test.go