From f465d2e8321ad736940af23827eb642c1438d121 Mon Sep 17 00:00:00 2001 From: Rudresh Amin Date: Sat, 9 Sep 2017 01:44:17 -0700 Subject: [PATCH 1/2] Auto generate READMEs based on problem description and Ruby docs template. --- bin/generate | 2 +- docs/EXERCISE_README_INSERT.md | 2 + exercises/acronym/README.md | 5 -- exercises/all-your-base/README.md | 4 +- exercises/alphametics/README.md | 2 - exercises/anagram/README.md | 5 -- exercises/beer-song/README.md | 7 +-- exercises/binary/README.md | 5 -- exercises/bob/README.md | 5 -- exercises/bowling/README.md | 5 -- exercises/bracket-push/README.md | 7 +-- exercises/change/README.md | 44 ++++++++++++++ exercises/clock/README.md | 5 -- exercises/collatz-conjecture/README.md | 7 +-- exercises/connect/README.md | 2 - exercises/custom-set/README.md | 4 +- exercises/difference-of-squares/README.md | 7 +-- exercises/dominoes/README.md | 2 - exercises/etl/README.md | 5 -- exercises/gigasecond/README.md | 5 -- exercises/grains/README.md | 5 -- exercises/hamming/README.md | 5 -- exercises/hello-world/README.md | 7 +-- exercises/isogram/README.md | 5 -- exercises/largest-series-product/README.md | 7 +-- exercises/leap/README.md | 5 -- exercises/luhn/README.md | 5 -- exercises/nth-prime/README.md | 7 +-- exercises/ocr-numbers/README.md | 7 +-- exercises/pangram/README.md | 5 -- exercises/phone-number/README.md | 7 +-- exercises/pig-latin/README.md | 7 +-- exercises/queen-attack/README.md | 7 +-- exercises/raindrops/README.md | 5 -- exercises/rna-transcription/README.md | 7 +-- exercises/roman-numerals/README.md | 7 +-- exercises/rotational-cipher/README.md | 57 +++++++++++++++++++ exercises/run-length-encoding/README.md | 7 +-- exercises/say/README.md | 5 -- exercises/sieve/README.md | 5 -- exercises/space-age/README.md | 10 +--- exercises/sum-of-multiples/README.md | 7 +-- exercises/tournament/README.md | 2 - exercises/transpose/README.md | 5 -- exercises/triangle/README.md | 5 -- exercises/two-bucket/README.md | 7 +-- exercises/word-count/README.md | 7 +-- exercises/wordy/README.md | 5 -- lib/generator.rb | 7 ++- lib/generator/exercise.rb | 4 ++ lib/generator/files.rb | 5 +- lib/generator/files/metadata_files.rb | 1 + lib/generator/implementation.rb | 16 ++++++ lib/helper.rb | 1 + .../command_line/generator_optparser_test.rb | 3 +- test/generator/command_line_test.rb | 3 +- test/generator/files/metadata_files_test.rb | 1 + test/generator/files/track_files_test.rb | 1 + test/generator/implementation_test.rb | 1 + test/generator_test.rb | 2 + 60 files changed, 165 insertions(+), 230 deletions(-) create mode 100644 exercises/change/README.md create mode 100644 exercises/rotational-cipher/README.md diff --git a/bin/generate b/bin/generate index 070b63cbba..65ce7e51a5 100755 --- a/bin/generate +++ b/bin/generate @@ -3,7 +3,7 @@ require_relative '../lib/helper' require 'generator' -paths = Generator::Paths.new(track: EXERCISM_RUBY_ROOT, metadata: METADATA_REPOSITORY_PATH) +paths = Generator::Paths.new(track: EXERCISM_RUBY_ROOT, docs: EXERCISM_RUBY_DOCS, metadata: METADATA_REPOSITORY_PATH) generators = Generator::CommandLine.new(paths).parse(ARGV) exit 1 unless generators diff --git a/docs/EXERCISE_README_INSERT.md b/docs/EXERCISE_README_INSERT.md index b946eeb289..1ff48ed22a 100644 --- a/docs/EXERCISE_README_INSERT.md +++ b/docs/EXERCISE_README_INSERT.md @@ -22,3 +22,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/acronym/README.md b/exercises/acronym/README.md index 7fbb051222..37f8d3687b 100644 --- a/exercises/acronym/README.md +++ b/exercises/acronym/README.md @@ -32,10 +32,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Julien Vanier [https://github.com/monkbroc](https://github.com/monkbroc) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/all-your-base/README.md b/exercises/all-your-base/README.md index 865be3e448..2d3d251e00 100644 --- a/exercises/all-your-base/README.md +++ b/exercises/all-your-base/README.md @@ -1,4 +1,4 @@ -# All Your Base +# All_your_base Convert a number, represented as a sequence of digits in one base, to any other base. @@ -55,7 +55,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/alphametics/README.md b/exercises/alphametics/README.md index a14369099f..838e8cff05 100644 --- a/exercises/alphametics/README.md +++ b/exercises/alphametics/README.md @@ -55,7 +55,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/anagram/README.md b/exercises/anagram/README.md index 15857df784..8f0ca107bb 100644 --- a/exercises/anagram/README.md +++ b/exercises/anagram/README.md @@ -30,10 +30,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/beer-song/README.md b/exercises/beer-song/README.md index 1d603c268b..c301bc2cac 100644 --- a/exercises/beer-song/README.md +++ b/exercises/beer-song/README.md @@ -1,4 +1,4 @@ -# Beer Song +# Beer_song Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall. @@ -344,10 +344,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Learn to Program by Chris Pine [http://pine.fm/LearnToProgram/?Chapter=06](http://pine.fm/LearnToProgram/?Chapter=06) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/binary/README.md b/exercises/binary/README.md index 8b66f4505b..4cda88876c 100644 --- a/exercises/binary/README.md +++ b/exercises/binary/README.md @@ -52,10 +52,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -All of Computer Science [http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-](http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/bob/README.md b/exercises/bob/README.md index 9019bf4d85..055250bdf9 100644 --- a/exercises/bob/README.md +++ b/exercises/bob/README.md @@ -35,10 +35,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=06](http://pine.fm/LearnToProgram/?Chapter=06) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/bowling/README.md b/exercises/bowling/README.md index 1dc31916c5..a6040dd30b 100644 --- a/exercises/bowling/README.md +++ b/exercises/bowling/README.md @@ -70,10 +70,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -The Bowling Game Kata at but UncleBob [http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata](http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/bracket-push/README.md b/exercises/bracket-push/README.md index 34d13def0a..ddca746779 100644 --- a/exercises/bracket-push/README.md +++ b/exercises/bracket-push/README.md @@ -1,4 +1,4 @@ -# Bracket Push +# Bracket_push Given a string containing brackets `[]`, braces `{}` and parentheses `()`, verify that all the pairs are matched and nested correctly. @@ -27,10 +27,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Ginna Baker - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/change/README.md b/exercises/change/README.md new file mode 100644 index 0000000000..c85dfc78b5 --- /dev/null +++ b/exercises/change/README.md @@ -0,0 +1,44 @@ +# Change + +Correctly determine the fewest number of coins to be given to a customer such +that the sum of the coins' value would equal the correct amount of change. + +## For example + +- An input of 15 with [1, 5, 10, 25, 100] should return one nickel (5) + and one dime (10) or [0, 1, 1, 0, 0] +- An input of 40 with [1, 5, 10, 25, 100] should return one nickel (5) + and one dime (10) and one quarter (25) or [0, 1, 1, 1, 0] + +## Edge cases + +- Does your algorithm work for any given set of coins? +- Can you ask for negative change? +- Can you ask for a change value smaller than the smallest coin value? + +* * * * + +For installation and learning resources, refer to the +[exercism help page](http://exercism.io/languages/ruby). + +For running the tests provided, you will need the Minitest gem. Open a +terminal window and run the following command to install minitest: + + gem install minitest + +If you would like color output, you can `require 'minitest/pride'` in +the test file, or note the alternative instruction, below, for running +the test file. + +In order to run the test, you can run the test file from the exercise +directory. For example, if the test suite is called +`hello_world_test.rb`, you can run the following command: + + ruby hello_world_test.rb + +To include color from the command line: + + ruby -r minitest/pride hello_world_test.rb + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/clock/README.md b/exercises/clock/README.md index 590d0150f5..2810fd0580 100644 --- a/exercises/clock/README.md +++ b/exercises/clock/README.md @@ -30,10 +30,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Pairing session with Erin Drummond [https://twitter.com/ebdrummond](https://twitter.com/ebdrummond) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/collatz-conjecture/README.md b/exercises/collatz-conjecture/README.md index b8fe3fae04..8ee8452b06 100644 --- a/exercises/collatz-conjecture/README.md +++ b/exercises/collatz-conjecture/README.md @@ -1,4 +1,4 @@ -# Collatz Conjecture +# Collatz_conjecture The Collatz Conjecture or 3x+1 problem can be summarized as follows: @@ -50,10 +50,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -An unsolved problem in mathematics named after mathematician Lothar Collatz [https://en.wikipedia.org/wiki/3x_%2B_1_problem](https://en.wikipedia.org/wiki/3x_%2B_1_problem) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/connect/README.md b/exercises/connect/README.md index aae91bfbc5..f0dc3aa0e0 100644 --- a/exercises/connect/README.md +++ b/exercises/connect/README.md @@ -54,7 +54,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/custom-set/README.md b/exercises/custom-set/README.md index 3e4de704a3..0aeba2b0c2 100644 --- a/exercises/custom-set/README.md +++ b/exercises/custom-set/README.md @@ -1,4 +1,4 @@ -# Custom Set +# Custom_set Create a custom set type. @@ -31,7 +31,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/difference-of-squares/README.md b/exercises/difference-of-squares/README.md index 62728718a0..6ce5b436fc 100644 --- a/exercises/difference-of-squares/README.md +++ b/exercises/difference-of-squares/README.md @@ -1,4 +1,4 @@ -# Difference Of Squares +# Difference_of_squares Find the difference between the square of the sum and the sum of the squares of the first N natural numbers. @@ -36,10 +36,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Problem 6 at Project Euler [http://projecteuler.net/problem=6](http://projecteuler.net/problem=6) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/dominoes/README.md b/exercises/dominoes/README.md index 14f666d6d5..1a053b552c 100644 --- a/exercises/dominoes/README.md +++ b/exercises/dominoes/README.md @@ -38,7 +38,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/etl/README.md b/exercises/etl/README.md index b7dbc63635..3b544c67ec 100644 --- a/exercises/etl/README.md +++ b/exercises/etl/README.md @@ -68,10 +68,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -The Jumpstart Lab team [http://jumpstartlab.com](http://jumpstartlab.com) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/gigasecond/README.md b/exercises/gigasecond/README.md index c4fdc48475..08ee01a4e5 100644 --- a/exercises/gigasecond/README.md +++ b/exercises/gigasecond/README.md @@ -28,10 +28,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Chapter 9 in Chris Pine's online Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=09](http://pine.fm/LearnToProgram/?Chapter=09) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/grains/README.md b/exercises/grains/README.md index b78c06e78c..372aa2db6e 100644 --- a/exercises/grains/README.md +++ b/exercises/grains/README.md @@ -51,10 +51,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -JavaRanch Cattle Drive, exercise 6 [http://www.javaranch.com/grains.jsp](http://www.javaranch.com/grains.jsp) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/hamming/README.md b/exercises/hamming/README.md index 936cbdf2c4..612c9aab05 100644 --- a/exercises/hamming/README.md +++ b/exercises/hamming/README.md @@ -59,10 +59,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -The Calculating Point Mutations problem at Rosalind [http://rosalind.info/problems/hamm/](http://rosalind.info/problems/hamm/) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/hello-world/README.md b/exercises/hello-world/README.md index 335b523b8d..8815b739f0 100644 --- a/exercises/hello-world/README.md +++ b/exercises/hello-world/README.md @@ -1,4 +1,4 @@ -# Hello World +# Hello_world The classical introductory exercise. Just say "Hello, World!". @@ -38,10 +38,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/isogram/README.md b/exercises/isogram/README.md index 1dfffd2185..23cdd19b21 100644 --- a/exercises/isogram/README.md +++ b/exercises/isogram/README.md @@ -36,10 +36,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Wikipedia [https://en.wikipedia.org/wiki/Isogram](https://en.wikipedia.org/wiki/Isogram) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/largest-series-product/README.md b/exercises/largest-series-product/README.md index f9ea37d478..a0834ad19a 100644 --- a/exercises/largest-series-product/README.md +++ b/exercises/largest-series-product/README.md @@ -1,4 +1,4 @@ -# Largest Series Product +# Largest_series_product Given a string of digits, calculate the largest product for a contiguous substring of digits of length n. @@ -37,10 +37,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -A variation on Problem 8 at Project Euler [http://projecteuler.net/problem=8](http://projecteuler.net/problem=8) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/leap/README.md b/exercises/leap/README.md index bc5e5bf9dc..736b110300 100644 --- a/exercises/leap/README.md +++ b/exercises/leap/README.md @@ -50,10 +50,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -JavaRanch Cattle Drive, exercise 3 [http://www.javaranch.com/leap.jsp](http://www.javaranch.com/leap.jsp) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/luhn/README.md b/exercises/luhn/README.md index 830097097f..2b4ab67d9f 100644 --- a/exercises/luhn/README.md +++ b/exercises/luhn/README.md @@ -88,10 +88,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -The Luhn Algorithm on Wikipedia [http://en.wikipedia.org/wiki/Luhn_algorithm](http://en.wikipedia.org/wiki/Luhn_algorithm) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/nth-prime/README.md b/exercises/nth-prime/README.md index cf698a9295..ec17ced736 100644 --- a/exercises/nth-prime/README.md +++ b/exercises/nth-prime/README.md @@ -1,4 +1,4 @@ -# Nth Prime +# Nth_prime Given a number n, determine what the nth prime is. @@ -32,10 +32,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -A variation on Problem 7 at Project Euler [http://projecteuler.net/problem=7](http://projecteuler.net/problem=7) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/ocr-numbers/README.md b/exercises/ocr-numbers/README.md index e201a94f15..80e4fed8ae 100644 --- a/exercises/ocr-numbers/README.md +++ b/exercises/ocr-numbers/README.md @@ -1,4 +1,4 @@ -# Ocr Numbers +# Ocr_numbers Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled. @@ -102,10 +102,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Inspired by the Bank OCR kata [http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR](http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/pangram/README.md b/exercises/pangram/README.md index 50d954d7ca..6430420343 100644 --- a/exercises/pangram/README.md +++ b/exercises/pangram/README.md @@ -32,10 +32,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Wikipedia [https://en.wikipedia.org/wiki/Pangram](https://en.wikipedia.org/wiki/Pangram) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/phone-number/README.md b/exercises/phone-number/README.md index 0b4d323211..1fa4ae1817 100644 --- a/exercises/phone-number/README.md +++ b/exercises/phone-number/README.md @@ -1,4 +1,4 @@ -# Phone Number +# Phone_number Clean up user-entered phone numbers so that they can be sent SMS messages. @@ -51,10 +51,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Event Manager by JumpstartLab [http://tutorials.jumpstartlab.com/projects/eventmanager.html](http://tutorials.jumpstartlab.com/projects/eventmanager.html) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/pig-latin/README.md b/exercises/pig-latin/README.md index 2633718104..37e72687f2 100644 --- a/exercises/pig-latin/README.md +++ b/exercises/pig-latin/README.md @@ -1,4 +1,4 @@ -# Pig Latin +# Pig_latin Implement a program that translates from English to Pig Latin. @@ -41,10 +41,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -The Pig Latin exercise at Test First Teaching by Ultrasaurus [https://github.com/ultrasaurus/test-first-teaching/blob/master/learn_ruby/pig_latin/](https://github.com/ultrasaurus/test-first-teaching/blob/master/learn_ruby/pig_latin/) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/queen-attack/README.md b/exercises/queen-attack/README.md index 506c6441f6..65c774d6ae 100644 --- a/exercises/queen-attack/README.md +++ b/exercises/queen-attack/README.md @@ -1,4 +1,4 @@ -# Queen Attack +# Queen_attack Given the position of two queens on a chess board, indicate whether or not they are positioned so that they can attack each other. @@ -50,10 +50,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -J Dalbey's Programming Practice problems [http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html](http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/raindrops/README.md b/exercises/raindrops/README.md index 8cf930774c..01ad82693b 100644 --- a/exercises/raindrops/README.md +++ b/exercises/raindrops/README.md @@ -41,10 +41,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -A variation on a famous interview question intended to weed out potential candidates. [http://jumpstartlab.com](http://jumpstartlab.com) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/rna-transcription/README.md b/exercises/rna-transcription/README.md index e2929a2340..14db36fecd 100644 --- a/exercises/rna-transcription/README.md +++ b/exercises/rna-transcription/README.md @@ -1,4 +1,4 @@ -# Rna Transcription +# Rna_transcription Given a DNA strand, return its RNA complement (per RNA transcription). @@ -42,10 +42,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Rosalind [http://rosalind.info/problems/rna](http://rosalind.info/problems/rna) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/roman-numerals/README.md b/exercises/roman-numerals/README.md index 29eae2e634..575ad4a9d1 100644 --- a/exercises/roman-numerals/README.md +++ b/exercises/roman-numerals/README.md @@ -1,4 +1,4 @@ -# Roman Numerals +# Roman_numerals Write a function to convert from normal numbers to Roman Numerals. @@ -66,10 +66,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -The Roman Numeral Kata [http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals](http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/rotational-cipher/README.md b/exercises/rotational-cipher/README.md new file mode 100644 index 0000000000..692e297416 --- /dev/null +++ b/exercises/rotational-cipher/README.md @@ -0,0 +1,57 @@ +# Rotational_cipher + +Create an implementation of the rotational cipher, also sometimes called the Caesar cipher. + +The Caesar cipher is a simple shift cipher that relies on +transposing all the letters in the alphabet using an integer key +between `0` and `26`. Using a key of `0` or `26` will always yield +the same output due to modular arithmetic. The letter is shifted +for as many values as the value of the key. + +The general notation for rotational ciphers is `ROT + `. +The most commonly used rotational cipher is `ROT13`. + +A `ROT13` on the Latin alphabet would be as follows: + +```plain +Plain: abcdefghijklmnopqrstuvwxyz +Cipher: nopqrstuvwxyzabcdefghijklm +``` + +It is stronger than the Atbash cipher because it has 27 possible keys, and 25 usable keys. + +Ciphertext is written out in the same formatting as the input including spaces and punctuation. + +## Examples +- ROT5 `omg` gives `trl` +- ROT0 `c` gives `c` +- ROT26 `Cool` gives `Cool` +- ROT13 `The quick brown fox jumps over the lazy dog.` gives `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.` +- ROT13 `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.` gives `The quick brown fox jumps over the lazy dog.` + +* * * * + +For installation and learning resources, refer to the +[exercism help page](http://exercism.io/languages/ruby). + +For running the tests provided, you will need the Minitest gem. Open a +terminal window and run the following command to install minitest: + + gem install minitest + +If you would like color output, you can `require 'minitest/pride'` in +the test file, or note the alternative instruction, below, for running +the test file. + +In order to run the test, you can run the test file from the exercise +directory. For example, if the test suite is called +`hello_world_test.rb`, you can run the following command: + + ruby hello_world_test.rb + +To include color from the command line: + + ruby -r minitest/pride hello_world_test.rb + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/run-length-encoding/README.md b/exercises/run-length-encoding/README.md index 3fe7134a83..7180226004 100644 --- a/exercises/run-length-encoding/README.md +++ b/exercises/run-length-encoding/README.md @@ -1,4 +1,4 @@ -# Run Length Encoding +# Run_length_encoding Implement run-length encoding and decoding. @@ -47,10 +47,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Wikipedia [https://en.wikipedia.org/wiki/Run-length_encoding](https://en.wikipedia.org/wiki/Run-length_encoding) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/say/README.md b/exercises/say/README.md index b61d98fd03..ca48147b31 100644 --- a/exercises/say/README.md +++ b/exercises/say/README.md @@ -86,10 +86,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -A variation on JavaRanch CattleDrive, exercise 4a [http://www.javaranch.com/say.jsp](http://www.javaranch.com/say.jsp) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/sieve/README.md b/exercises/sieve/README.md index 8be49d6143..1583c4d493 100644 --- a/exercises/sieve/README.md +++ b/exercises/sieve/README.md @@ -51,10 +51,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Sieve of Eratosthenes at Wikipedia [http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes](http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/space-age/README.md b/exercises/space-age/README.md index 12a08040f3..4c7fd08807 100644 --- a/exercises/space-age/README.md +++ b/exercises/space-age/README.md @@ -1,4 +1,4 @@ -# Space Age +# Space_age Given an age in seconds, calculate how old someone would be on: @@ -12,7 +12,8 @@ Given an age in seconds, calculate how old someone would be on: - Neptune: orbital period 164.79132 Earth years So if you were told someone were 1,000,000,000 seconds old, you should -be able to say that they're 31 Earth-years old. +be able to say that they're 31.69 Earth-years old. Round all ages to +the nearest hundredth of a year. If you're wondering why Pluto didn't make the cut, go watch [this youtube video](http://www.youtube.com/watch?v=Z_2gbGXzFbs). @@ -41,10 +42,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Partially inspired by Chapter 1 in Chris Pine's online Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=01](http://pine.fm/LearnToProgram/?Chapter=01) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/sum-of-multiples/README.md b/exercises/sum-of-multiples/README.md index 85ab1f98da..b715befb28 100644 --- a/exercises/sum-of-multiples/README.md +++ b/exercises/sum-of-multiples/README.md @@ -1,4 +1,4 @@ -# Sum Of Multiples +# Sum_of_multiples Given a number, find the sum of all the multiples of particular numbers up to but not including that number. @@ -35,10 +35,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -A variation on Problem 1 at Project Euler [http://projecteuler.net/problem=1](http://projecteuler.net/problem=1) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/tournament/README.md b/exercises/tournament/README.md index 44ed94c2d4..c7f97f9127 100644 --- a/exercises/tournament/README.md +++ b/exercises/tournament/README.md @@ -88,7 +88,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/transpose/README.md b/exercises/transpose/README.md index 5e47bc60f2..31598f7464 100644 --- a/exercises/transpose/README.md +++ b/exercises/transpose/README.md @@ -82,10 +82,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Reddit r/dailyprogrammer challenge #270 [Easy]. [https://www.reddit.com/r/dailyprogrammer/comments/4msu2x/challenge_270_easy_transpose_the_input_text](https://www.reddit.com/r/dailyprogrammer/comments/4msu2x/challenge_270_easy_transpose_the_input_text) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/triangle/README.md b/exercises/triangle/README.md index 6c869777ee..0c5683fd53 100644 --- a/exercises/triangle/README.md +++ b/exercises/triangle/README.md @@ -43,10 +43,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -The Ruby Koans triangle project, parts 1 & 2 [http://rubykoans.com](http://rubykoans.com) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/two-bucket/README.md b/exercises/two-bucket/README.md index 92c73efa92..6c952273ca 100644 --- a/exercises/two-bucket/README.md +++ b/exercises/two-bucket/README.md @@ -1,4 +1,4 @@ -# Two Bucket +# Two_bucket Given two buckets of different size, demonstrate how to measure an exact number of liters by strategically transferring liters of fluid between the buckets. @@ -53,10 +53,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Water Pouring Problem [http://demonstrations.wolfram.com/WaterPouringProblem/](http://demonstrations.wolfram.com/WaterPouringProblem/) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/word-count/README.md b/exercises/word-count/README.md index 0cbd9d03ea..ce3aa359ab 100644 --- a/exercises/word-count/README.md +++ b/exercises/word-count/README.md @@ -1,4 +1,4 @@ -# Word Count +# Word_count Given a phrase, count the occurrences of each word in that phrase. @@ -36,10 +36,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -This is a classic toy problem, but we were reminded of it by seeing it in the Go Tour. - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/wordy/README.md b/exercises/wordy/README.md index 43e43bf534..81dd20b546 100644 --- a/exercises/wordy/README.md +++ b/exercises/wordy/README.md @@ -80,10 +80,5 @@ To include color from the command line: ruby -r minitest/pride hello_world_test.rb - -## Source - -Inspired by one of the generated questions in the Extreme Startup game. [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup) - ## Submitting Incomplete Solutions It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/lib/generator.rb b/lib/generator.rb index d14497448f..b17cd98a7c 100644 --- a/lib/generator.rb +++ b/lib/generator.rb @@ -4,9 +4,10 @@ module Generator # Immutable value object for storing paths class Paths - attr_reader :track, :metadata - def initialize(track:, metadata:) + attr_reader :track, :docs, :metadata + def initialize(track:, docs:, metadata:) @track = track + @docs = docs @metadata = metadata end end @@ -16,6 +17,7 @@ def initialize(track:, metadata:) class GenerateTests < ImplementationDelegator def call build_tests + build_readme end end @@ -25,6 +27,7 @@ def call update_tests_version update_example_solution build_tests + build_readme end end end diff --git a/lib/generator/exercise.rb b/lib/generator/exercise.rb index e858a12d1e..801cbd1cca 100644 --- a/lib/generator/exercise.rb +++ b/lib/generator/exercise.rb @@ -12,6 +12,10 @@ def name @name ||= slug.underscore end + def directory + "exercises/#{@slug}" + end + def case_class slug.camel_case + 'Case' end diff --git a/lib/generator/files.rb b/lib/generator/files.rb index 95fff207b4..104c1aff72 100644 --- a/lib/generator/files.rb +++ b/lib/generator/files.rb @@ -7,9 +7,10 @@ def self.read(filename) end class Readable - attr_reader :filename, :repository_root - def initialize(filename:, repository_root: nil) + attr_reader :filename, :docs, :repository_root + def initialize(filename:, docs: nil, repository_root: nil) @filename = filename + @docs = docs @repository_root = repository_root end diff --git a/lib/generator/files/metadata_files.rb b/lib/generator/files/metadata_files.rb index c68eedf080..10f2ac9c0b 100644 --- a/lib/generator/files/metadata_files.rb +++ b/lib/generator/files/metadata_files.rb @@ -4,6 +4,7 @@ module MetadataFiles def canonical_data CanonicalDataFile.new( filename: File.join(metadata_path, 'canonical-data.json'), + docs: File.join(metadata_path, 'description.md'), repository_root: paths.metadata) end diff --git a/lib/generator/implementation.rb b/lib/generator/implementation.rb index 196c39c957..ed983845a2 100644 --- a/lib/generator/implementation.rb +++ b/lib/generator/implementation.rb @@ -33,6 +33,17 @@ def build_tests values: template_values ) end + + def build_readme + canonicalDocs = File.read(@repository.canonical_data().docs) + docs = File.read(@repository.paths.docs) + ne = "#{@repository.paths.track}/#{@exercise.directory}/README.md" + File.open(ne, "w") do |handle| + handle.puts "# #{@exercise.name.capitalize}\n\n" + handle.puts "#{canonicalDocs}\n" + handle.puts docs + end + end end # This exists to give us a clue as to what we are delegating to. @@ -60,5 +71,10 @@ def build_tests @implementation.build_tests @logger.info "Generated #{exercise.slug} tests version #{version}" end + + def build_readme + @implementation.build_readme + @logger.info "Generated #{exercise.slug} README" + end end end diff --git a/lib/helper.rb b/lib/helper.rb index bb1874b49e..ee7a4b2b98 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -1,5 +1,6 @@ EXERCISM_RUBY_ROOT = File.join(File.dirname(__FILE__), '..').freeze EXERCISM_RUBY_LIB = File.join(EXERCISM_RUBY_ROOT, 'lib').freeze +EXERCISM_RUBY_DOCS = File.join(EXERCISM_RUBY_ROOT, 'docs/EXERCISE_README_INSERT.md').freeze METADATA_REPOSITORY_PATH = File.join(EXERCISM_RUBY_ROOT, '..', 'problem-specifications').freeze $LOAD_PATH.unshift(EXERCISM_RUBY_LIB) diff --git a/test/generator/command_line/generator_optparser_test.rb b/test/generator/command_line/generator_optparser_test.rb index 8375c69857..385a542d5a 100644 --- a/test/generator/command_line/generator_optparser_test.rb +++ b/test/generator/command_line/generator_optparser_test.rb @@ -4,6 +4,7 @@ module Generator class GeneratorOptparserTest < Minitest::Test FixturePaths = Paths.new( metadata: 'test/fixtures/metadata', + docs: 'test/fixtures/metadata', track: 'test/fixtures/ruby' ) @@ -87,7 +88,7 @@ def test_usage_help_includes_available_generators end def test_invalid_metadata_repository_outputs_message_to_stderr - paths = Paths.new(metadata: 'test/fixtures/nonexistent', track: nil) + paths = Paths.new(metadata: 'test/fixtures/nonexistent', track: nil, docs: nil) expected_stderr = <<-MESSAGE.gsub(/^ {6}/, '') 'problem-specifications' repository not found. Try running the command: diff --git a/test/generator/command_line_test.rb b/test/generator/command_line_test.rb index a4a7aec2d0..c6fc0daaec 100644 --- a/test/generator/command_line_test.rb +++ b/test/generator/command_line_test.rb @@ -4,6 +4,7 @@ module Generator class CommandLineTest < Minitest::Test FixturePaths = Paths.new( metadata: 'test/fixtures/metadata', + docs: 'test/fixtures/metadata', track: 'test/fixtures/ruby' ) @@ -15,7 +16,7 @@ def test_parse end def test_invalid_metadata_repository_outputs_message_to_stderr - paths = Paths.new(metadata: 'test/fixtures/nonexistent', track: nil) + paths = Paths.new(metadata: 'test/fixtures/nonexistent', track: nil, docs: nil) expected_stderr = <<-MESSAGE.gsub(/^ {6}/, '') 'problem-specifications' repository not found. Try running the command: diff --git a/test/generator/files/metadata_files_test.rb b/test/generator/files/metadata_files_test.rb index 5b80e8c092..3f1eac5c21 100644 --- a/test/generator/files/metadata_files_test.rb +++ b/test/generator/files/metadata_files_test.rb @@ -4,6 +4,7 @@ module Files class MetadataFilesTest < Minitest::Test FixturePaths = Paths.new( metadata: 'test/fixtures/metadata', + docs: 'test/fixtures/metadata', track: 'test/fixtures/ruby' ) diff --git a/test/generator/files/track_files_test.rb b/test/generator/files/track_files_test.rb index 24d7a39dd4..1203d496e2 100644 --- a/test/generator/files/track_files_test.rb +++ b/test/generator/files/track_files_test.rb @@ -5,6 +5,7 @@ module Files class TrackFilesTest < Minitest::Test FixturePaths = Paths.new( metadata: 'test/fixtures/metadata', + docs: 'test/fixtures/metadata', track: 'test/fixtures/ruby' ) diff --git a/test/generator/implementation_test.rb b/test/generator/implementation_test.rb index 12009af043..a54c809bd1 100644 --- a/test/generator/implementation_test.rb +++ b/test/generator/implementation_test.rb @@ -4,6 +4,7 @@ module Generator class ImplementationTest < Minitest::Test FixturePaths = Paths.new( metadata: 'test/fixtures/metadata', + docs: 'test/fixtures/metadata', track: 'test/fixtures/ruby' ) diff --git a/test/generator_test.rb b/test/generator_test.rb index b376960afa..db4ab160d0 100644 --- a/test/generator_test.rb +++ b/test/generator_test.rb @@ -7,6 +7,7 @@ def test_call mock_exercise.expect :update_tests_version, nil mock_exercise.expect :update_example_solution, nil mock_exercise.expect :build_tests, nil + mock_exercise.expect :build_readme, nil subject = UpdateVersionAndGenerateTests.new(mock_exercise) subject.call @@ -19,6 +20,7 @@ class UpdateVersionAndGenerateTestsFrozenVersionTest < Minitest::Test def test_call mock_exercise = Minitest::Mock.new mock_exercise.expect :build_tests, nil + mock_exercise.expect :build_readme, nil subject = GenerateTests.new(mock_exercise) subject.call From ee50d45ed9dc416f71a41efe094440771ac6a62a Mon Sep 17 00:00:00 2001 From: Rudresh Amin Date: Sat, 9 Sep 2017 09:20:04 -0700 Subject: [PATCH 2/2] Add test case for build_readme. --- exercises/acronym/README.md | 2 -- exercises/all-your-base/README.md | 2 -- exercises/alphametics/README.md | 2 -- exercises/anagram/README.md | 2 -- exercises/beer-song/README.md | 2 -- exercises/binary/README.md | 2 -- exercises/bob/README.md | 2 -- exercises/bowling/README.md | 2 -- exercises/bracket-push/README.md | 2 -- exercises/change/README.md | 2 -- exercises/clock/README.md | 2 -- exercises/collatz-conjecture/README.md | 2 -- exercises/connect/README.md | 2 -- exercises/custom-set/README.md | 2 -- exercises/difference-of-squares/README.md | 2 -- exercises/dominoes/README.md | 2 -- exercises/etl/README.md | 2 -- exercises/gigasecond/README.md | 2 -- exercises/grains/README.md | 2 -- exercises/hamming/README.md | 2 -- exercises/hello-world/README.md | 2 -- exercises/isogram/README.md | 2 -- exercises/largest-series-product/README.md | 2 -- exercises/leap/README.md | 2 -- exercises/luhn/README.md | 2 -- exercises/nth-prime/README.md | 2 -- exercises/ocr-numbers/README.md | 2 -- exercises/pangram/README.md | 2 -- exercises/phone-number/README.md | 2 -- exercises/pig-latin/README.md | 2 -- exercises/queen-attack/README.md | 2 -- exercises/raindrops/README.md | 2 -- exercises/rna-transcription/README.md | 2 -- exercises/roman-numerals/README.md | 2 -- exercises/rotational-cipher/README.md | 2 -- exercises/run-length-encoding/README.md | 2 -- exercises/say/README.md | 2 -- exercises/sieve/README.md | 2 -- exercises/space-age/README.md | 2 -- exercises/sum-of-multiples/README.md | 2 -- exercises/tournament/README.md | 2 -- exercises/transpose/README.md | 2 -- exercises/triangle/README.md | 2 -- exercises/two-bucket/README.md | 2 -- exercises/word-count/README.md | 2 -- exercises/wordy/README.md | 2 -- lib/generator/exercise.rb | 4 +++ lib/generator/implementation.rb | 10 +++---- test/fixtures/docs/EXERCISE_README_INSERT.md | 2 ++ .../metadata/exercises/alpha/description.md | 5 ++++ test/generator/implementation_test.rb | 26 ++++++++++++++++++- 51 files changed, 39 insertions(+), 100 deletions(-) create mode 100644 test/fixtures/docs/EXERCISE_README_INSERT.md create mode 100644 test/fixtures/metadata/exercises/alpha/description.md diff --git a/exercises/acronym/README.md b/exercises/acronym/README.md index 37f8d3687b..2d7296628f 100644 --- a/exercises/acronym/README.md +++ b/exercises/acronym/README.md @@ -1,5 +1,3 @@ -# Acronym - Convert a phrase to its acronym. Techies love their TLA (Three Letter Acronyms)! diff --git a/exercises/all-your-base/README.md b/exercises/all-your-base/README.md index 2d3d251e00..ba959230e4 100644 --- a/exercises/all-your-base/README.md +++ b/exercises/all-your-base/README.md @@ -1,5 +1,3 @@ -# All_your_base - Convert a number, represented as a sequence of digits in one base, to any other base. Implement general base conversion. Given a number in base **a**, diff --git a/exercises/alphametics/README.md b/exercises/alphametics/README.md index 838e8cff05..00b0782fe1 100644 --- a/exercises/alphametics/README.md +++ b/exercises/alphametics/README.md @@ -1,5 +1,3 @@ -# Alphametics - Write a function to solve alphametics puzzles. [Alphametics](https://en.wikipedia.org/wiki/Alphametics) is a puzzle where diff --git a/exercises/anagram/README.md b/exercises/anagram/README.md index 8f0ca107bb..24357083fd 100644 --- a/exercises/anagram/README.md +++ b/exercises/anagram/README.md @@ -1,5 +1,3 @@ -# Anagram - Given a word and a list of possible anagrams, select the correct sublist. Given `"listen"` and a list of candidates like `"enlists" "google" diff --git a/exercises/beer-song/README.md b/exercises/beer-song/README.md index c301bc2cac..e9bc8baa11 100644 --- a/exercises/beer-song/README.md +++ b/exercises/beer-song/README.md @@ -1,5 +1,3 @@ -# Beer_song - Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall. Note that not all verses are identical. diff --git a/exercises/binary/README.md b/exercises/binary/README.md index 4cda88876c..e15e5f6457 100644 --- a/exercises/binary/README.md +++ b/exercises/binary/README.md @@ -1,5 +1,3 @@ -# Binary - Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles. Implement binary to decimal conversion. Given a binary input diff --git a/exercises/bob/README.md b/exercises/bob/README.md index 055250bdf9..168ab232ec 100644 --- a/exercises/bob/README.md +++ b/exercises/bob/README.md @@ -1,5 +1,3 @@ -# Bob - Bob is a lackadaisical teenager. In conversation, his responses are very limited. Bob answers 'Sure.' if you ask him a question. diff --git a/exercises/bowling/README.md b/exercises/bowling/README.md index a6040dd30b..6447837c09 100644 --- a/exercises/bowling/README.md +++ b/exercises/bowling/README.md @@ -1,5 +1,3 @@ -# Bowling - Score a bowling game. Bowling is game where players roll a heavy ball to knock down pins diff --git a/exercises/bracket-push/README.md b/exercises/bracket-push/README.md index ddca746779..8fb701914b 100644 --- a/exercises/bracket-push/README.md +++ b/exercises/bracket-push/README.md @@ -1,5 +1,3 @@ -# Bracket_push - Given a string containing brackets `[]`, braces `{}` and parentheses `()`, verify that all the pairs are matched and nested correctly. diff --git a/exercises/change/README.md b/exercises/change/README.md index c85dfc78b5..8e459acc0a 100644 --- a/exercises/change/README.md +++ b/exercises/change/README.md @@ -1,5 +1,3 @@ -# Change - Correctly determine the fewest number of coins to be given to a customer such that the sum of the coins' value would equal the correct amount of change. diff --git a/exercises/clock/README.md b/exercises/clock/README.md index 2810fd0580..b10ae527d7 100644 --- a/exercises/clock/README.md +++ b/exercises/clock/README.md @@ -1,5 +1,3 @@ -# Clock - Implement a clock that handles times without dates. You should be able to add and subtract minutes to it. diff --git a/exercises/collatz-conjecture/README.md b/exercises/collatz-conjecture/README.md index 8ee8452b06..7dcc402be6 100644 --- a/exercises/collatz-conjecture/README.md +++ b/exercises/collatz-conjecture/README.md @@ -1,5 +1,3 @@ -# Collatz_conjecture - The Collatz Conjecture or 3x+1 problem can be summarized as follows: Take any positive integer n. If n is even, divide n by 2 to get n / 2. If n is diff --git a/exercises/connect/README.md b/exercises/connect/README.md index f0dc3aa0e0..eef3c42875 100644 --- a/exercises/connect/README.md +++ b/exercises/connect/README.md @@ -1,5 +1,3 @@ -# Connect - Compute the result for a game of Hex / Polygon. The abstract boardgame known as diff --git a/exercises/custom-set/README.md b/exercises/custom-set/README.md index 0aeba2b0c2..097ad1fc4f 100644 --- a/exercises/custom-set/README.md +++ b/exercises/custom-set/README.md @@ -1,5 +1,3 @@ -# Custom_set - Create a custom set type. Sometimes it is necessary to define a custom data structure of some diff --git a/exercises/difference-of-squares/README.md b/exercises/difference-of-squares/README.md index 6ce5b436fc..5a48d4e81a 100644 --- a/exercises/difference-of-squares/README.md +++ b/exercises/difference-of-squares/README.md @@ -1,5 +1,3 @@ -# Difference_of_squares - Find the difference between the square of the sum and the sum of the squares of the first N natural numbers. The square of the sum of the first ten natural numbers is diff --git a/exercises/dominoes/README.md b/exercises/dominoes/README.md index 1a053b552c..8e8c956a48 100644 --- a/exercises/dominoes/README.md +++ b/exercises/dominoes/README.md @@ -1,5 +1,3 @@ -# Dominoes - Make a chain of dominoes. Compute a way to order a given set of dominoes in such a way that they form a diff --git a/exercises/etl/README.md b/exercises/etl/README.md index 3b544c67ec..f9de1ff53a 100644 --- a/exercises/etl/README.md +++ b/exercises/etl/README.md @@ -1,5 +1,3 @@ -# Etl - We are going to do the `Transform` step of an Extract-Transform-Load. ### ETL diff --git a/exercises/gigasecond/README.md b/exercises/gigasecond/README.md index 08ee01a4e5..4517741f80 100644 --- a/exercises/gigasecond/README.md +++ b/exercises/gigasecond/README.md @@ -1,5 +1,3 @@ -# Gigasecond - Calculate the moment when someone has lived for 10^9 seconds. A gigasecond is 10^9 (1,000,000,000) seconds. diff --git a/exercises/grains/README.md b/exercises/grains/README.md index 372aa2db6e..c0be805ca1 100644 --- a/exercises/grains/README.md +++ b/exercises/grains/README.md @@ -1,5 +1,3 @@ -# Grains - Calculate the number of grains of wheat on a chessboard given that the number on each square doubles. diff --git a/exercises/hamming/README.md b/exercises/hamming/README.md index 612c9aab05..6e7246183d 100644 --- a/exercises/hamming/README.md +++ b/exercises/hamming/README.md @@ -1,5 +1,3 @@ -# Hamming - Calculate the Hamming difference between two DNA strands. A mutation is simply a mistake that occurs during the creation or diff --git a/exercises/hello-world/README.md b/exercises/hello-world/README.md index 8815b739f0..54d002d127 100644 --- a/exercises/hello-world/README.md +++ b/exercises/hello-world/README.md @@ -1,5 +1,3 @@ -# Hello_world - The classical introductory exercise. Just say "Hello, World!". ["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is diff --git a/exercises/isogram/README.md b/exercises/isogram/README.md index 23cdd19b21..b6b1834e79 100644 --- a/exercises/isogram/README.md +++ b/exercises/isogram/README.md @@ -1,5 +1,3 @@ -# Isogram - Determine if a word or phrase is an isogram. An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter. diff --git a/exercises/largest-series-product/README.md b/exercises/largest-series-product/README.md index a0834ad19a..e459fec2fb 100644 --- a/exercises/largest-series-product/README.md +++ b/exercises/largest-series-product/README.md @@ -1,5 +1,3 @@ -# Largest_series_product - Given a string of digits, calculate the largest product for a contiguous substring of digits of length n. diff --git a/exercises/leap/README.md b/exercises/leap/README.md index 736b110300..228a95b0f9 100644 --- a/exercises/leap/README.md +++ b/exercises/leap/README.md @@ -1,5 +1,3 @@ -# Leap - Given a year, report if it is a leap year. The tricky thing here is that a leap year in the Gregorian calendar occurs: diff --git a/exercises/luhn/README.md b/exercises/luhn/README.md index 2b4ab67d9f..c98fcac7f1 100644 --- a/exercises/luhn/README.md +++ b/exercises/luhn/README.md @@ -1,5 +1,3 @@ -# Luhn - Given a number determine whether or not it is valid per the Luhn formula. The [Luhn algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) is diff --git a/exercises/nth-prime/README.md b/exercises/nth-prime/README.md index ec17ced736..9a9825ca02 100644 --- a/exercises/nth-prime/README.md +++ b/exercises/nth-prime/README.md @@ -1,5 +1,3 @@ -# Nth_prime - Given a number n, determine what the nth prime is. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that diff --git a/exercises/ocr-numbers/README.md b/exercises/ocr-numbers/README.md index 80e4fed8ae..4d2ebe2cee 100644 --- a/exercises/ocr-numbers/README.md +++ b/exercises/ocr-numbers/README.md @@ -1,5 +1,3 @@ -# Ocr_numbers - Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled. diff --git a/exercises/pangram/README.md b/exercises/pangram/README.md index 6430420343..d82f393858 100644 --- a/exercises/pangram/README.md +++ b/exercises/pangram/README.md @@ -1,5 +1,3 @@ -# Pangram - Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is: diff --git a/exercises/phone-number/README.md b/exercises/phone-number/README.md index 1fa4ae1817..511388b168 100644 --- a/exercises/phone-number/README.md +++ b/exercises/phone-number/README.md @@ -1,5 +1,3 @@ -# Phone_number - Clean up user-entered phone numbers so that they can be sent SMS messages. The **North American Numbering Plan (NANP)** is a telephone numbering system used by many countries in North America like the United States, Canada or Bermuda. All NANP-countries share the same international country code: `1`. diff --git a/exercises/pig-latin/README.md b/exercises/pig-latin/README.md index 37e72687f2..57db2bfab2 100644 --- a/exercises/pig-latin/README.md +++ b/exercises/pig-latin/README.md @@ -1,5 +1,3 @@ -# Pig_latin - Implement a program that translates from English to Pig Latin. Pig Latin is a made-up children's language that's intended to be diff --git a/exercises/queen-attack/README.md b/exercises/queen-attack/README.md index 65c774d6ae..726ba4b30b 100644 --- a/exercises/queen-attack/README.md +++ b/exercises/queen-attack/README.md @@ -1,5 +1,3 @@ -# Queen_attack - Given the position of two queens on a chess board, indicate whether or not they are positioned so that they can attack each other. diff --git a/exercises/raindrops/README.md b/exercises/raindrops/README.md index 01ad82693b..3fa7843a21 100644 --- a/exercises/raindrops/README.md +++ b/exercises/raindrops/README.md @@ -1,5 +1,3 @@ -# Raindrops - Convert a number to a string, the contents of which depend on the number's factors. - If the number has 3 as a factor, output 'Pling'. diff --git a/exercises/rna-transcription/README.md b/exercises/rna-transcription/README.md index 14db36fecd..d27e048b89 100644 --- a/exercises/rna-transcription/README.md +++ b/exercises/rna-transcription/README.md @@ -1,5 +1,3 @@ -# Rna_transcription - Given a DNA strand, return its RNA complement (per RNA transcription). Both DNA and RNA strands are a sequence of nucleotides. diff --git a/exercises/roman-numerals/README.md b/exercises/roman-numerals/README.md index 575ad4a9d1..739f1260cc 100644 --- a/exercises/roman-numerals/README.md +++ b/exercises/roman-numerals/README.md @@ -1,5 +1,3 @@ -# Roman_numerals - Write a function to convert from normal numbers to Roman Numerals. The Romans were a clever bunch. They conquered most of Europe and ruled diff --git a/exercises/rotational-cipher/README.md b/exercises/rotational-cipher/README.md index 692e297416..5a238b181d 100644 --- a/exercises/rotational-cipher/README.md +++ b/exercises/rotational-cipher/README.md @@ -1,5 +1,3 @@ -# Rotational_cipher - Create an implementation of the rotational cipher, also sometimes called the Caesar cipher. The Caesar cipher is a simple shift cipher that relies on diff --git a/exercises/run-length-encoding/README.md b/exercises/run-length-encoding/README.md index 7180226004..d2ad10abad 100644 --- a/exercises/run-length-encoding/README.md +++ b/exercises/run-length-encoding/README.md @@ -1,5 +1,3 @@ -# Run_length_encoding - Implement run-length encoding and decoding. Run-length encoding (RLE) is a simple form of data compression, where runs diff --git a/exercises/say/README.md b/exercises/say/README.md index ca48147b31..2443af225f 100644 --- a/exercises/say/README.md +++ b/exercises/say/README.md @@ -1,5 +1,3 @@ -# Say - Given a number from 0 to 999,999,999,999, spell out that number in English. ## Step 1 diff --git a/exercises/sieve/README.md b/exercises/sieve/README.md index 1583c4d493..b2b560c0ac 100644 --- a/exercises/sieve/README.md +++ b/exercises/sieve/README.md @@ -1,5 +1,3 @@ -# Sieve - Use the Sieve of Eratosthenes to find all the primes from 2 up to a given number. diff --git a/exercises/space-age/README.md b/exercises/space-age/README.md index 4c7fd08807..9d0569a083 100644 --- a/exercises/space-age/README.md +++ b/exercises/space-age/README.md @@ -1,5 +1,3 @@ -# Space_age - Given an age in seconds, calculate how old someone would be on: - Earth: orbital period 365.25 Earth days, or 31557600 seconds diff --git a/exercises/sum-of-multiples/README.md b/exercises/sum-of-multiples/README.md index b715befb28..ba5e02fb87 100644 --- a/exercises/sum-of-multiples/README.md +++ b/exercises/sum-of-multiples/README.md @@ -1,5 +1,3 @@ -# Sum_of_multiples - Given a number, find the sum of all the multiples of particular numbers up to but not including that number. diff --git a/exercises/tournament/README.md b/exercises/tournament/README.md index c7f97f9127..aaf6ff6ba3 100644 --- a/exercises/tournament/README.md +++ b/exercises/tournament/README.md @@ -1,5 +1,3 @@ -# Tournament - Tally the results of a small football competition. Based on an input file containing which team played against which and what the diff --git a/exercises/transpose/README.md b/exercises/transpose/README.md index 31598f7464..53975b63f3 100644 --- a/exercises/transpose/README.md +++ b/exercises/transpose/README.md @@ -1,5 +1,3 @@ -# Transpose - Given an input text output it transposed. Roughly explained, the transpose of a matrix: diff --git a/exercises/triangle/README.md b/exercises/triangle/README.md index 0c5683fd53..a2e12959b0 100644 --- a/exercises/triangle/README.md +++ b/exercises/triangle/README.md @@ -1,5 +1,3 @@ -# Triangle - Determine if a triangle is equilateral, isosceles, or scalene. An _equilateral_ triangle has all three sides the same length.
diff --git a/exercises/two-bucket/README.md b/exercises/two-bucket/README.md index 6c952273ca..35b14cc8c7 100644 --- a/exercises/two-bucket/README.md +++ b/exercises/two-bucket/README.md @@ -1,5 +1,3 @@ -# Two_bucket - Given two buckets of different size, demonstrate how to measure an exact number of liters by strategically transferring liters of fluid between the buckets. Since this mathematical problem is fairly subject to interpretation / individual approach, the tests have been written specifically to expect one overarching solution. diff --git a/exercises/word-count/README.md b/exercises/word-count/README.md index ce3aa359ab..f724141f79 100644 --- a/exercises/word-count/README.md +++ b/exercises/word-count/README.md @@ -1,5 +1,3 @@ -# Word_count - Given a phrase, count the occurrences of each word in that phrase. For example for the input `"olly olly in come free"` diff --git a/exercises/wordy/README.md b/exercises/wordy/README.md index 81dd20b546..1fabc3a14c 100644 --- a/exercises/wordy/README.md +++ b/exercises/wordy/README.md @@ -1,5 +1,3 @@ -# Wordy - Parse and evaluate simple math word problems returning the answer as an integer. diff --git a/lib/generator/exercise.rb b/lib/generator/exercise.rb index 801cbd1cca..6caf6f5542 100644 --- a/lib/generator/exercise.rb +++ b/lib/generator/exercise.rb @@ -16,6 +16,10 @@ def directory "exercises/#{@slug}" end + def readme + "exercises/#{@slug}/README.md" + end + def case_class slug.camel_case + 'Case' end diff --git a/lib/generator/implementation.rb b/lib/generator/implementation.rb index ed983845a2..36d934cd93 100644 --- a/lib/generator/implementation.rb +++ b/lib/generator/implementation.rb @@ -36,13 +36,9 @@ def build_tests def build_readme canonicalDocs = File.read(@repository.canonical_data().docs) - docs = File.read(@repository.paths.docs) - ne = "#{@repository.paths.track}/#{@exercise.directory}/README.md" - File.open(ne, "w") do |handle| - handle.puts "# #{@exercise.name.capitalize}\n\n" - handle.puts "#{canonicalDocs}\n" - handle.puts docs - end + rubyDocs = File.read(@repository.paths.docs) + readme = File.join(@repository.paths.track, @exercise.readme) + File.open(readme, "w") { |handle| handle.puts "#{canonicalDocs}\n#{rubyDocs}" } end end diff --git a/test/fixtures/docs/EXERCISE_README_INSERT.md b/test/fixtures/docs/EXERCISE_README_INSERT.md new file mode 100644 index 0000000000..bcce0b9f76 --- /dev/null +++ b/test/fixtures/docs/EXERCISE_README_INSERT.md @@ -0,0 +1,2 @@ +**** +Ruby instructions on how to run tests. \ No newline at end of file diff --git a/test/fixtures/metadata/exercises/alpha/description.md b/test/fixtures/metadata/exercises/alpha/description.md new file mode 100644 index 0000000000..dbeab99431 --- /dev/null +++ b/test/fixtures/metadata/exercises/alpha/description.md @@ -0,0 +1,5 @@ +Add two numbers together + +## Requirements + +* The numbers should be added together diff --git a/test/generator/implementation_test.rb b/test/generator/implementation_test.rb index a54c809bd1..478e26262a 100644 --- a/test/generator/implementation_test.rb +++ b/test/generator/implementation_test.rb @@ -4,7 +4,7 @@ module Generator class ImplementationTest < Minitest::Test FixturePaths = Paths.new( metadata: 'test/fixtures/metadata', - docs: 'test/fixtures/metadata', + docs: 'test/fixtures/docs/EXERCISE_README_INSERT.md', track: 'test/fixtures/ruby' ) @@ -97,6 +97,16 @@ def test_bookkeeping # Don't pollute the namespace Object.send(:remove_const, :AlphaCase) end + + def test_build_readme + expected_content = "Add two numbers together\n\n## Requirements\n\n* The numbers should be added together\n\n****\nRuby instructions on how to run tests." + mock_file = Minitest::Mock.new.expect :puts, expected_content.length, [expected_content] + exercise = Exercise.new(slug: 'alpha') + repository = Repository.new(paths: FixturePaths, slug: 'alpha') + subject = Implementation.new(repository: repository, exercise: exercise) + File.stub(:open, true, mock_file) { subject.build_readme } + mock_file.verify + end end class LoggingImplementationTest < Minitest::Test @@ -115,6 +125,20 @@ def test_build_tests mock_implementation.verify end + def test_build_readme + exercise = Exercise.new(slug: 'alpha') + mock_implementation = Minitest::Mock.new + mock_implementation.expect :build_readme, nil + mock_implementation.expect :exercise, exercise + mock_logger = Minitest::Mock.new + mock_logger.expect :info, nil, ['Generated alpha README'] + + subject = LoggingImplementation.new(implementation: mock_implementation, logger: mock_logger) + subject.build_readme + + mock_implementation.verify + end + def test_update_tests_version mock_implementation = Minitest::Mock.new mock_implementation.expect :update_tests_version, nil