Sha256: 1cdea6deab8aaef8fff62c8969b27333c966ef9f080851171e2e96707182e99c

Contents?: true

Size: 1.14 KB

Versions: 78

Compression:

Stored size: 1.14 KB

Contents

package main

import (
	"log"
	"text/template"

	"../../../gen"
)

func main() {
	t, err := template.New("").Parse(tmpl)
	if err != nil {
		log.Fatal(err)
	}
	var j js
	if err := gen.Gen("two-bucket", &j, t); err != nil {
		log.Fatal(err)
	}
}

// The JSON structure we expect to be able to unmarshal into
type js struct {
	Cases []struct {
		Description string
		Input       struct {
			BucketOne   int
			BucketTwo   int
			Goal        int
			StartBucket string
		}
		Expected struct {
			GoalBucket  string
			Moves       int
			OtherBucket int
		}
	}
}

// template applied to above data structure generates the Go test cases
var tmpl = `package twobucket

{{.Header}}

type bucketTestCase struct {
	description     string
	bucketOne	int
	bucketTwo	int
	goal		int
	startBucket	string
	goalBucket	string
	moves		int
	otherBucket	int
	errorExpected   bool // always false for generated test cases.
}

var testCases = []bucketTestCase {
{{range .J.Cases}}{
	"{{.Description}}",
	{{.Input.BucketOne}}, {{.Input.BucketTwo}}, {{.Input.Goal}}, "{{.Input.StartBucket}}", "{{.Expected.GoalBucket}}", {{.Expected.Moves}}, {{.Expected.OtherBucket}}, false,
},
{{end}}}
`

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.179 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.178 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.177 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.176 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.175 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.174 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.173 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.172 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.171 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.170 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.169 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.167 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.166 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.165 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.164 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.163 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.162 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.161 tracks/go/exercises/two-bucket/.meta/gen.go
trackler-2.2.1.160 tracks/go/exercises/two-bucket/.meta/gen.go