trackler 2.0.8.7 → 2.0.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/common/CONTRIBUTING.md +2 -2
  3. data/common/exercises/diamond/canonical-data.json +125 -0
  4. data/common/exercises/difference-of-squares/metadata.yml +1 -1
  5. data/common/exercises/hello-world/description.md +1 -1
  6. data/common/exercises/perfect-numbers/canonical-data.json +108 -0
  7. data/common/exercises/word-search/description.md +9 -9
  8. data/lib/trackler/version.rb +1 -1
  9. data/tracks/delphi/exercises/bob/uBobTests.pas +17 -17
  10. data/tracks/elixir/config.json +6 -0
  11. data/tracks/elixir/exercises/all-your-base/all-your-base-test.exs +115 -0
  12. data/tracks/elixir/exercises/all-your-base/all-your-base.exs +10 -0
  13. data/tracks/elixir/exercises/all-your-base/example.exs +48 -0
  14. data/tracks/erlang/.gitignore +1 -0
  15. data/tracks/erlang/.travis.yml +5 -1
  16. data/tracks/erlang/bin/journey-test.sh +264 -0
  17. data/tracks/erlang/exercises/allergies/test/allergies_tests.erl +1 -1
  18. data/tracks/erlang/exercises/nucleotide-count/test/{dna_tests.erl → nucleotide_count_tests.erl} +2 -2
  19. data/tracks/erlang/exercises/parallel-letter-frequency/src/example.erl +1 -1
  20. data/tracks/erlang/exercises/phone-number/test/{phone_tests.erl → phone_number_tests.erl} +2 -2
  21. data/tracks/erlang/exercises/robot-simulator/src/example.erl +1 -1
  22. data/tracks/erlang/exercises/scrabble-score/test/scrabble_score_tests.erl +1 -1
  23. data/tracks/erlang/exercises/series/src/example.erl +1 -1
  24. data/tracks/go/exercises/parallel-letter-frequency/example.go +2 -0
  25. data/tracks/go/exercises/parallel-letter-frequency/parallel_letter_frequency_test.go +8 -0
  26. data/tracks/go/exercises/pascals-triangle/example.go +2 -0
  27. data/tracks/go/exercises/pascals-triangle/pascals_triangle_test.go +8 -0
  28. data/tracks/java/exercises/acronym/src/test/java/AcronymTest.java +8 -0
  29. data/tracks/java/exercises/beer-song/src/test/java/BeerSongTest.java +44 -8
  30. data/tracks/javascript/config.json +27 -9
  31. data/tracks/julia/README.md +3 -0
  32. data/tracks/julia/img/logo.png +0 -0
  33. data/tracks/julia/img/logo.svg +11 -0
  34. data/tracks/r/exercises/TRACK_HINTS.md +8 -0
  35. data/tracks/typescript/config.json +1 -1
  36. metadata +13 -5
  37. data/tracks/r/docs/SETUP.md +0 -8
@@ -0,0 +1,10 @@
1
+ defmodule AllYourBase do
2
+ @doc """
3
+ Given a number in base a, represented as a sequence of digits, converts it to base b,
4
+ or returns nil if either of the bases are less than 2
5
+ """
6
+
7
+ @spec convert(list, integer, integer) :: list
8
+ def convert(digits, base_a, base_b) do
9
+ end
10
+ end
@@ -0,0 +1,48 @@
1
+ defmodule AllYourBase do
2
+
3
+ @doc """
4
+ Given a number in base a, represented as a sequence of digits, converts it to base b,
5
+ or returns nil if either of the bases are less than 2
6
+ """
7
+
8
+ @spec convert(list, integer, integer) :: list
9
+ def convert(digits, base_a, base_b) do
10
+ cond do
11
+ base_a > 1 and base_b > 1 and digits !=[] ->
12
+ do_convert(digits, base_a, base_b)
13
+ true ->
14
+ nil
15
+ end
16
+ end
17
+
18
+ defp do_convert(digits, base_a, base_b) do
19
+ num = convert_to_num(digits, base_a, 0)
20
+ case num do
21
+ nil -> nil
22
+ 0 -> [0]
23
+ num -> convert_to_digits(num, base_b, [])
24
+ |> Enum.reverse
25
+ end
26
+ end
27
+
28
+ defp convert_to_num([head | tail], base_a, accumulator) do
29
+ cond do
30
+ head < base_a and head >= 0 ->
31
+ convert_to_num(tail, base_a, accumulator * base_a + head)
32
+ true ->
33
+ nil
34
+ end
35
+ end
36
+
37
+ defp convert_to_num([], _base_a, accumulator) do
38
+ accumulator
39
+ end
40
+
41
+ defp convert_to_digits(num, base_b, arr) when num > 0 do
42
+ convert_to_digits(div(num, base_b), base_b, arr ++ [rem(num, base_b)])
43
+ end
44
+
45
+ defp convert_to_digits(num, _base_b, arr) when num == 0 do
46
+ arr
47
+ end
48
+ end
@@ -6,3 +6,4 @@ bin/configlet
6
6
  bin/configlet.exe
