Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ jobs:

exit "$fail"

- name: Verify that all keys are in the correct order
run: ./bin/check_key_order.rb

markdown-lint:
name: Lint markdown files
runs-on: ubuntu-latest
Expand Down
34 changes: 34 additions & 0 deletions bin/check_key_order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env ruby

CORRECT_ORDER = %w[uuid reimplements description comments scenarios property input expected]

require 'json'

def find_tests(json)
if json['cases']
json['cases'].flat_map {|cases| find_tests(cases)}
elsif json['uuid']
[json]
end
end

exit_code = 0

root_dir = "#{__dir__}/.."
Dir.glob("#{root_dir}/exercises/*/canonical-data.json").each do |path|
json = JSON.parse(File.read(path))
invalid_tests = find_tests(json).select {|test| (CORRECT_ORDER & test.keys) != test.keys}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

next if invalid_tests.empty?

puts "The following tests in #{path.delete_prefix("#{root_dir}/")} use the wrong key order:"
invalid_tests.each do |test|
puts "- Test: #{test['uuid']} (#{test['description']})"
puts " Actual: #{test.keys}"
puts " Expected: #{(CORRECT_ORDER & test.keys)}"
puts ""
end

exit_code = 1
end

exit(exit_code)
4 changes: 2 additions & 2 deletions exercises/accumulate/canonical-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
},
{
"uuid": "0b357334-4cad-49e1-a741-425202edfc7c",
"description": "accumulate recursively",
"property": "accumulate",
"reimplements": "bee8e9b6-b16f-4cd2-be3b-ccf7457e50bb",
"description": "accumulate recursively",
"comments": ["Removes the trailing `)` at the end of the expression"],
"property": "accumulate",
"input": {
"list": ["a", "b", "c"],
"accumulator": "(x) => accumulate([\"1\", \"2\", \"3\"], (y) => x + y)"
Expand Down
2 changes: 1 addition & 1 deletion exercises/anagram/canonical-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
{
"uuid": "03eb9bbe-8906-4ea0-84fa-ffe711b52c8b",
"reimplements": "b3cca662-f50a-489e-ae10-ab8290a09bdc",
"description": "detects two anagrams",
"comments": [
"Reimplemented to be consistent about removing references to 'master'"
],
"description": "detects two anagrams",
"property": "findAnagrams",
"input": {
"subject": "solemn",
Expand Down
36 changes: 18 additions & 18 deletions exercises/book-store/canonical-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,187 +11,187 @@
"cases": [
{
"uuid": "17146bd5-2e80-4557-ab4c-05632b6b0d01",
"property": "total",
"description": "Only a single book",
"comments": ["Suggested grouping, [[1]]."],
"property": "total",
"input": {
"basket": [1]
},
"expected": 800
},
{
"uuid": "cc2de9ac-ff2a-4efd-b7c7-bfe0f43271ce",
"property": "total",
"description": "Two of the same book",
"comments": ["Suggested grouping, [[2],[2]]."],
"property": "total",
"input": {
"basket": [2, 2]
},
"expected": 1600
},
{
"uuid": "5a86eac0-45d2-46aa-bbf0-266b94393a1a",
"property": "total",
"description": "Empty basket",
"comments": ["Suggested grouping, []."],
"property": "total",
"input": {
"basket": []
},
"expected": 0
},
{
"uuid": "158bd19a-3db4-4468-ae85-e0638a688990",
"property": "total",
"description": "Two different books",
"comments": ["Suggested grouping, [[1,2]]."],
"property": "total",
"input": {
"basket": [1, 2]
},
"expected": 1520
},
{
"uuid": "f3833f6b-9332-4a1f-ad98-6c3f8e30e163",
"property": "total",
"description": "Three different books",
"comments": ["Suggested grouping, [[1,2,3]]."],
"property": "total",
"input": {
"basket": [1, 2, 3]
},
"expected": 2160
},
{
"uuid": "1951a1db-2fb6-4cd1-a69a-f691b6dd30a2",
"property": "total",
"description": "Four different books",
"comments": ["Suggested grouping, [[1,2,3,4]]."],
"property": "total",
"input": {
"basket": [1, 2, 3, 4]
},
"expected": 2560
},
{
"uuid": "d70f6682-3019-4c3f-aede-83c6a8c647a3",
"property": "total",
"description": "Five different books",
"comments": ["Suggested grouping, [[1,2,3,4,5]]."],
"property": "total",
"input": {
"basket": [1, 2, 3, 4, 5]
},
"expected": 3000
},
{
"uuid": "78cacb57-911a-45f1-be52-2a5bd428c634",
"property": "total",
"description": "Two groups of four is cheaper than group of five plus group of three",
"comments": ["Suggested grouping, [[1,2,3,4],[1,2,3,5]]."],
"property": "total",
"input": {
"basket": [1, 1, 2, 2, 3, 3, 4, 5]
},
"expected": 5120
},
{
"uuid": "f808b5a4-e01f-4c0d-881f-f7b90d9739da",
"property": "total",
"description": "Two groups of four is cheaper than groups of five and three",
"comments": [
"Suggested grouping, [[1,2,4,5],[1,3,4,5]]. This differs from the other 'two groups of four' test in that it will fail for solutions that add books to groups in the order in which they appear in the list."
],
"property": "total",
"input": {
"basket": [1, 1, 2, 3, 4, 4, 5, 5]
},
"expected": 5120
},
{
"uuid": "fe96401c-5268-4be2-9d9e-19b76478007c",
"property": "total",
"description": "Group of four plus group of two is cheaper than two groups of three",
"comments": ["Suggested grouping, [[1,2,3,4],[1,2]]."],
"property": "total",
"input": {
"basket": [1, 1, 2, 2, 3, 4]
},
"expected": 4080
},
{
"uuid": "68ea9b78-10ad-420e-a766-836a501d3633",
"property": "total",
"description": "Two each of first 4 books and 1 copy each of rest",
"comments": ["Suggested grouping, [[1,2,3,4,5],[1,2,3,4]]."],
"property": "total",
"input": {
"basket": [1, 1, 2, 2, 3, 3, 4, 4, 5]
},
"expected": 5560
},
{
"uuid": "c0a779d5-a40c-47ae-9828-a340e936b866",
"property": "total",
"description": "Two copies of each book",
"comments": ["Suggested grouping, [[1,2,3,4,5],[1,2,3,4,5]]."],
"property": "total",
"input": {
"basket": [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
},
"expected": 6000
},
{
"uuid": "18fd86fe-08f1-4b68-969b-392b8af20513",
"property": "total",
"description": "Three copies of first book and 2 each of remaining",
"comments": ["Suggested grouping, [[1,2,3,4,5],[1,2,3,4,5],[1]]."],
"property": "total",
"input": {
"basket": [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1]
},
"expected": 6800
},
{
"uuid": "0b19a24d-e4cf-4ec8-9db2-8899a41af0da",
"property": "total",
"description": "Three each of first 2 books and 2 each of remaining books",
"comments": ["Suggested grouping, [[1,2,3,4,5],[1,2,3,4,5],[1,2]]."],
"property": "total",
"input": {
"basket": [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2]
},
"expected": 7520
},
{
"uuid": "bb376344-4fb2-49ab-ab85-e38d8354a58d",
"property": "total",
"description": "Four groups of four are cheaper than two groups each of five and three",
"comments": [
"Suggested grouping, [[1,2,3,4],[1,2,3,5],[1,2,3,4],[1,2,3,5]]."
],
"property": "total",
"input": {
"basket": [1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5]
},
"expected": 10240
},
{
"uuid": "5260ddde-2703-4915-b45a-e54dbbac4303",
"property": "total",
"description": "Check that groups of four are created properly even when there are more groups of three than groups of five",
"comments": [
"Suggested grouping, [[1,2,3,4],[1,2,3,5],[1,2,3,4],[1,2,3,5],[1,2,3],[1,2,3]]."
],
"property": "total",
"input": {
"basket": [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5]
},
"expected": 14560
},
{
"uuid": "b0478278-c551-4747-b0fc-7e0be3158b1f",
"property": "total",
"description": "One group of one and four is cheaper than one group of two and three",
"comments": ["Suggested grouping, [[1],[1,2,3,4]]."],
"property": "total",
"input": {
"basket": [1, 1, 2, 3, 4]
},
"expected": 3360
},
{
"uuid": "cf868453-6484-4ae1-9dfc-f8ee85bbde01",
"property": "total",
"description": "One group of one and two plus three groups of four is cheaper than one group of each size",
"comments": [
"Suggested grouping, [[5],[5,4],[5,4,3,2],[5,4,3,2],[5,4,3,1]]."
],
"property": "total",
"input": {
"basket": [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
},
Expand Down
6 changes: 3 additions & 3 deletions exercises/collatz-conjecture/canonical-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
},
{
"uuid": "2187673d-77d6-4543-975e-66df6c50e2da",
"reimplements": "7d4750e6-def9-4b86-aec7-9f7eb44f95a3",
"description": "zero is an error",
"property": "steps",
"comments": ["Collatz Conjecture holds only for positive integers"],
"reimplements": "7d4750e6-def9-4b86-aec7-9f7eb44f95a3",
"property": "steps",
"input": {
"number": 0
},
Expand All @@ -74,9 +74,9 @@
},
{
"uuid": "ec11f479-56bc-47fd-a434-bcd7a31a7a2e",
"reimplements": "c6c795bf-a288-45e9-86a1-841359ad426d",
"description": "negative value is an error",
"comments": ["Collatz Conjecture holds only for positive integers"],
"reimplements": "c6c795bf-a288-45e9-86a1-841359ad426d",
"property": "steps",
"input": {
"number": -15
Expand Down
Loading