trackler 2.2.1.179 → 2.2.1.180

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/exercises/yacht/description.md +14 -13
  4. data/tracks/ballerina/config.json +1 -0
  5. data/tracks/coffeescript/config.json +138 -41
  6. data/tracks/coffeescript/docs/ABOUT.md +3 -7
  7. data/tracks/coq/config.json +1 -0
  8. data/tracks/d/config.json +1 -0
  9. data/tracks/dart/config.json +1 -0
  10. data/tracks/elixir/config.json +17 -16
  11. data/tracks/elixir/docs/ABOUT.md +10 -2
  12. data/tracks/fortran/config.json +1 -0
  13. data/tracks/gnu-apl/config.json +1 -0
  14. data/tracks/go/config.json +13 -0
  15. data/tracks/go/exercises/list-ops/README.md +27 -0
  16. data/tracks/go/exercises/list-ops/example.go +99 -0
  17. data/tracks/go/exercises/list-ops/listops_test.go +291 -0
  18. data/tracks/groovy/config.json +1 -0
  19. data/tracks/haxe/config.json +1 -0
  20. data/tracks/perl5/exercises/leap/.meta/exercise-data.yaml +3 -5
  21. data/tracks/perl5/exercises/leap/.meta/solutions/Leap.pm +2 -4
  22. data/tracks/perl5/exercises/leap/Leap.pm +1 -1
  23. data/tracks/perl5/exercises/leap/leap.t +2 -2
  24. data/tracks/php/config.json +1 -0
  25. data/tracks/plsql/config.json +1 -0
  26. data/tracks/pony/config.json +1 -0
  27. data/tracks/purescript/config.json +1 -0
  28. data/tracks/reasonml/config/exercise_readme.go.tmpl +18 -2
  29. data/tracks/reasonml/exercises/anagram/README.md +15 -4
  30. data/tracks/reasonml/exercises/armstrong-numbers/README.md +3 -4
  31. data/tracks/reasonml/exercises/binary-search/README.md +14 -7
  32. data/tracks/reasonml/exercises/bob/README.md +14 -6
  33. data/tracks/reasonml/exercises/change/README.md +2 -4
  34. data/tracks/reasonml/exercises/hello-world/README.md +2 -3
  35. data/tracks/reasonml/exercises/isogram/README.md +4 -6
  36. data/tracks/reasonml/exercises/leap/README.md +14 -4
  37. data/tracks/reasonml/exercises/pangram/README.md +13 -3
  38. data/tracks/reasonml/exercises/phone-number/README.md +15 -7
  39. data/tracks/reasonml/exercises/raindrops/README.md +14 -7
  40. data/tracks/reasonml/exercises/rna-transcription/README.md +13 -3
  41. data/tracks/reasonml/exercises/roman-numerals/README.md +4 -8
  42. data/tracks/reasonml/exercises/run-length-encoding/README.md +14 -7
  43. data/tracks/reasonml/exercises/space-age/README.md +13 -3
  44. data/tracks/reasonml/exercises/word-count/README.md +18 -8
  45. data/tracks/rust/.travis.yml +1 -0
  46. data/tracks/rust/_test/check-exercises-for-authors.sh +10 -0
  47. data/tracks/rust/bin/format_exercises +2 -0
  48. data/tracks/rust/exercises/accumulate/Cargo.toml +0 -1
  49. data/tracks/rust/exercises/accumulate/example.rs +4 -1
  50. data/tracks/rust/exercises/acronym/example.rs +6 -5
  51. data/tracks/rust/exercises/acronym/tests/acronym.rs +1 -1
  52. data/tracks/rust/exercises/all-your-base/example.rs +8 -2
  53. data/tracks/rust/exercises/allergies/example.rs +28 -6
  54. data/tracks/rust/exercises/alphametics/example.rs +18 -10
  55. data/tracks/rust/exercises/anagram/example.rs +8 -4
  56. data/tracks/rust/exercises/atbash-cipher/example.rs +15 -15
  57. data/tracks/rust/exercises/beer-song/example.rs +18 -12
  58. data/tracks/rust/exercises/binary-search/Cargo.toml +0 -1
  59. data/tracks/rust/exercises/binary-search/example.rs +3 -4
  60. data/tracks/rust/exercises/bob/example.rs +11 -5
  61. data/tracks/rust/exercises/book-store/Cargo-example.toml +0 -1
  62. data/tracks/rust/exercises/book-store/Cargo.toml +0 -1
  63. data/tracks/rust/exercises/book-store/example.rs +15 -19
  64. data/tracks/rust/exercises/bowling/example.rs +3 -1
  65. data/tracks/rust/exercises/bracket-push/example.rs +7 -2
  66. data/tracks/rust/exercises/circular-buffer/example.rs +1 -1
  67. data/tracks/rust/exercises/clock/.meta/ALLOWED_TO_NOT_COMPILE +3 -0
  68. data/tracks/rust/exercises/clock/Cargo.toml +0 -1
  69. data/tracks/rust/exercises/clock/example.rs +5 -3
  70. data/tracks/rust/exercises/clock/src/lib.rs +14 -0
  71. data/tracks/rust/exercises/collatz-conjecture/example.rs +2 -2
  72. data/tracks/rust/exercises/crypto-square/Cargo-example.toml +0 -1
  73. data/tracks/rust/exercises/crypto-square/Cargo.toml +0 -1
  74. data/tracks/rust/exercises/custom-set/example.rs +17 -15
  75. data/tracks/rust/exercises/decimal/Cargo-example.toml +0 -1
  76. data/tracks/rust/exercises/decimal/Cargo.toml +0 -1
  77. data/tracks/rust/exercises/decimal/example.rs +5 -5
  78. data/tracks/rust/exercises/diamond/Cargo.toml +0 -1
  79. data/tracks/rust/exercises/difference-of-squares/example.rs +1 -1
  80. data/tracks/rust/exercises/dominoes/example.rs +20 -19
  81. data/tracks/rust/exercises/etl/example.rs +4 -3
  82. data/tracks/rust/exercises/forth/example.rs +29 -45
  83. data/tracks/rust/exercises/grade-school/example.rs +4 -2
  84. data/tracks/rust/exercises/hexadecimal/example.rs +2 -4
  85. data/tracks/rust/exercises/isbn-verifier/example.rs +5 -6
  86. data/tracks/rust/exercises/isbn-verifier/tests/isbn-verifier.rs +12 -0
  87. data/tracks/rust/exercises/isogram/example.rs +9 -3
  88. data/tracks/rust/exercises/largest-series-product/example.rs +2 -1
  89. data/tracks/rust/exercises/luhn-from/example.rs +3 -1
  90. data/tracks/rust/exercises/luhn/example.rs +5 -3
  91. data/tracks/rust/exercises/macros/Cargo.toml +0 -1
  92. data/tracks/rust/exercises/nth-prime/Cargo.toml +0 -1
  93. data/tracks/rust/exercises/nth-prime/example.rs +6 -6
  94. data/tracks/rust/exercises/nucleotide-codons/Cargo.toml +0 -1
  95. data/tracks/rust/exercises/nucleotide-codons/example.rs +23 -17
  96. data/tracks/rust/exercises/nucleotide-count/example.rs +15 -5
  97. data/tracks/rust/exercises/nucleotide-count/src/lib.rs +15 -0
  98. data/tracks/rust/exercises/nucleotide-count/tests/nucleotide-count.rs +3 -3
  99. data/tracks/rust/exercises/palindrome-products/Cargo.toml +0 -1
  100. data/tracks/rust/exercises/pangram/example.rs +6 -6
  101. data/tracks/rust/exercises/parallel-letter-frequency/example.rs +7 -4
  102. data/tracks/rust/exercises/pascals-triangle/example.rs +6 -2
  103. data/tracks/rust/exercises/perfect-numbers/example.rs +2 -2
  104. data/tracks/rust/exercises/phone-number/example.rs +11 -15
  105. data/tracks/rust/exercises/pig-latin/Cargo-example.toml +0 -1
  106. data/tracks/rust/exercises/pig-latin/Cargo.toml +0 -1
  107. data/tracks/rust/exercises/pig-latin/example.rs +6 -2
  108. data/tracks/rust/exercises/poker/Cargo-example.toml +0 -1
  109. data/tracks/rust/exercises/poker/Cargo.toml +0 -1
  110. data/tracks/rust/exercises/poker/example.rs +9 -8
  111. data/tracks/rust/exercises/prime-factors/Cargo.toml +0 -1
  112. data/tracks/rust/exercises/prime-factors/example.rs +1 -1
  113. data/tracks/rust/exercises/protein-translation/Cargo.toml +0 -1
  114. data/tracks/rust/exercises/protein-translation/example.rs +6 -5
  115. data/tracks/rust/exercises/proverb/Cargo.toml +0 -1
  116. data/tracks/rust/exercises/proverb/example.rs +0 -1
  117. data/tracks/rust/exercises/pythagorean-triplet/Cargo.toml +0 -1
  118. data/tracks/rust/exercises/pythagorean-triplet/example.rs +3 -3
  119. data/tracks/rust/exercises/queen-attack/example.rs +3 -3
  120. data/tracks/rust/exercises/react/example.rs +61 -29
  121. data/tracks/rust/exercises/reverse-string/Cargo.toml +0 -1
  122. data/tracks/rust/exercises/rna-transcription/example.rs +17 -9
  123. data/tracks/rust/exercises/robot-name/example.rs +4 -3
  124. data/tracks/rust/exercises/robot-simulator/example.rs +5 -2
  125. data/tracks/rust/exercises/roman-numerals/example.rs +15 -14
  126. data/tracks/rust/exercises/rotational-cipher/Cargo.toml +0 -1
  127. data/tracks/rust/exercises/rotational-cipher/example.rs +10 -14
  128. data/tracks/rust/exercises/rotational-cipher/src/lib.rs +7 -1
  129. data/tracks/rust/exercises/run-length-encoding/Cargo.toml +0 -1
  130. data/tracks/rust/exercises/run-length-encoding/example.rs +34 -29
  131. data/tracks/rust/exercises/saddle-points/example.rs +0 -1
  132. data/tracks/rust/exercises/say/Cargo.toml +0 -1
  133. data/tracks/rust/exercises/say/example.rs +34 -8
  134. data/tracks/rust/exercises/series/example.rs +6 -8
  135. data/tracks/rust/exercises/simple-linked-list/example.rs +0 -2
  136. data/tracks/rust/exercises/spiral-matrix/example.rs +0 -1
  137. data/tracks/rust/exercises/tournament/example.rs +33 -20
  138. data/tracks/rust/exercises/triangle/example.rs +1 -1
  139. data/tracks/rust/exercises/two-bucket/example.rs +2 -6
  140. data/tracks/rust/exercises/two-fer/example.rs +3 -3
  141. data/tracks/rust/exercises/variable-length-quantity/example.rs +2 -3
  142. data/tracks/rust/exercises/word-count/example.rs +4 -1
  143. data/tracks/rust/exercises/wordy/example.rs +10 -4
  144. metadata +7 -2
