trackler 2.1.0.0 → 2.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/common/exercises/connect/description.md +2 -1
- data/common/exercises/crypto-square/canonical-data.json +2 -2
- data/common/exercises/two-bucket/canonical-data.json +27 -1
- data/lib/trackler/version.rb +1 -1
- data/tracks/c/exercises/perfect-numbers/src/example.c +8 -4
- data/tracks/clojure/config.json +5 -0
- data/tracks/clojure/exercises/secret-handshake/project.clj +4 -0
- data/tracks/clojure/exercises/secret-handshake/src/example.clj +19 -0
- data/tracks/clojure/exercises/secret-handshake/test/secret_handshake_test.clj +55 -0
- data/tracks/cpp/.travis.yml +4 -3
- data/tracks/cpp/README.md +1 -1
- data/tracks/cpp/config.json +171 -67
- data/tracks/cpp/docs/ABOUT.md +2 -2
- data/tracks/cpp/docs/INSTALLATION.md +22 -28
- data/tracks/cpp/docs/TESTS.md +1 -1
- data/tracks/cpp/exercises/anagram/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/beer-song/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/binary/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/bob/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/clock/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/clock/clock_test.cpp +188 -64
- data/tracks/cpp/exercises/clock/example.cpp +17 -12
- data/tracks/cpp/exercises/clock/example.h +1 -0
- data/tracks/cpp/exercises/crypto-square/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/difference-of-squares/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/etl/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/etl/etl_test.cpp +5 -5
- data/tracks/cpp/exercises/food-chain/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/gigasecond/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/gigasecond/example.cpp +2 -6
- data/tracks/cpp/exercises/gigasecond/example.h +2 -2
- data/tracks/cpp/exercises/gigasecond/gigasecond_test.cpp +26 -8
- data/tracks/cpp/exercises/grade-school/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/grade-school/grade_school_test.cpp +5 -6
- data/tracks/cpp/exercises/grains/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/hamming/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/hello-world/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/hexadecimal/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/leap/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/meetup/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/meetup/meetup_test.cpp +1 -1
- data/tracks/cpp/exercises/nth-prime/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/nucleotide-count/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/nucleotide-count/nucleotide_count_test.cpp +3 -4
- data/tracks/cpp/exercises/phone-number/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/prime-factors/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/queen-attack/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/raindrops/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/rna-transcription/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/robot-name/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/roman-numerals/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/say/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/scrabble-score/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/series/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/series/series_test.cpp +11 -11
- data/tracks/cpp/exercises/sieve/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/space-age/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/sum-of-multiples/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/triangle/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/trinary/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/word-count/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/word-count/word_count_test.cpp +14 -15
- data/tracks/go/README.md +27 -13
- data/tracks/go/config.json +1 -0
- data/tracks/go/exercises/connect/.meta/gen.go +1 -3
- data/tracks/go/exercises/connect/cases_test.go +2 -1
- data/tracks/go/exercises/custom-set/.meta/gen.go +122 -101
- data/tracks/go/exercises/custom-set/cases_test.go +13 -4
- data/tracks/go/exercises/custom-set/custom_set_test.go +2 -2
- data/tracks/go/exercises/hamming/.meta/gen.go +1 -3
- data/tracks/go/exercises/hamming/cases_test.go +7 -1
- data/tracks/go/exercises/hamming/example.go +1 -1
- data/tracks/go/exercises/hamming/hamming_test.go +1 -1
- data/tracks/go/exercises/hello-world/{hello_example_test.go → example_helloworld_test.go} +0 -0
- data/tracks/go/exercises/house/house_test.go +8 -8
- data/tracks/go/exercises/meetup/.meta/gen.go +1 -3
- data/tracks/go/exercises/meetup/cases_test.go +2 -1
- data/tracks/go/exercises/palindrome-products/example.go +1 -1
- data/tracks/go/exercises/palindrome-products/palindrome_products_test.go +1 -1
- data/tracks/go/exercises/pascals-triangle/pascals_triangle_test.go +24 -4
- data/tracks/go/exercises/rna-transcription/.meta/gen.go +1 -3
- data/tracks/go/exercises/rna-transcription/cases_test.go +2 -1
- data/tracks/go/exercises/roman-numerals/.meta/gen.go +1 -3
- data/tracks/go/exercises/roman-numerals/cases_test.go +2 -1
- data/tracks/go/exercises/roman-numerals/example.go +1 -1
- data/tracks/go/exercises/transpose/.meta/gen.go +1 -3
- data/tracks/go/exercises/transpose/cases_test.go +2 -1
- data/tracks/go/exercises/transpose/transpose_test.go +5 -0
- data/tracks/go/exercises/word-count/.meta/gen.go +1 -3
- data/tracks/go/exercises/word-count/cases_test.go +2 -1
- data/tracks/go/gen/gen.go +3 -2
- data/tracks/java/config.json +5 -0
- data/tracks/java/exercises/saddle-points/build.gradle +17 -0
- data/tracks/java/exercises/saddle-points/src/example/java/Matrix.java +44 -0
- data/tracks/java/exercises/saddle-points/src/example/java/MatrixCoordinate.java +31 -0
- data/tracks/java/exercises/saddle-points/src/main/java/Matrix.java +5 -0
- data/tracks/java/exercises/saddle-points/src/main/java/MatrixCoordinate.java +31 -0
- data/tracks/java/exercises/saddle-points/src/test/java/MatrixTest.java +82 -0
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/javascript/.travis.yml +3 -1
- data/tracks/javascript/Makefile +2 -8
- data/tracks/javascript/SETUP.md +1 -2
- data/tracks/javascript/docs/INSTALLATION.md +3 -4
- data/tracks/javascript/docs/TESTS.md +14 -26
- data/tracks/javascript/exercises/hamming/example.js +7 -11
- data/tracks/javascript/exercises/hello-world/HINTS.md +3 -3
- data/tracks/javascript/exercises/robot-simulator/example.js +72 -73
- data/tracks/perl6/config.json +5 -0
- data/tracks/perl6/exercises/clock/Clock.pm6 +4 -0
- data/tracks/perl6/exercises/clock/Example.pm6 +12 -0
- data/tracks/perl6/exercises/clock/clock.t +534 -0
- data/tracks/perl6/exercises/clock/example.yaml +16 -0
- data/tracks/perl6/exercises/robot-name/Example.pm +11 -4
- data/tracks/php/exercises/hello-world/hello-world.php +1 -1
- data/tracks/php/exercises/hello-world/hello-world_test.php +1 -11
- data/tracks/php/exercises/robot-name/robot-name_test.php +1 -0
- data/tracks/purescript/config.json +7 -0
- data/tracks/purescript/exercises/largest-series-product/bower.json +16 -0
- data/tracks/purescript/exercises/largest-series-product/examples/src/LargestSeriesProduct.purs +31 -0
- data/tracks/purescript/exercises/largest-series-product/src/LargestSeriesProduct.purs +3 -0
- data/tracks/purescript/exercises/largest-series-product/test/Main.purs +73 -0
- data/tracks/python/exercises/sublist/sublist_test.py +94 -55
- data/tracks/ruby/README.md +38 -25
- data/tracks/ruby/exercises/hamming/example.tt +6 -4
- data/tracks/ruby/exercises/hamming/hamming_test.rb +4 -5
- data/tracks/ruby/exercises/linked-list/linked_list_test.rb +16 -0
- data/tracks/ruby/exercises/luhn/luhn_test.rb +5 -5
- data/tracks/ruby/exercises/ocr-numbers/.meta/.version +1 -0
- data/tracks/ruby/exercises/ocr-numbers/example.rb +42 -61
- data/tracks/ruby/exercises/ocr-numbers/example.tt +21 -0
- data/tracks/ruby/exercises/ocr-numbers/ocr_numbers_test.rb +63 -138
- data/tracks/ruby/lib/generator/exercise_cases.rb +43 -0
- data/tracks/ruby/lib/generator/underscore.rb +9 -0
- data/tracks/ruby/lib/hamming_cases.rb +9 -14
- data/tracks/ruby/lib/luhn_cases.rb +2 -18
- data/tracks/ruby/lib/ocr_numbers_cases.rb +20 -0
- data/tracks/ruby/lib/pig_latin_cases.rb +2 -12
- data/tracks/ruby/test/generator/underscore_test.rb +23 -0
- data/tracks/scala/config.json +316 -316
- metadata +26 -10
- data/tracks/cpp/exercises/etl/require_equal_containers.h +0 -88
- data/tracks/cpp/exercises/grade-school/require_equal_containers.h +0 -88
- data/tracks/cpp/exercises/nucleotide-count/require_equal_containers.h +0 -88
- data/tracks/cpp/exercises/series/require_equal_containers.h +0 -88
- data/tracks/cpp/exercises/word-count/require_equal_containers.h +0 -88
- data/tracks/javascript/exercises/acronym/package.json +0 -12
- data/tracks/javascript/package.json +0 -12
@@ -3,6 +3,7 @@
|
|
3
3
|
package main
|
4
4
|
|
5
5
|
import (
|
6
|
+
"errors"
|
6
7
|
"log"
|
7
8
|
"strconv"
|
8
9
|
"text/template"
|
@@ -12,8 +13,10 @@ import (
|
|
12
13
|
|
13
14
|
func main() {
|
14
15
|
t := template.New("").Funcs(template.FuncMap{
|
15
|
-
"str":
|
16
|
-
"strs":
|
16
|
+
"str": str,
|
17
|
+
"strs": strSlice,
|
18
|
+
"istrs": istrSlice,
|
19
|
+
"dict": dict,
|
17
20
|
})
|
18
21
|
t, err := t.Parse(tmpl)
|
19
22
|
if err != nil {
|
@@ -25,6 +28,7 @@ func main() {
|
|
25
28
|
}
|
26
29
|
}
|
27
30
|
|
31
|
+
// str converts an integer 1..26 to a letter 'a'..'z'.
|
28
32
|
func str(n int) string {
|
29
33
|
if n >= 1 && n <= 26 {
|
30
34
|
return string('a' - 1 + n)
|
@@ -32,6 +36,7 @@ func str(n int) string {
|
|
32
36
|
return strconv.Itoa(n)
|
33
37
|
}
|
34
38
|
|
39
|
+
// strSlice converts a slice of int to a slice of string.
|
35
40
|
func strSlice(ns []int) []string {
|
36
41
|
s := make([]string, len(ns))
|
37
42
|
for i, n := range ns {
|
@@ -40,66 +45,76 @@ func strSlice(ns []int) []string {
|
|
40
45
|
return s
|
41
46
|
}
|
42
47
|
|
43
|
-
//
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
// istrSlice converts a slice of interface{} values whose
|
49
|
+
// underlying members should be float64(JSON decoded integers)
|
50
|
+
// to a slice of string.
|
51
|
+
func istrSlice(ns []interface{}) []string {
|
52
|
+
s := make([]string, len(ns))
|
53
|
+
for i, n := range ns {
|
54
|
+
if fn, ok := n.(float64); ok {
|
55
|
+
s[i] = str(int(fn))
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return s
|
54
59
|
}
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
61
|
+
// dict sets up and returns a map for pairs of items given;
|
62
|
+
// it is used in order to pass multiple parameters in a template call.
|
63
|
+
func dict(values ...interface{}) (map[string]interface{}, error) {
|
64
|
+
if len(values)%2 != 0 {
|
65
|
+
return nil, errors.New("invalid dict call: odd number of values given")
|
66
|
+
}
|
67
|
+
valueMap := make(map[string]interface{}, len(values)/2)
|
68
|
+
for i := 0; i < len(values); i += 2 {
|
69
|
+
key, ok := values[i].(string)
|
70
|
+
if !ok {
|
71
|
+
return nil, errors.New("Expected string for dict key")
|
72
|
+
}
|
73
|
+
valueMap[key] = values[i+1]
|
62
74
|
}
|
75
|
+
return valueMap, nil
|
63
76
|
}
|
64
77
|
|
65
|
-
|
66
|
-
|
67
|
-
Cases
|
68
|
-
Description string
|
69
|
-
Set []int
|
70
|
-
Element int
|
71
|
-
Expected bool
|
72
|
-
}
|
78
|
+
// The JSON structure we expect to be able to unmarshal into
|
79
|
+
type js struct {
|
80
|
+
Groups TestGroups `json:"Cases"`
|
73
81
|
}
|
74
82
|
|
75
|
-
type
|
83
|
+
type TestGroups []struct {
|
76
84
|
Description string
|
77
|
-
Cases []
|
78
|
-
Description string
|
79
|
-
Set1 []int
|
80
|
-
Set2 []int
|
81
|
-
Expected bool
|
82
|
-
}
|
85
|
+
Cases []OneCase
|
83
86
|
}
|
84
87
|
|
85
|
-
type
|
88
|
+
type OneCase struct {
|
86
89
|
Description string
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
90
|
+
Property string
|
91
|
+
Set []int // "empty"/"contains"/"add" cases
|
92
|
+
Set1 []int // "subset"/"disjoint"/"equal"/"difference"/"intersection"/"union" cases
|
93
|
+
Set2 []int // "subset"/"disjoint"/"equal"/"difference"/"intersection"/"union" cases
|
94
|
+
Element int // "contains"/"add" cases
|
95
|
+
Expected interface{} // bool or []int
|
93
96
|
}
|
94
97
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
func (c OneCase) PropertyMatch(property string) bool { return c.Property == property }
|
99
|
+
|
100
|
+
// GroupComment looks in each of the test case groups to find the
|
101
|
+
// group for which every test case has the .Property matching given property;
|
102
|
+
// it returns the .Description field for the matching property group,
|
103
|
+
// or a 'Note: ...' if no test group consistently matches given property.
|
104
|
+
func (groups TestGroups) GroupComment(property string) string {
|
105
|
+
for _, group := range groups {
|
106
|
+
propertyGroupMatch := true
|
107
|
+
for _, testcase := range group.Cases {
|
108
|
+
if !testcase.PropertyMatch(property) {
|
109
|
+
propertyGroupMatch = false
|
110
|
+
break
|
111
|
+
}
|
112
|
+
}
|
113
|
+
if propertyGroupMatch {
|
114
|
+
return group.Description
|
115
|
+
}
|
102
116
|
}
|
117
|
+
return "Note: Apparent inconsistent use of \"property\": \"" + property + "\" within test case group!"
|
103
118
|
}
|
104
119
|
|
105
120
|
// template applied to above data structure generates the Go test cases
|
@@ -110,72 +125,78 @@ type binaryOp struct {
|
|
110
125
|
var tmpl = `
|
111
126
|
{{/* nested templates for repeated stuff */}}
|
112
127
|
|
113
|
-
{{define "
|
114
|
-
{{
|
115
|
-
|
116
|
-
|
128
|
+
{{define "unaryBool"}}{{$property := .PropertyType}}{{with .Groups}}
|
129
|
+
// {{ .GroupComment $property}}
|
130
|
+
var {{$property}}Cases = []unaryBoolCase{ {{range .}} {{range .Cases}}
|
131
|
+
{{if .PropertyMatch $property}} { // {{.Description}}
|
132
|
+
{{strs .Set | printf "%#v"}},
|
117
133
|
{{.Expected}},
|
118
134
|
},
|
119
|
-
{{end}}}{{end}}
|
120
|
-
|
121
|
-
{{
|
122
|
-
{{range .}}{ // {{.Description}}
|
123
|
-
{{strs .Set1 | printf "%#v"}},
|
124
|
-
{{strs .Set2 | printf "%#v"}},
|
125
|
-
{{strs .Expected | printf "%#v"}},
|
126
|
-
},
|
127
|
-
{{end}}}{{end}}
|
135
|
+
{{- end}}{{end}}{{end}}
|
136
|
+
}
|
137
|
+
{{end}}{{end}}
|
128
138
|
|
129
|
-
{{define "
|
130
|
-
{{
|
139
|
+
{{define "eleBool"}}{{$property := .PropertyType}}{{with .Groups}}
|
140
|
+
// {{ .GroupComment $property}}
|
141
|
+
var {{$property}}Cases = []eleBoolCase{ {{range .}} {{range .Cases}}
|
142
|
+
{{if .PropertyMatch $property}} { // {{.Description}}
|
131
143
|
{{strs .Set | printf "%#v"}},
|
132
144
|
{{str .Element | printf "%q"}},
|
133
|
-
{{strs .Expected | printf "%#v"}},
|
134
|
-
},
|
135
|
-
{{end}}}{{end}}
|
136
|
-
|
137
|
-
{{/* begin template body */}}
|
138
|
-
package stringset
|
139
|
-
|
140
|
-
// Source: {{.Ori}}
|
141
|
-
{{if .Commit}}// Commit: {{.Commit}}
|
142
|
-
{{end}}
|
143
|
-
|
144
|
-
// {{.J.IsEmpty.Description}}
|
145
|
-
var emptyCases = []unaryBoolCase{
|
146
|
-
{{range .J.IsEmpty.Cases}}{ // {{.Description}}
|
147
|
-
{{strs .Set | printf "%#v"}},
|
148
145
|
{{.Expected}},
|
149
146
|
},
|
150
|
-
{{end}}}
|
147
|
+
{{- end}}{{end}}{{end}}
|
148
|
+
}
|
149
|
+
{{end}}{{end}}
|
151
150
|
|
152
|
-
|
153
|
-
|
154
|
-
{{range .
|
151
|
+
{{define "eleOp"}}{{$property := .PropertyType}}{{with .Groups}}
|
152
|
+
// {{ .GroupComment $property}}
|
153
|
+
var {{$property}}Cases = []eleOpCase{ {{range .}} {{range .Cases}}
|
154
|
+
{{if .PropertyMatch $property}} { // {{.Description}}
|
155
155
|
{{strs .Set | printf "%#v"}},
|
156
156
|
{{str .Element | printf "%q"}},
|
157
|
-
{{.Expected}},
|
157
|
+
{{istrs .Expected | printf "%#v"}},
|
158
158
|
},
|
159
|
-
{{end}}}
|
160
|
-
|
161
|
-
|
162
|
-
var subsetCases{{template "binaryBool" .J.Subset.Cases}}
|
163
|
-
|
164
|
-
// {{.J.Disjoint.Description}}
|
165
|
-
var disjointCases{{template "binaryBool" .J.Disjoint.Cases}}
|
166
|
-
|
167
|
-
// {{.J.Equal.Description}}
|
168
|
-
var eqCases{{template "binaryBool" .J.Equal.Cases}}
|
159
|
+
{{- end}}{{end}}{{end}}
|
160
|
+
}
|
161
|
+
{{end}}{{end}}
|
169
162
|
|
170
|
-
|
171
|
-
|
163
|
+
{{define "binaryBool"}}{{$property := .PropertyType}}{{with .Groups}}
|
164
|
+
// {{ .GroupComment $property}}
|
165
|
+
var {{$property}}Cases = []binBoolCase{ {{range .}} {{range .Cases}}
|
166
|
+
{{if .PropertyMatch $property}} { // {{.Description}}
|
167
|
+
{{strs .Set1 | printf "%#v"}},
|
168
|
+
{{strs .Set2 | printf "%#v"}},
|
169
|
+
{{.Expected}},
|
170
|
+
},
|
171
|
+
{{- end}}{{end}}{{end}}
|
172
|
+
}
|
173
|
+
{{end}}{{end}}
|
172
174
|
|
173
|
-
|
174
|
-
|
175
|
+
{{define "binaryOp"}}{{$property := .PropertyType}}{{with .Groups}}
|
176
|
+
// {{ .GroupComment $property}}
|
177
|
+
var {{$property}}Cases = []binOpCase{ {{range .}} {{range .Cases}}
|
178
|
+
{{if .PropertyMatch $property}} { // {{.Description}}
|
179
|
+
{{strs .Set1 | printf "%#v"}},
|
180
|
+
{{strs .Set2 | printf "%#v"}},
|
181
|
+
{{istrs .Expected | printf "%#v"}},
|
182
|
+
},
|
183
|
+
{{- end}}{{end}}{{end}}
|
184
|
+
}
|
185
|
+
{{end}}{{end}}
|
175
186
|
|
176
|
-
|
177
|
-
|
187
|
+
{{/* begin template body */}}
|
188
|
+
package stringset
|
178
189
|
|
179
|
-
|
180
|
-
|
190
|
+
{{.Header}}
|
191
|
+
|
192
|
+
{{/* These template calls utilize a dict helper function in order to pass multiple parameters. */}}
|
193
|
+
{{template "unaryBool" dict "PropertyType" "empty" "Groups" .J.Groups}}
|
194
|
+
{{template "eleBool" dict "PropertyType" "contains" "Groups" .J.Groups}}
|
195
|
+
{{template "binaryBool" dict "PropertyType" "subset" "Groups" .J.Groups}}
|
196
|
+
{{template "binaryBool" dict "PropertyType" "disjoint" "Groups" .J.Groups}}
|
197
|
+
{{template "binaryBool" dict "PropertyType" "equal" "Groups" .J.Groups}}
|
198
|
+
{{template "eleOp" dict "PropertyType" "add" "Groups" .J.Groups}}
|
199
|
+
{{template "binaryOp" dict "PropertyType" "intersection" "Groups" .J.Groups}}
|
200
|
+
{{template "binaryOp" dict "PropertyType" "difference" "Groups" .J.Groups}}
|
201
|
+
{{template "binaryOp" dict "PropertyType" "union" "Groups" .J.Groups}}
|
181
202
|
`
|
@@ -1,7 +1,8 @@
|
|
1
1
|
package stringset
|
2
2
|
|
3
3
|
// Source: exercism/x-common
|
4
|
-
// Commit:
|
4
|
+
// Commit: 4527635 custom-set: Fix description to match property name
|
5
|
+
// x-common version: 1.0.1
|
5
6
|
|
6
7
|
// Returns true if the set contains no elements
|
7
8
|
var emptyCases = []unaryBoolCase{
|
@@ -16,7 +17,8 @@ var emptyCases = []unaryBoolCase{
|
|
16
17
|
}
|
17
18
|
|
18
19
|
// Sets can report if they contain an element
|
19
|
-
var
|
20
|
+
var containsCases = []eleBoolCase{
|
21
|
+
|
20
22
|
{ // nothing is contained in an empty set
|
21
23
|
[]string{},
|
22
24
|
"a",
|
@@ -36,6 +38,7 @@ var hasCases = []eleBoolCase{
|
|
36
38
|
|
37
39
|
// A set is a subset if all of its elements are contained in the other set
|
38
40
|
var subsetCases = []binBoolCase{
|
41
|
+
|
39
42
|
{ // empty set is a subset of another empty set
|
40
43
|
[]string{},
|
41
44
|
[]string{},
|
@@ -70,6 +73,7 @@ var subsetCases = []binBoolCase{
|
|
70
73
|
|
71
74
|
// Sets are disjoint if they share no elements
|
72
75
|
var disjointCases = []binBoolCase{
|
76
|
+
|
73
77
|
{ // the empty set is disjoint with itself
|
74
78
|
[]string{},
|
75
79
|
[]string{},
|
@@ -98,7 +102,8 @@ var disjointCases = []binBoolCase{
|
|
98
102
|
}
|
99
103
|
|
100
104
|
// Sets with the same elements are equal
|
101
|
-
var
|
105
|
+
var equalCases = []binBoolCase{
|
106
|
+
|
102
107
|
{ // empty sets are equal
|
103
108
|
[]string{},
|
104
109
|
[]string{},
|
@@ -128,6 +133,7 @@ var eqCases = []binBoolCase{
|
|
128
133
|
|
129
134
|
// Unique elements can be added to a set
|
130
135
|
var addCases = []eleOpCase{
|
136
|
+
|
131
137
|
{ // add to empty set
|
132
138
|
[]string{},
|
133
139
|
"c",
|
@@ -145,8 +151,9 @@ var addCases = []eleOpCase{
|
|
145
151
|
},
|
146
152
|
}
|
147
153
|
|
148
|
-
//
|
154
|
+
// Intersection returns a set of all shared elements
|
149
155
|
var intersectionCases = []binOpCase{
|
156
|
+
|
150
157
|
{ // intersection of two empty sets is an empty set
|
151
158
|
[]string{},
|
152
159
|
[]string{},
|
@@ -176,6 +183,7 @@ var intersectionCases = []binOpCase{
|
|
176
183
|
|
177
184
|
// Difference (or Complement) of a set is a set of all elements that are only in the first set
|
178
185
|
var differenceCases = []binOpCase{
|
186
|
+
|
179
187
|
{ // difference of two empty sets is an empty set
|
180
188
|
[]string{},
|
181
189
|
[]string{},
|
@@ -200,6 +208,7 @@ var differenceCases = []binOpCase{
|
|
200
208
|
|
201
209
|
// Union returns a set of all elements in either set
|
202
210
|
var unionCases = []binOpCase{
|
211
|
+
|
203
212
|
{ // union of empty sets is an empty set
|
204
213
|
[]string{},
|
205
214
|
[]string{},
|
@@ -122,7 +122,7 @@ func TestIsEmpty(t *testing.T) {
|
|
122
122
|
}
|
123
123
|
|
124
124
|
func TestHas(t *testing.T) {
|
125
|
-
for _, tc := range
|
125
|
+
for _, tc := range containsCases {
|
126
126
|
s := NewFromSlice(tc.set)
|
127
127
|
got := s.Has(tc.ele)
|
128
128
|
if got != tc.want {
|
@@ -152,7 +152,7 @@ func TestDisjoint(t *testing.T) {
|
|
152
152
|
}
|
153
153
|
|
154
154
|
func TestEqual(t *testing.T) {
|
155
|
-
testBinBool("Equal", Equal,
|
155
|
+
testBinBool("Equal", Equal, equalCases, t)
|
156
156
|
}
|
157
157
|
|
158
158
|
func TestAdd(t *testing.T) {
|
@@ -33,9 +33,7 @@ type js struct {
|
|
33
33
|
// template applied to above data structure generates the Go test cases
|
34
34
|
var tmpl = `package hamming
|
35
35
|
|
36
|
-
|
37
|
-
{{if .Commit}}// Commit: {{.Commit}}
|
38
|
-
{{end}}
|
36
|
+
{{.Header}}
|
39
37
|
|
40
38
|
var testCases = []struct {
|
41
39
|
s1 string
|
@@ -1,7 +1,8 @@
|
|
1
1
|
package hamming
|
2
2
|
|
3
3
|
// Source: exercism/x-common
|
4
|
-
// Commit:
|
4
|
+
// Commit: bb56dc7 Fix canonical-data.json formatting
|
5
|
+
// x-common version: 1.0.0
|
5
6
|
|
6
7
|
var testCases = []struct {
|
7
8
|
s1 string
|
@@ -53,6 +54,11 @@ var testCases = []struct {
|
|
53
54
|
"AGA",
|
54
55
|
1,
|
55
56
|
},
|
57
|
+
{ // same nucleotides in different positions
|
58
|
+
"TAG",
|
59
|
+
"GAT",
|
60
|
+
2,
|
61
|
+
},
|
56
62
|
{ // large distance
|
57
63
|
"GATACA",
|
58
64
|
"GCATAA",
|