7
7
  _build/
8
8
  rebar.lock
9
+ /build/
@@ -6,11 +6,15 @@ otp_release:
6
6
  - 19.2
7
7
  install:
8
8
  - "./_test/bootstrap.sh"
9
+ - rvm install 2.2.5
10
+ - rvm use 2.2.5
9
11
  script:
10
12
  - configlet .
11
- - "./_test/check-exercises.escript"
13
+ # - "./_test/check-exercises.escript"
14
+ - "./bin/journey-test.sh"
12
15
  cache:
13
16
  - apt
17
+ - cache bundler
14
18
  - directories:
15
19
  - $HOME/bin
16
20
 
@@ -0,0 +1,264 @@
1
+ #!/usr/bin/env bash
2
+
3
+ assert_installed() {
4
+ local ok=0
5
+ for executable in $@; do
6
+ if [[ "`which $executable`" == "" ]]; then
7
+ echo "Missing executable: $executable"
8
+ ok=1
9
+ fi
10
+ done
11
+ if [[ "$ok" != "0" ]]; then exit $ok; fi
12
+ }
13
+
14
+ assert_ruby_installed() {
15
+ local app_home="$1"
16
+
17
+ pushd "${app_home}"
18
+ local current_ruby_ver=$(ruby --version | egrep --only-matching "[0-9]+\.[0-9]+\.[0-9]+")
19
+ local expected_rby_ver=$(cat Gemfile | awk -F\' '/ruby /{print $2}')
20
+ popd
21
+
22
+ if [[ "${expected_rby_ver}" != "" && "${current_ruby_ver}" != "${expected_rby_ver}" ]]; then
23
+ echo "${app_home} requires Ruby ${expected_rby_ver}; current Ruby version is ${current_ruby_ver}."
24
+ echo -e "Ruby used: `which ruby`.\n"
25
+ echo "PATH=${PATH}"
26
+ echo "aborting."
27
+ exit 1
28
+ fi
29
+ }
30
+
31
+ clean() {
32
+ local build_dir="$1"
33
+
34
+ # empty, absolute pathes, or parent references are considered dangerous to
35
+ # rm -rf against
36
+ if [[ "${build_dir}" == "" || "${build_dir}" =~ "^/" || "${build_dir}" =~ "\.\." ]]; then
37
+ echo "Value for build_dir (${build_dir}) looks dangerous, aborting!"
38
+ exit 1
39
+ fi
40
+
41
+ local build_path=$(pwd)/${build_dir}
42
+ if [[ -d "${build_path}" ]]; then
43
+ echo "Cleaning journey script build output directory (${build_path})"
44
+ rm -rf "${build_path}"
45
+ fi
46
+
47
+ for i in $(ls exercises); do
48
+ pushd exercises/$i
49
+ rm -rf _build deps rebar.lock
50
+ popd
51
+ done
52
+ }
53
+
54
+ git_clone() {
55
+ local repo_name="$1"
56
+ local dest_path="$2"
57
+
58
+ git clone "https://github.com/exercism/${repo_name}" "${dest_path}"
59
+ }
60
+
61
+ make_local_trackler() {
62
+ local trackler="$1"
63
+ local xapi_home="$2"
64
+
65
+ local xerlang=$(pwd)
66
+
67
+ pushd $trackler
68
+
69
+ git submodule init -- common
70
+ git submodule update
71
+
72
+ # Bake in local version of xerlang, this is what we are testing.
73
+ rmdir tracks/erlang
74
+ mkdir -p tracks/erlang/exercises
75
+ cp "${xerlang}/config.json" tracks/erlang
76
+ cp -r "${xerlang}/exercises" tracks/erlang
77
+
78
+ # Set version to that expected by x-api
79
+ version=$(grep -m 1 'trackler' ${xapi_home}/Gemfile.lock | sed 's/.*(//' | sed 's/)//')
80
+ echo "module Trackler VERSION = \"${version}\" end" > lib/trackler/version.rb
81
+
82
+ [[ $(which bundler) != "" ]] || gem install bundler
83
+ bundle install
84
+ gem build trackler.gemspec
85
+
86
+ # Make this the trackler that x-api will use when we build it
87
+ gem install --local "trackler-${version}.gem"
88
+ popd
89
+ }
90
+
91
+ start_x_api() {
92
+ local xapi_home="$1"
93
+
94
+ pushd "$xapi_home"
95
+
96
+ gem install bundler
97
+ bundle install
98
+ RACK_ENV=development rackup &
99
+ xapi_pid=$!
100
+ sleep 5
101
+
102
+ echo "x-api is running, pid is ${xapi_pid}."
103
+
104
+ popd
105
+ }
106
+
107
+ download_exercism_cli() {
108
+ local os="$1"
109
+ local arch="$2"
110
+ local exercism_home="$3"
111
+
112
+ local CLI_RELEASES=https://github.com/exercism/cli/releases
113
+
114
+ local latest=${CLI_RELEASES}/latest
115
+
116
+ # "curl..." :: HTTP 302 headers, including "Location" -- URL to redirect to.
117
+ # "awk..." :: pluck last path segment from "Location" (i.e. the version number)
118
+ local version="$(curl --head --silent ${latest} | awk -v FS=/ '/Location:/{print $NF}' | tr -d '\r')"
119
+
120
+ local download_url_suffix
121
+ local unzip_command
122
+ local unzip_from_file_option
123
+ if [[ ${os} == "windows" ]] ; then
124
+ download_url_suffix="zip"
125
+ unzip_command="unzip -d"
126
+ unzip_from_file_option=""
127
+ else
128
+ download_url_suffix="tgz"
129
+ unzip_command="tar xz -C"
130
+ unzip_from_file_option="-f"
131
+ fi
132
+ local download_url=${CLI_RELEASES}/download/${version}/exercism-${os}-${arch}.${download_url_suffix}
133
+
134
+ mkdir -p ${exercism_home}
135
+ local temp=`mktemp`
136
+ curl -s --location ${download_url} > ${temp}
137
+ ${unzip_command} ${exercism_home} ${unzip_from_file_option} ${temp}
138
+ }
139
+
140
+ configure_exercism_cli() {
141
+ local exercism_home="$1"
142
+ local exercism_config_file="$2"
143
+ local xapi_port=$3
144
+ local exercism="./exercism --config ${exercism_config_file}"
145
+
146
+ mkdir -p "${exercism_home}"
147
+ pushd "${exercism_home}"
148
+ $exercism configure --dir="${exercism_home}"
149
+ $exercism configure --api "http://localhost:${xapi_port}"
150
+ $exercism debug
151
+ popd
152
+ }
153
+
154
+ get_operating_system() {
155
+ case $(uname) in
156
+ (Darwin*)
157
+ echo "mac";;
158
+ (Linux*)
159
+ echo "linux";;
160
+ (Windows*)
161
+ echo "windows";;
162
+ (MINGW*)
163
+ echo "windows";;
164
+ (*)
165
+ echo "linux";;
166
+ esac
167
+ }
168
+
169
+ get_cpu_architecture() {
170
+ case $(uname -m) in
171
+ (*64*)
172
+ echo 64bit;;
173
+ (*686*)
174
+ echo 32bit;;
175
+ (*386*)
176
+ echo 32bit;;
177
+ (*)
178
+ echo 64bit;;
179
+ esac
180
+ }
181
+
182
+ solve_all_exercises() {
183
+ local exercism_exercises_dir="$1"
184
+ local exercism_configfile="$2"
185
+
186
+ local xerlang=$(pwd)
187
+ local exercism_cli="./exercism --config ${exercism_config_file}"
188
+ local exercises=$(ls exercises | sed 's|/||g')
189
+ local total_exercises=$(echo $exercises | wc -w)
190
+ local current_exercise_number=1
191
+ # local tempfile="${TMPDIR:-/tmp}/journey-test.sh-unignore_all_tests.txt"
192
+
193
+ pushd ${exercism_exercises_dir}
194
+ for exercise in $exercises; do
195
+ echo -e "\n\n"
196
+ echo "=================================================="
197
+ echo "${current_exercise_number} of ${total_exercises} -- ${exercise}"
198
+ echo "=================================================="
199
+
200
+ ${exercism_cli} fetch erlang ${exercise}
201
+ local module=$(echo $exercise | sed s/-/_/g)
202
+ cat "${xerlang}/exercises/${exercise}/src/example.erl" \
203
+ | sed "s/-module(example)./-module(${module})./" \
204
+ > "${exercism_exercises_dir}/erlang/${exercise}/src/${module}.erl"
205
+
206
+ pushd "${exercism_exercises_dir}/erlang/${exercise}"
207
+ rebar3 eunit
208
+ popd
209
+
210
+ current_exercise_number=$((current_exercise_number + 1))
211
+ done
212
+ }
213
+
214
+ main() {
215
+ cd "${EXECPATH}"
216
+
217
+ local xerlang=$(pwd)
218
+ local build_dir="build"
219
+ local build_path="${xerlang}/${build_dir}"
220
+
221
+ local xapi_home="${build_path}/x-api"
222
+ local trackler_home="${build_path}/trackler"
223
+ local exercism_home="${build_path}/exercism"
224
+
225
+ local exercism_config_file=".journey-test.exercism.json"
226
+ local xapi_port=9292
227
+
228
+ # fail fast if required tools are missing
229
+ assert_installed "git" "erl" "rebar3"
230
+
231
+ # clean up old cruft
232
+ clean "${build_dir}"
233
+
234
+ # make a version of trackler containing this sources
235
+ git_clone "x-api" "${xapi_home}"
236
+ git_clone "trackler" "${trackler_home}"
237
+ assert_ruby_installed "${trackler_home}"
238
+ make_local_trackler "${trackler_home}" "${xapi_home}"
239
+
240
+ # Fire up the local x-api
241
+ assert_ruby_installed "${xapi_home}"
242
+ start_x_api "${xapi_home}"
243
+
244
+ # Create a CLI install and config just for this build; this script does not use your CLI install.
245
+ download_exercism_cli $(get_operating_system) $(get_cpu_architecture) "${exercism_home}"
246
+ configure_exercism_cli "${exercism_home}" "${exercism_config_file}" "${xapi_port}"
247
+
248
+ solve_all_exercises "${exercism_home}" "${exercism_config_file}"
249
+ }
250
+
251
+ # Show expanded commands
252
+ set -ex
253
+
254
+ # Determine path of this script as well as the current execution dir
255
+ SCRIPTPATH=$(pushd `dirname $0` > /dev/null && pwd && popd > /dev/null)
256
+ EXECPATH=$(pwd)
257
+
258
+ # Make output easier to read in CI
259
+ TERM=dumb
260
+
261
+
262
+ xapi_pid=""
263
+ # trap on_exit EXIT
264
+ main
@@ -1,6 +1,6 @@
1
1
  -module(allergies_tests).
2
2
 
3
- -define(TESTED_MODULE, (sut(accumulate))).
3
+ -define(TESTED_MODULE, (sut(allergies))).
4
4
  -define(TEST_VERSION, 1).
5
5
  -include("exercism.hrl").
6
6
 
@@ -1,6 +1,6 @@
1
- -module(dna_tests).
1
+ -module(nucleotide_count_tests).
2
2
 
3
- -define(TESTED_MODULE, (sut(dna))).
3
+ -define(TESTED_MODULE, (sut(nucleotide_count))).
4
4
  -define(TEST_VERSION, 1).
5
5
  -include("exercism.hrl").
6
6
 
@@ -1,4 +1,4 @@
1
- -module( example ).
1
+ -module(example).
2
2
 
3
3
  -export( [dict/1, test_version/0] ).
4
4
 
@@ -1,6 +1,6 @@
1
- -module(phone_tests).
1
+ -module(phone_number_tests).
2
2
 
3
- -define(TESTED_MODULE, (sut(phone))).
3
+ -define(TESTED_MODULE, (sut(phone_number))).
4
4
  -define(TEST_VERSION, 1).
5
5
  -include("exercism.hrl").
6
6
 
@@ -1,4 +1,4 @@
1
- -module( example ).
1
+ -module(example).
2
2
 
3
3
  -export([advance/1,
4
4
  control/2,
@@ -1,6 +1,6 @@
1
1
  -module(scrabble_score_tests).
2
2
 
3
- -define(TESTED_MODULE, (sut(scrabble))).
3
+ -define(TESTED_MODULE, (sut(scrabble_score))).
4
4
  -define(TEST_VERSION, 1).
5
5
  -include("exercism.hrl").
6
6
 
@@ -1,4 +1,4 @@
1
- -module( example ).
1
+ -module(example).
2
2
 
3
3
  -export( [from_string/2, test_version/0] ).
4
4
 
@@ -1,5 +1,7 @@
1
1
  package letter
2
2
 
3
+ const testVersion = 1
4
+
3
5
  func ConcurrentFrequency(l []string) FreqMap {
4
6
  switch len(l) {
5
7
  case 0:
@@ -5,6 +5,14 @@ import (
5
5
  "testing"
6
6
  )
7
7
 
8
+ const targetTestVersion = 1
9
+
10
+ func TestTestVersion(t *testing.T) {
11
+ if testVersion != targetTestVersion {
12
+ t.Fatalf("Found testVersion = %v, want %v", testVersion, targetTestVersion)
13
+ }
14
+ }
15
+
8
16
  // In the separate file frequency.go, you are given a function, Frequency(),
9
17
  // to sequentially count letter frequencies in a single text.
10
18
  // Perform this exercise on parallelism using Go concurrency features.
@@ -1,5 +1,7 @@
1
1
  package pascal
2
2
 
3
+ const testVersion = 1
4
+
3
5
  func Triangle(n int) (t [][]int) {
4
6
  if n < 1 {
5
7
  return
@@ -6,6 +6,8 @@ import (
6
6
  "testing"
7
7
  )
8
8
 
9
+ const targetTestVersion = 1
10
+
9
11
  var t20 = [][]int{
10
12
  {1},
11
13
  {1, 1},
@@ -29,6 +31,12 @@ var t20 = [][]int{
29
31
  {1, 19, 171, 969, 3876, 11628, 27132, 50388, 75582, 92378, 92378, 75582, 50388, 27132, 11628, 3876, 969, 171, 19, 1},
30
32
  }
31
33
 
34
+ func TestTestVersion(t *testing.T) {
35
+ if testVersion != targetTestVersion {
36
+ t.Fatalf("Found testVersion = %v, want %v", testVersion, targetTestVersion)
37
+ }
38
+ }
39
+
32
40
  func TestTriangle(t *testing.T) {
33
41
  for n := 1; n <= 20; n++ {
34
42
  res := Triangle(n)