@@ -11,8 +11,16 @@ Elixir actually compiles down to [bytecode](https://en.wikipedia.org/wiki/Byteco
11
11
 
12
12
  There is no "conversion cost" for calling Erlang, meaning you can run Erlang code right next to Elixir code.
13
13
 
14
- Being a functional language, everything in Elixir is an expression. Elixir has "First Class Documentation" meaning comments can be attached to a function, making it easier to retrieve. Regular expressions are also given first class treatment, removing awkward escaping within strings.
14
+ Being a functional language, everything in Elixir is an expression.
15
15
 
16
- Elixir's asynchronous communication implementation allows the code to be lightweight, yet incorporate high-volume concurrency. Programmers use Elixir to handle thousands of requests and responses *concurrently* on a single server node. It has been used successfully for microservices that need to consume and serve a multitude of APIs rapidly.
16
+ Elixir has "First Class Documentation" meaning comments can be attached to a function, making it easier to retrieve.
17
+
18
+ Regular expressions are also given first class treatment, removing awkward escaping within strings.
19
+
20
+ Elixir's asynchronous communication implementation allows the code to be lightweight, yet incorporate high-volume concurrency.
21
+
22
+ Programmers use Elixir to handle thousands of requests and responses *concurrently* on a single server node.
23
+
24
+ It has been used successfully for microservices that need to consume and serve a multitude of APIs rapidly.
17
25
 
18
26
  The [Phoenix framework](http://www.phoenixframework.org/) helps structure Elixir applications for the web.
@@ -9,6 +9,7 @@
9
9
  "slug": "hello-world",
10
10
  "uuid": "b71d9258-78ef-4986-b9ed-ebf93b72d399",
11
11
  "core": false,
12
+ "auto_approve": true,
12
13
  "unlocked_by": null,
13
14
  "difficulty": 1,
14
15
  "topics": []
@@ -9,6 +9,7 @@
9
9
  "slug": "hello-world",
10
10
  "uuid": "81121f0c-1218-4d88-bb6c-fd9df3bc0b8d",
11
11
  "core": true,
12
+ "auto_approve": true,
12
13
  "unlocked_by": null,
13
14
  "difficulty": 1,
14
15
  "topics": [
@@ -1328,6 +1328,19 @@
1328
1328
  "strings"
1329
1329
  ]
1330
1330
  },
1331
+ {
1332
+ "slug": "list-ops",
1333
+ "uuid": "13d25b60-e8e1-42da-a54f-ce020a2b86e9",
1334
+ "core": false,
1335
+ "unlocked_by": null,
1336
+ "difficulty": 3,
1337
+ "topics": [
1338
+ "recursion",
1339
+ "type_conversion",
1340
+ "lists",
1341
+ "functional_programming"
1342
+ ]
1343
+ },
1331
1344
  {
1332
1345
  "slug": "binary",
1333
1346
  "uuid": "bf2dcbc4-266f-4cad-9cd7-76d446360a5d",
@@ -0,0 +1,27 @@
1
+ # List Ops
2
+
3
+ Implement basic list operations.
4
+
5
+ In functional languages list operations like `length`, `map`, and
6
+ `reduce` are very common. Implement a series of basic list operations,
7
+ without using existing functions.
8
+
9
+ ## Running the tests
10
+
11
+ To run the tests run the command `go test` from within the exercise directory.
12
+
13
+ If the test suite contains benchmarks, you can run these with the `--bench` and `--benchmem`
14
+ flags:
15
+
16
+ go test -v --bench . --benchmem
17
+
18
+ Keep in mind that each reviewer will run benchmarks on a different machine, with
19
+ different specs, so the results from these benchmark tests may vary.
20
+
21
+ ## Further information
22
+
23
+ For more detailed information about the Go track, including how to get help if
24
+ you're having trouble, please visit the exercism.io [Go language page](http://exercism.io/languages/go/about).
25
+
26
+ ## Submitting Incomplete Solutions
27
+ It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -0,0 +1,99 @@
1
+ package listops
2
+
3
+ // IntList is an abstraction of a list of integers
4
+ type IntList []int
5
+ type predFunc func(int) bool
6
+ type binFunc func(int, int) int
7
+ type unaryFunc func(int) int
8
+
9
+ // Foldl folds (reduces) the given list from the left with a function
10
+ func (s IntList) Foldl(fn binFunc, initial int) int {
11
+ if len(s) == 0 {
12
+ return initial
13
+ }
14
+ x, xs := s[0], s[1:]
15
+ return xs.Foldl(fn, fn(initial, x))
16
+ }
17
+
18
+ // Foldr folds (reduces) the given list from the right with a function
19
+ func (s IntList) Foldr(fn binFunc, initial int) int {
20
+ flippedFunc := func(x, y int) int { return fn(y, x) }
21
+ // Note: This relies on s being finite
22
+ return s.Reverse().Foldl(flippedFunc, initial)
23
+ }
24
+
25
+ // Filter list returning only values that satisfy the filter function
26
+ func (s IntList) Filter(fn predFunc) IntList {
27
+ filtered := make([]int, 0, len(s))
28
+ var filterAcc func(predFunc, IntList, IntList) IntList
29
+ filterAcc = func(fn predFunc, acc IntList, lst IntList) IntList {
30
+ if len(lst) == 0 {
31
+ return acc
32
+ }
33
+ x, xs := lst[0], lst[1:]
34
+ if fn(x) {
35
+ acc = append(acc, x)
36
+ }
37
+ return filterAcc(fn, acc, xs)
38
+ }
39
+ return filterAcc(fn, filtered, s)
40
+ }
41
+
42
+ // Length returns the length of a list
43
+ func (s IntList) Length() int {
44
+ // for fun, let's do this with recursion
45
+ var lengthAcc func(IntList, int) int
46
+ var isEmpty func(IntList) bool
47
+ // yeah, this is kind of cheaty, but it's hard to determine if a slice is
48
+ // empty without using len, so walling it off
49
+ isEmpty = func(l IntList) bool {
50
+ return len(l) == 0
51
+ }
52
+ lengthAcc = func(lst IntList, acc int) int {
53
+ if isEmpty(lst) {
54
+ return acc
55
+ }
56
+ return lengthAcc(lst[1:], acc+1)
57
+ }
58
+ return lengthAcc(s, 0)
59
+ }
60
+
61
+ // Map returns a list of elements whose values equal the list value transformed by the mapping function
62
+ func (s IntList) Map(fn unaryFunc) IntList {
63
+ newSlice := make([]int, len(s))
64
+ for idx, elt := range s {
65
+ newSlice[idx] = fn(elt)
66
+ }
67
+ return newSlice
68
+ }
69
+
70
+ // Reverse reverses the list
71
+ func (s IntList) Reverse() IntList {
72
+ last := len(s) - 1
73
+ newSlice := make([]int, len(s))
74
+ for idx, elt := range s {
75
+ newSlice[last-idx] = elt
76
+ }
77
+ return newSlice
78
+ }
79
+
80
+ // Append adds the elements of the argument list to the receiver
81
+ func (s IntList) Append(lst IntList) IntList {
82
+ offset := len(s)
83
+ newSlice := make([]int, offset+len(lst))
84
+ copy(newSlice, s)
85
+ for idx, elt := range lst {
86
+ newSlice[offset+idx] = elt
87
+ }
88
+ return newSlice
89
+ }
90
+
91
+ // Concat concatenates a list of lists
92
+ func (s IntList) Concat(lists []IntList) IntList {
93
+ newSlice := make([]int, len(s))
94
+ copy(newSlice, s)
95
+ for _, l := range lists {
96
+ newSlice = append(newSlice, l...)
97
+ }
98
+ return newSlice
99
+ }
@@ -0,0 +1,291 @@
1
+ package listops
2
+
3
+ import "reflect"
4
+ import "testing"
5
+
6
+ var foldTestCases = []struct {
7
+ name string
8
+ property string
9
+ fn binFunc
10
+ initial int
11
+ list IntList
12
+ want int
13
+ }{
14
+ {
15
+ name: "empty list",
16
+ property: "foldl",
17
+ fn: func(x, y int) int { return x * y },
18
+ initial: 2,
19
+ want: 2,
20
+ list: []int{},
21
+ },
22
+ {
23
+ name: "direction independent function applied to non-empty list",
24
+ property: "foldl",
25
+ fn: func(x, y int) int { return x + y },
26
+ initial: 5,
27
+ want: 15,
28
+ list: []int{1, 2, 3, 4},
29
+ },
30
+ {
31
+ name: "direction dependent function applied to non-empty list",
32
+ property: "foldl",
33
+ fn: func(x, y int) int { return x / y },
34
+ initial: 5,
35
+ want: 0,
36
+ list: []int{2, 5},
37
+ },
38
+ {
39
+ name: "empty list",
40
+ property: "foldr",
41
+ fn: func(x, y int) int { return x * y },
42
+ initial: 2,
43
+ want: 2,
44
+ list: []int{},
45
+ },
46
+ {
47
+ name: "direction dependent function applied to non-empty list",
48
+ property: "foldr",
49
+ fn: func(x, y int) int { return x + y },
50
+ initial: 5,
51
+ want: 15,
52
+ list: []int{1, 2, 3, 4},
53
+ },
54
+ {
55
+ name: "direction dependent function applied to non-empty list",
56
+ property: "foldr",
57
+ fn: func(x, y int) int { return x / y },
58
+ initial: 5,
59
+ want: 2,
60
+ list: []int{2, 5},
61
+ },
62
+ }
63
+
64
+ func TestFold(t *testing.T) {
65
+ var got int
66
+ for _, tt := range foldTestCases {
67
+ if tt.property == "foldr" {
68
+ got = tt.list.Foldr(tt.fn, tt.initial)
69
+ } else {
70
+ got = tt.list.Foldl(tt.fn, tt.initial)
71
+ }
72
+ if got != tt.want {
73
+ t.Fatalf("FAIL: %s: %q -- expected: %d, actual: %d", tt.property, tt.name, tt.want, got)
74
+ } else {
75
+ t.Logf("PASS: %s: %s", tt.property, tt.name)
76
+ }
77
+
78
+ }
79
+
80
+ }
81
+
82
+ var filterTestCases = []struct {
83
+ name string
84
+ property string
85
+ fn predFunc
86
+ list []int
87
+ want []int
88
+ }{
89
+ {
90
+ name: "empty list",
91
+ property: "filter",
92
+ fn: func(n int) bool { return n%2 == 1 },
93
+ list: []int{},
94
+ want: []int{},
95
+ },
96
+ {
97
+ name: "non-empty list",
98
+ property: "filter",
99
+ fn: func(n int) bool { return n%2 == 1 },
100
+ list: []int{1, 2, 3, 4, 5},
101
+ want: []int{1, 3, 5},
102
+ },
103
+ }
104
+
105
+ func TestFilterMethod(t *testing.T) {
106
+ for _, tt := range filterTestCases {
107
+ in := IntList(tt.list)
108
+ got := in.Filter(tt.fn)
109
+ if !reflect.DeepEqual(IntList(tt.want), got) {
110
+ t.Fatalf("FAIL: %s: %q -- expected: %v, actual: %v", tt.property, tt.name, tt.want, got)
111
+ } else {
112
+ t.Logf("PASS: %s: %s", tt.property, tt.name)
113
+ }
114
+
115
+ }
116
+ }
117
+
118
+ var lengthTestCases = []struct {
119
+ name string
120
+ property string
121
+ list IntList
122
+ want int
123
+ }{
124
+ {
125
+ name: "empty list",
126
+ property: "length",
127
+ list: []int{},
128
+ want: 0,
129
+ },
130
+ {
131
+ name: "non-empty list",
132
+ property: "length",
133
+ list: []int{1, 2, 3, 4},
134
+ want: 4,
135
+ },
136
+ }
137
+
138
+ func TestLengthMethod(t *testing.T) {
139
+ for _, tt := range lengthTestCases {
140
+ got := tt.list.Length()
141
+ if tt.want != got {
142
+ t.Fatalf("FAIL: %s: %q -- expected: %d, actual: %d", tt.property, tt.name, tt.want, got)
143
+ } else {
144
+ t.Logf("PASS: %s: %s", tt.property, tt.name)
145
+ }
146
+
147
+ }
148
+ }
149
+
150
+ var mapTestCases = []struct {
151
+ name string
152
+ property string
153
+ list IntList
154
+ fn unaryFunc
155
+ want IntList
156
+ }{
157
+ {
158
+ name: "empty list",
159
+ property: "map",
160
+ list: []int{},
161
+ fn: func(x int) int { return x + 1 },
162
+ want: []int{},
163
+ },
164
+ {
165
+ name: "non-empty list",
166
+ property: "map",
167
+ list: []int{1, 3, 5, 7},
168
+ fn: func(x int) int { return x + 1 },
169
+ want: []int{2, 4, 6, 8},
170
+ },
171
+ }
172
+
173
+ func TestMapMethod(t *testing.T) {
174
+ for _, tt := range mapTestCases {
175
+ got := tt.list.Map(tt.fn)
176
+ if !reflect.DeepEqual(tt.want, got) {
177
+ t.Fatalf("FAIL: %s: %q -- expected: %v, actual: %v", tt.property, tt.name, tt.want, got)
178
+ } else {
179
+ t.Logf("PASS: %s: %s", tt.property, tt.name)
180
+ }
181
+
182
+ }
183
+ }
184
+
185
+ var reverseTestCases = []struct {
186
+ name string
187
+ property string
188
+ list IntList
189
+ want IntList
190
+ }{
191
+ {
192
+ name: "empty list",
193
+ property: "reverse",
194
+ list: []int{},
195
+ want: []int{},
196
+ },
197
+ {
198
+ name: "non-empty list",
199
+ property: "reverse",
200
+ list: []int{1, 3, 5, 7},
201
+ want: []int{7, 5, 3, 1},
202
+ },
203
+ }
204
+
205
+ func TestReverseMethod(t *testing.T) {
206
+ for _, tt := range reverseTestCases {
207
+ got := tt.list.Reverse()
208
+ if !reflect.DeepEqual(tt.want, got) {
209
+ t.Fatalf("FAIL: %s: %q -- expected: %v, actual: %v", tt.property, tt.name, tt.want, got)
210
+ } else {
211
+ t.Logf("PASS: %s: %s", tt.property, tt.name)
212
+ }
213
+
214
+ }
215
+ }
216
+
217
+ var appendTestCases = []struct {
218
+ name string
219
+ property string
220
+ list IntList
221
+ appendThis IntList
222
+ want IntList
223
+ }{
224
+ {
225
+ name: "empty list",
226
+ property: "append",
227
+ list: []int{},
228
+ appendThis: []int{},
229
+ want: []int{},
230
+ },
231
+ {
232
+ name: "empty list to list",
233
+ property: "append",
234
+ list: []int{},
235
+ appendThis: []int{1, 2, 3, 4},
236
+ want: []int{1, 2, 3, 4},
237
+ },
238
+ {
239
+ name: "non-empty lists",
240
+ property: "append",
241
+ list: []int{1, 2},
242
+ appendThis: []int{2, 3, 4, 5},
243
+ want: []int{1, 2, 2, 3, 4, 5},
244
+ },
245
+ }
246
+
247
+ func TestAppendMethod(t *testing.T) {
248
+ for _, tt := range appendTestCases {
249
+ got := tt.list.Append(tt.appendThis)
250
+ if !reflect.DeepEqual(tt.want, got) {
251
+ t.Fatalf("FAIL: %s: %q -- expected: %v, actual: %v", tt.property, tt.name, tt.want, got)
252
+ } else {
253
+ t.Logf("PASS: %s: %s", tt.property, tt.name)
254
+ }
255
+
256
+ }
257
+ }
258
+
259
+ var concatTestCases = []struct {
260
+ name string
261
+ property string
262
+ list IntList
263
+ args []IntList
264
+ want IntList
265
+ }{
266
+ {
267
+ name: "empty list",
268
+ property: "concat",
269
+ list: []int{},
270
+ args: []IntList{},
271
+ want: []int{},
272
+ },
273
+ {
274
+ name: "list of lists",
275
+ property: "concat",
276
+ list: []int{1, 2},
277
+ args: []IntList{[]int{3}, []int{}, []int{4, 5, 6}},
278
+ want: []int{1, 2, 3, 4, 5, 6},
279
+ },
280
+ }
281
+
282
+ func TestConcatMethod(t *testing.T) {
283
+ for _, tt := range concatTestCases {
284
+ got := tt.list.Concat(tt.args)
285
+ if !reflect.DeepEqual(tt.want, got) {
286
+ t.Fatalf("FAIL: %s: %q -- expected: %v, actual: %v", tt.property, tt.name, tt.want, got)
287
+ } else {
288
+ t.Logf("PASS: %s: %s", tt.property, tt.name)
289
+ }
290
+ }
291
+ }