diff --git a/README.md b/README.md index 10fee7b5..4ebcc048 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Exercism Workspace | July | Jurassic | C (5/5), C++ (5/5), Fortran (0/5) | | August | Apps | Dart (5/5), Java (0/5), Kotlin (0/5) | | September | Slimline | Awk (5/5), Bash\* (5/5), jq (0/5), Perl (0/5) | -| October | Object-Oriented | Ruby (0/5), Java (0/5) | +| October | Object-Oriented | Ruby (1/5), Java (0/5) | | November | Nibbly | | | December | Diversions | | diff --git a/ruby/README.md b/ruby/README.md index f92f11f4..49cb1da3 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -66,3 +66,5 @@ - [protein-translation](./protein-translation/README.md) - [series](./series/README.md) - [word-count](./word-count/README.md) +- [allergies](./allergies/README.md) +- [simple-cipher](./simple-cipher/README.md) diff --git a/ruby/allergies/.exercism/config.json b/ruby/allergies/.exercism/config.json new file mode 100644 index 00000000..27e2c66f --- /dev/null +++ b/ruby/allergies/.exercism/config.json @@ -0,0 +1,32 @@ +{ + "authors": [ + "kytrinyx" + ], + "contributors": [ + "ajwann", + "budmc29", + "cadwallion", + "hilary", + "iHiD", + "Insti", + "jpotts244", + "kotp", + "mikegehard", + "pendletons", + "tryantwit" + ], + "files": { + "solution": [ + "allergies.rb" + ], + "test": [ + "allergies_test.rb" + ], + "example": [ + ".meta/example.rb" + ] + }, + "blurb": "Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.", + "source": "Exercise by the JumpstartLab team for students at The Turing School of Software and Design.", + "source_url": "https://turing.edu" +} diff --git a/ruby/allergies/.exercism/metadata.json b/ruby/allergies/.exercism/metadata.json new file mode 100644 index 00000000..f25df91f --- /dev/null +++ b/ruby/allergies/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"ruby","exercise":"allergies","id":"fbd4b08f2e4b47b6830990e8560871b6","url":"https://exercism.org/tracks/ruby/exercises/allergies","handle":"vpayno","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/ruby/allergies/HELP.md b/ruby/allergies/HELP.md new file mode 100644 index 00000000..659e3a08 --- /dev/null +++ b/ruby/allergies/HELP.md @@ -0,0 +1,54 @@ +# Help + +## Running the tests + +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 +``` + + +Run the tests from the exercise directory using the following command: + +``` +ruby _test.rb +``` + +Please replace `` with your exercise name in snake_case. + +## Color output + +You can `require 'minitest/pride'` or run the following command to get colored output: + +``` +ruby -r minitest/pride _test.rb +``` + +## Submitting your solution + +You can submit your solution using the `exercism submit allergies.rb` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Ruby track's documentation](https://exercism.org/docs/tracks/ruby) +- The [Ruby track's programming category on the forum](https://forum.exercism.org/c/programming/ruby) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Ruby Documentation](http://ruby-doc.org/) +- [StackOverflow](http://stackoverflow.com/questions/tagged/ruby) +- [/r/ruby](https://www.reddit.com/r/ruby) is the Ruby subreddit. \ No newline at end of file diff --git a/ruby/allergies/README.md b/ruby/allergies/README.md new file mode 100644 index 00000000..feb15708 --- /dev/null +++ b/ruby/allergies/README.md @@ -0,0 +1,61 @@ +# Allergies + +Welcome to Allergies on Exercism's Ruby Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies. + +An allergy test produces a single numeric score which contains the information about all the allergies the person has (that they were tested for). + +The list of items (and their value) that were tested are: + +- eggs (1) +- peanuts (2) +- shellfish (4) +- strawberries (8) +- tomatoes (16) +- chocolate (32) +- pollen (64) +- cats (128) + +So if Tom is allergic to peanuts and chocolate, he gets a score of 34. + +Now, given just that score of 34, your program should be able to say: + +- Whether Tom is allergic to any one of those allergens listed above. +- All the allergens Tom is allergic to. + +Note: a given score may include allergens **not** listed above (i.e. allergens that score 256, 512, 1024, etc.). +Your program should ignore those components of the score. +For example, if the allergy score is 257, your program should only report the eggs (1) allergy. + +## Source + +### Created by + +- @kytrinyx + +### Contributed to by + +- @ajwann +- @budmc29 +- @cadwallion +- @hilary +- @iHiD +- @Insti +- @jpotts244 +- @kotp +- @mikegehard +- @pendletons +- @tryantwit + +### Based on + +Exercise by the JumpstartLab team for students at The Turing School of Software and Design. - https://turing.edu + +### My Solution + +- [my solution](./allergies.rb) +- [run-tests](./run-tests-ruby.txt) diff --git a/ruby/allergies/allergies.rb b/ruby/allergies/allergies.rb new file mode 100644 index 00000000..19838ac9 --- /dev/null +++ b/ruby/allergies/allergies.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: false + +# https://exercism.org/tracks/ruby/exercises/allergies +# Allergies exercise +class Allergies + def initialize(score) + @score = score + + @allergies = { + 'eggs' => 1, + 'peanuts' => 2, + 'shellfish' => 4, + 'strawberries' => 8, + 'tomatoes' => 16, + 'chocolate' => 32, + 'pollen' => 64, + 'cats' => 128 + } + end + + def allergic_to?(allergen) + (@allergies.fetch(allergen, 0) & @score).positive? + end + + def list + allergic_reactions = [] + + @allergies.each_pair do |key, value| + allergic_reactions.push(key) unless (value & @score).zero? + end + + allergic_reactions + end +end diff --git a/ruby/allergies/allergies_test.rb b/ruby/allergies/allergies_test.rb new file mode 100644 index 00000000..a93c613e --- /dev/null +++ b/ruby/allergies/allergies_test.rb @@ -0,0 +1,328 @@ +# frozen_string_literal: false + +# https://github.com/simplecov-ruby/simplecov +require 'simplecov' + +# https://about.codecov.io/blog/getting-started-with-code-coverage-for-ruby/ +require 'simplecov-cobertura' +SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter + +# line coverage +SimpleCov.start if ENV['COVERAGE'] != 'branch' + +# branch coverage +if ENV['COVERAGE'] == 'branch' + SimpleCov.start do + enable_coverage :branch + primary_coverage :branch + end +end + +# name the test file/group +SimpleCov.command_name 'test:exercism' + +# original exercism tests +require 'minitest/autorun' +require_relative 'allergies' + +class AllergiesTest < Minitest::Test + def test_testing_for_eggs_allergy_not_allergic_to_anything + # skip + allergies = Allergies.new(0) + refute allergies.allergic_to?('eggs'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_eggs_allergy_allergic_only_to_eggs + # skip + allergies = Allergies.new(1) + assert allergies.allergic_to?('eggs'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_eggs_allergy_allergic_to_eggs_and_something_else + # skip + allergies = Allergies.new(3) + assert allergies.allergic_to?('eggs'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_eggs_allergy_allergic_to_something_but_not_eggs + # skip + allergies = Allergies.new(2) + refute allergies.allergic_to?('eggs'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_eggs_allergy_allergic_to_everything + # skip + allergies = Allergies.new(255) + assert allergies.allergic_to?('eggs'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_peanuts_allergy_not_allergic_to_anything + # skip + allergies = Allergies.new(0) + refute allergies.allergic_to?('peanuts'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_peanuts_allergy_allergic_only_to_peanuts + # skip + allergies = Allergies.new(2) + assert allergies.allergic_to?('peanuts'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_peanuts_allergy_allergic_to_peanuts_and_something_else + # skip + allergies = Allergies.new(7) + assert allergies.allergic_to?('peanuts'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_peanuts_allergy_allergic_to_something_but_not_peanuts + # skip + allergies = Allergies.new(5) + refute allergies.allergic_to?('peanuts'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_peanuts_allergy_allergic_to_everything + # skip + allergies = Allergies.new(255) + assert allergies.allergic_to?('peanuts'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_shellfish_allergy_not_allergic_to_anything + # skip + allergies = Allergies.new(0) + refute allergies.allergic_to?('shellfish'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_shellfish_allergy_allergic_only_to_shellfish + # skip + allergies = Allergies.new(4) + assert allergies.allergic_to?('shellfish'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_shellfish_allergy_allergic_to_shellfish_and_something_else + # skip + allergies = Allergies.new(14) + assert allergies.allergic_to?('shellfish'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_shellfish_allergy_allergic_to_something_but_not_shellfish + # skip + allergies = Allergies.new(10) + refute allergies.allergic_to?('shellfish'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_shellfish_allergy_allergic_to_everything + # skip + allergies = Allergies.new(255) + assert allergies.allergic_to?('shellfish'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_strawberries_allergy_not_allergic_to_anything + # skip + allergies = Allergies.new(0) + refute allergies.allergic_to?('strawberries'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_strawberries_allergy_allergic_only_to_strawberries + # skip + allergies = Allergies.new(8) + assert allergies.allergic_to?('strawberries'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_strawberries_allergy_allergic_to_strawberries_and_something_else + # skip + allergies = Allergies.new(28) + assert allergies.allergic_to?('strawberries'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_strawberries_allergy_allergic_to_something_but_not_strawberries + # skip + allergies = Allergies.new(20) + refute allergies.allergic_to?('strawberries'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_strawberries_allergy_allergic_to_everything + # skip + allergies = Allergies.new(255) + assert allergies.allergic_to?('strawberries'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_tomatoes_allergy_not_allergic_to_anything + # skip + allergies = Allergies.new(0) + refute allergies.allergic_to?('tomatoes'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_tomatoes_allergy_allergic_only_to_tomatoes + # skip + allergies = Allergies.new(16) + assert allergies.allergic_to?('tomatoes'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_tomatoes_allergy_allergic_to_tomatoes_and_something_else + # skip + allergies = Allergies.new(56) + assert allergies.allergic_to?('tomatoes'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_tomatoes_allergy_allergic_to_something_but_not_tomatoes + # skip + allergies = Allergies.new(40) + refute allergies.allergic_to?('tomatoes'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_tomatoes_allergy_allergic_to_everything + # skip + allergies = Allergies.new(255) + assert allergies.allergic_to?('tomatoes'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_chocolate_allergy_not_allergic_to_anything + # skip + allergies = Allergies.new(0) + refute allergies.allergic_to?('chocolate'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_chocolate_allergy_allergic_only_to_chocolate + # skip + allergies = Allergies.new(32) + assert allergies.allergic_to?('chocolate'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_chocolate_allergy_allergic_to_chocolate_and_something_else + # skip + allergies = Allergies.new(112) + assert allergies.allergic_to?('chocolate'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_chocolate_allergy_allergic_to_something_but_not_chocolate + # skip + allergies = Allergies.new(80) + refute allergies.allergic_to?('chocolate'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_chocolate_allergy_allergic_to_everything + # skip + allergies = Allergies.new(255) + assert allergies.allergic_to?('chocolate'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_pollen_allergy_not_allergic_to_anything + # skip + allergies = Allergies.new(0) + refute allergies.allergic_to?('pollen'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_pollen_allergy_allergic_only_to_pollen + # skip + allergies = Allergies.new(64) + assert allergies.allergic_to?('pollen'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_pollen_allergy_allergic_to_pollen_and_something_else + # skip + allergies = Allergies.new(224) + assert allergies.allergic_to?('pollen'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_pollen_allergy_allergic_to_something_but_not_pollen + # skip + allergies = Allergies.new(160) + refute allergies.allergic_to?('pollen'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_pollen_allergy_allergic_to_everything + # skip + allergies = Allergies.new(255) + assert allergies.allergic_to?('pollen'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_cats_allergy_not_allergic_to_anything + # skip + allergies = Allergies.new(0) + refute allergies.allergic_to?('cats'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_cats_allergy_allergic_only_to_cats + # skip + allergies = Allergies.new(128) + assert allergies.allergic_to?('cats'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_cats_allergy_allergic_to_cats_and_something_else + # skip + allergies = Allergies.new(192) + assert allergies.allergic_to?('cats'), 'Tom is allergic, but it says he is not.' + end + + def test_testing_for_cats_allergy_allergic_to_something_but_not_cats + # skip + allergies = Allergies.new(64) + refute allergies.allergic_to?('cats'), 'Tom is not allergic, but it says he is.' + end + + def test_testing_for_cats_allergy_allergic_to_everything + # skip + allergies = Allergies.new(255) + assert allergies.allergic_to?('cats'), 'Tom is allergic, but it says he is not.' + end + + def test_list_when_no_allergies + # skip + expected = [] + assert_equal expected, Allergies.new(0).list + end + + def test_list_when_just_eggs + # skip + expected = ['eggs'] + assert_equal expected, Allergies.new(1).list + end + + def test_list_when_just_peanuts + # skip + expected = ['peanuts'] + assert_equal expected, Allergies.new(2).list + end + + def test_list_when_just_strawberries + # skip + expected = ['strawberries'] + assert_equal expected, Allergies.new(8).list + end + + def test_list_when_eggs_and_peanuts + # skip + expected = %w[eggs peanuts] + assert_equal expected, Allergies.new(3).list + end + + def test_list_when_more_than_eggs_but_not_peanuts + # skip + expected = %w[eggs shellfish] + assert_equal expected, Allergies.new(5).list + end + + def test_list_when_lots_of_stuff + # skip + expected = %w[strawberries tomatoes chocolate pollen cats] + assert_equal expected, Allergies.new(248).list + end + + def test_list_when_everything + # skip + expected = %w[eggs peanuts shellfish strawberries tomatoes chocolate pollen cats] + assert_equal expected, Allergies.new(255).list + end + + def test_list_when_no_allergen_score_parts + # skip + expected = %w[eggs shellfish strawberries tomatoes chocolate pollen cats] + assert_equal expected, Allergies.new(509).list + end + + def test_list_when_no_allergen_score_parts_without_highest_valid_score + # skip + expected = ['eggs'] + assert_equal expected, Allergies.new(257).list + end +end diff --git a/ruby/allergies/coverage/.last_run.json b/ruby/allergies/coverage/.last_run.json new file mode 100644 index 00000000..52d2bf29 --- /dev/null +++ b/ruby/allergies/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "line": 100.0 + } +} diff --git a/ruby/allergies/coverage/.resultset.json b/ruby/allergies/coverage/.resultset.json new file mode 100644 index 00000000..d0253d4d --- /dev/null +++ b/ruby/allergies/coverage/.resultset.json @@ -0,0 +1,45 @@ +{ + "test:exercism": { + "coverage": { + "/home/vpayno/git_vpayno/exercism-workspace/ruby/allergies/allergies.rb": { + "lines": [ + null, + null, + null, + null, + 1, + 1, + 50, + null, + 50, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + 40, + null, + null, + 1, + 10, + null, + 10, + 80, + null, + null, + 10, + null, + null + ] + } + }, + "timestamp": 1698442692 + } +} diff --git a/ruby/allergies/coverage/.resultset.json.lock b/ruby/allergies/coverage/.resultset.json.lock new file mode 100644 index 00000000..e69de29b diff --git a/ruby/allergies/coverage/coverage.xml b/ruby/allergies/coverage/coverage.xml new file mode 100644 index 00000000..0266f6f5 --- /dev/null +++ b/ruby/allergies/coverage/coverage.xml @@ -0,0 +1,30 @@ + + + + + + /home/vpayno/git_vpayno/exercism-workspace/ruby/allergies + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ruby/allergies/run-tests-ruby.txt b/ruby/allergies/run-tests-ruby.txt new file mode 100644 index 00000000..f9517be4 --- /dev/null +++ b/ruby/allergies/run-tests-ruby.txt @@ -0,0 +1,494 @@ +Running automated test file(s): + + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-lint-rubycritic + +Running RubyCritic + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + rbenv 1.2.0-11-ge4f61e6 + + + ============================================================================== + +Running: rubycritic --path .rubycritic --format console --no-browser . + +running flay smells + +running flog smells +.. +running reek smells +.. +running complexity +.. +running attributes +.. +running churn +.. +running simple_cov +.. +/home/vpayno/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubycritic-4.6.1/lib/rubycritic/generators/text/list.rb:13: warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments. +/home/vpayno/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubycritic-4.6.1/lib/rubycritic/generators/text/list.rb:13: warning: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead. +Allergies: + Rating: A + Churn: 0 + Complexity: 11.58 + Duplication: 0 + Smells: 0 + +AllergiesTest: + Rating: D + Churn: 0 + Complexity: 200.93 + Duplication: 0 + Smells: 2 + * (IrresponsibleModule) AllergiesTest has no descriptive comment + - allergies_test.rb:28 + * (TooManyMethods) AllergiesTest has at least 50 methods + - allergies_test.rb:28 +Score: 73.44 + +real 0m0.723s +user 0m0.609s +sys 0m0.111s + + + ============================================================================== + +Exit code: 0 + +real 0m0.818s +user 0m0.654s +sys 0m0.168s + +real 0m0.822s +user 0m0.657s +sys 0m0.168s + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-lint-formatter + +Running Ruby Formatter + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + rbenv 1.2.0-11-ge4f61e6 + + + ============================================================================== + +Running: rubocop -a . + +Inspecting 2 files +CC + +Offenses: + +allergies.rb:6:3: C: Metrics/MethodLength: Method has too many lines. [11/10] + def initialize(score) ... + ^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:28:1: C: Metrics/ClassLength: Class has too many lines. [200/100] +class AllergiesTest < Minitest::Test ... +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:28:1: C: Style/Documentation: Missing top-level documentation comment for class AllergiesTest. +class AllergiesTest < Minitest::Test +^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:32:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("eggs"), "Tom is not allergic, but it says he is." + ^^^^^^ +allergies_test.rb:32:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("eggs"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:38:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + ^^^^^^ +allergies_test.rb:38:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:44:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + ^^^^^^ +allergies_test.rb:44:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:50:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("eggs"), "Tom is not allergic, but it says he is." + ^^^^^^ +allergies_test.rb:50:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("eggs"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:56:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + ^^^^^^ +allergies_test.rb:56:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("eggs"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:62:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("peanuts"), "Tom is not allergic, but it says he is." + ^^^^^^^^^ +allergies_test.rb:62:47: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("peanuts"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:68:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + ^^^^^^^^^ +allergies_test.rb:68:47: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:74:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + ^^^^^^^^^ +allergies_test.rb:74:47: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:80:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("peanuts"), "Tom is not allergic, but it says he is." + ^^^^^^^^^ +allergies_test.rb:80:47: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("peanuts"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:86:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + ^^^^^^^^^ +allergies_test.rb:86:47: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("peanuts"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:92:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("shellfish"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^ +allergies_test.rb:92:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("shellfish"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:98:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^ +allergies_test.rb:98:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:104:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^ +allergies_test.rb:104:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:110:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("shellfish"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^ +allergies_test.rb:110:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("shellfish"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:116:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^ +allergies_test.rb:116:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("shellfish"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:122:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("strawberries"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^ +allergies_test.rb:122:52: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("strawberries"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:128:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^ +allergies_test.rb:128:52: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:134:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^ +allergies_test.rb:134:52: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:140:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("strawberries"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^ +allergies_test.rb:140:52: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("strawberries"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:146:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^ +allergies_test.rb:146:52: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("strawberries"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:152:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("tomatoes"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^ +allergies_test.rb:152:48: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("tomatoes"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:158:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^ +allergies_test.rb:158:48: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:164:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^ +allergies_test.rb:164:48: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:170:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("tomatoes"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^ +allergies_test.rb:170:48: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("tomatoes"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:176:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^ +allergies_test.rb:176:48: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("tomatoes"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:182:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("chocolate"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^ +allergies_test.rb:182:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("chocolate"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:188:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^ +allergies_test.rb:188:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:194:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^ +allergies_test.rb:194:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:200:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("chocolate"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^ +allergies_test.rb:200:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("chocolate"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:206:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^ +allergies_test.rb:206:49: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("chocolate"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:212:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("pollen"), "Tom is not allergic, but it says he is." + ^^^^^^^^ +allergies_test.rb:212:46: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("pollen"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:218:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + ^^^^^^^^ +allergies_test.rb:218:46: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:224:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + ^^^^^^^^ +allergies_test.rb:224:46: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:230:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("pollen"), "Tom is not allergic, but it says he is." + ^^^^^^^^ +allergies_test.rb:230:46: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("pollen"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:236:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + ^^^^^^^^ +allergies_test.rb:236:46: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("pollen"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:242:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("cats"), "Tom is not allergic, but it says he is." + ^^^^^^ +allergies_test.rb:242:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("cats"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:248:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + ^^^^^^ +allergies_test.rb:248:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:254:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + ^^^^^^ +allergies_test.rb:254:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:260:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("cats"), "Tom is not allergic, but it says he is." + ^^^^^^ +allergies_test.rb:260:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + refute allergies.allergic_to?("cats"), "Tom is not allergic, but it says he is." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:266:35: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + ^^^^^^ +allergies_test.rb:266:44: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + assert allergies.allergic_to?("cats"), "Tom is allergic, but it says he is not." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +allergies_test.rb:277:17: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + expected = ["eggs"] + ^^^^^^ +allergies_test.rb:283:17: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + expected = ["peanuts"] + ^^^^^^^^^ +allergies_test.rb:289:17: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + expected = ["strawberries"] + ^^^^^^^^^^^^^^ +allergies_test.rb:325:17: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. + expected = ["eggs"] + ^^^^^^ + +2 files inspected, 87 offenses detected, 84 offenses corrected + +real 0m1.187s +user 0m1.068s +sys 0m0.224s + + + ============================================================================== + +Exit code: -1 + +real 0m1.262s +user 0m1.096s +sys 0m0.274s + +real 0m1.265s +user 0m1.098s +sys 0m0.276s + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-test-with-coverage + +Running Ruby Tests With Coverage + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + rbenv 1.2.0-11-ge4f61e6 + + + ============================================================================== + +Running: rm -rf ./coverage + + +real 0m0.002s +user 0m0.002s +sys 0m0.001s + + + ============================================================================== + +Running: ruby ./allergies_test.rb -v + +Run options: -v --seed 40395 + +# Running: + +AllergiesTest#test_list_when_more_than_eggs_but_not_peanuts = 0.00 s = . +AllergiesTest#test_testing_for_peanuts_allergy_not_allergic_to_anything = 0.00 s = . +AllergiesTest#test_testing_for_shellfish_allergy_allergic_to_something_but_not_shellfish = 0.00 s = . +AllergiesTest#test_testing_for_eggs_allergy_not_allergic_to_anything = 0.00 s = . +AllergiesTest#test_testing_for_pollen_allergy_allergic_to_everything = 0.00 s = . +AllergiesTest#test_testing_for_shellfish_allergy_not_allergic_to_anything = 0.00 s = . +AllergiesTest#test_testing_for_tomatoes_allergy_allergic_to_everything = 0.00 s = . +AllergiesTest#test_testing_for_chocolate_allergy_allergic_to_everything = 0.00 s = . +AllergiesTest#test_testing_for_cats_allergy_not_allergic_to_anything = 0.00 s = . +AllergiesTest#test_testing_for_chocolate_allergy_not_allergic_to_anything = 0.00 s = . +AllergiesTest#test_testing_for_shellfish_allergy_allergic_only_to_shellfish = 0.00 s = . +AllergiesTest#test_testing_for_cats_allergy_allergic_to_cats_and_something_else = 0.00 s = . +AllergiesTest#test_testing_for_peanuts_allergy_allergic_to_everything = 0.00 s = . +AllergiesTest#test_testing_for_shellfish_allergy_allergic_to_shellfish_and_something_else = 0.00 s = . +AllergiesTest#test_testing_for_strawberries_allergy_allergic_only_to_strawberries = 0.00 s = . +AllergiesTest#test_list_when_everything = 0.00 s = . +AllergiesTest#test_testing_for_eggs_allergy_allergic_to_something_but_not_eggs = 0.00 s = . +AllergiesTest#test_testing_for_chocolate_allergy_allergic_to_chocolate_and_something_else = 0.00 s = . +AllergiesTest#test_testing_for_peanuts_allergy_allergic_only_to_peanuts = 0.00 s = . +AllergiesTest#test_testing_for_strawberries_allergy_allergic_to_strawberries_and_something_else = 0.00 s = . +AllergiesTest#test_list_when_lots_of_stuff = 0.00 s = . +AllergiesTest#test_testing_for_tomatoes_allergy_not_allergic_to_anything = 0.00 s = . +AllergiesTest#test_testing_for_cats_allergy_allergic_to_everything = 0.00 s = . +AllergiesTest#test_testing_for_strawberries_allergy_allergic_to_something_but_not_strawberries = 0.00 s = . +AllergiesTest#test_testing_for_tomatoes_allergy_allergic_only_to_tomatoes = 0.00 s = . +AllergiesTest#test_testing_for_cats_allergy_allergic_only_to_cats = 0.00 s = . +AllergiesTest#test_testing_for_peanuts_allergy_allergic_to_something_but_not_peanuts = 0.00 s = . +AllergiesTest#test_testing_for_chocolate_allergy_allergic_to_something_but_not_chocolate = 0.00 s = . +AllergiesTest#test_testing_for_pollen_allergy_allergic_only_to_pollen = 0.00 s = . +AllergiesTest#test_testing_for_strawberries_allergy_not_allergic_to_anything = 0.00 s = . +AllergiesTest#test_list_when_no_allergen_score_parts = 0.00 s = . +AllergiesTest#test_testing_for_eggs_allergy_allergic_to_everything = 0.00 s = . +AllergiesTest#test_list_when_just_strawberries = 0.00 s = . +AllergiesTest#test_testing_for_cats_allergy_allergic_to_something_but_not_cats = 0.00 s = . +AllergiesTest#test_testing_for_chocolate_allergy_allergic_only_to_chocolate = 0.00 s = . +AllergiesTest#test_testing_for_pollen_allergy_allergic_to_pollen_and_something_else = 0.00 s = . +AllergiesTest#test_testing_for_strawberries_allergy_allergic_to_everything = 0.00 s = . +AllergiesTest#test_list_when_just_eggs = 0.00 s = . +AllergiesTest#test_list_when_just_peanuts = 0.00 s = . +AllergiesTest#test_testing_for_pollen_allergy_not_allergic_to_anything = 0.00 s = . +AllergiesTest#test_list_when_eggs_and_peanuts = 0.00 s = . +AllergiesTest#test_testing_for_peanuts_allergy_allergic_to_peanuts_and_something_else = 0.00 s = . +AllergiesTest#test_testing_for_eggs_allergy_allergic_only_to_eggs = 0.00 s = . +AllergiesTest#test_list_when_no_allergies = 0.00 s = . +AllergiesTest#test_testing_for_tomatoes_allergy_allergic_to_something_but_not_tomatoes = 0.00 s = . +AllergiesTest#test_testing_for_shellfish_allergy_allergic_to_everything = 0.00 s = . +AllergiesTest#test_testing_for_eggs_allergy_allergic_to_eggs_and_something_else = 0.00 s = . +AllergiesTest#test_testing_for_pollen_allergy_allergic_to_something_but_not_pollen = 0.00 s = . +AllergiesTest#test_list_when_no_allergen_score_parts_without_highest_valid_score = 0.00 s = . +AllergiesTest#test_testing_for_tomatoes_allergy_allergic_to_tomatoes_and_something_else = 0.00 s = . + +Finished in 0.002438s, 20507.6378 runs/s, 20507.6378 assertions/s. + +50 runs, 50 assertions, 0 failures, 0 errors, 0 skips +Coverage report generated for test:exercism to /home/vpayno/git_vpayno/exercism-workspace/ruby/allergies/coverage/coverage.xml. 11 / 11 LOC (100.00%) covered + +real 0m0.194s +user 0m0.130s +sys 0m0.064s + + + ============================================================================== + +Coverage: 100.0% + + ============================================================================== + +Exit code: 0 + +real 0m0.259s +user 0m0.160s +sys 0m0.103s + +real 0m0.261s +user 0m0.160s +sys 0m0.105s + +=============================================================================== + +Running: misspell . + +real 0m0.027s +user 0m0.031s +sys 0m0.013s + +=============================================================================== + +/home/vpayno/git_vpayno/exercism-workspace/ruby + +=============================================================================== + diff --git a/ruby/simple-cipher/.exercism/config.json b/ruby/simple-cipher/.exercism/config.json new file mode 100644 index 00000000..6fdd6e0c --- /dev/null +++ b/ruby/simple-cipher/.exercism/config.json @@ -0,0 +1,32 @@ +{ + "authors": [ + "vosechu" + ], + "contributors": [ + "budmc29", + "dalexj", + "dkinzer", + "hilary", + "iHiD", + "Insti", + "kotp", + "kytrinyx", + "markijbema", + "snoozer05", + "tryantwit" + ], + "files": { + "solution": [ + "simple_cipher.rb" + ], + "test": [ + "simple_cipher_test.rb" + ], + "example": [ + ".meta/example.rb" + ] + }, + "blurb": "Implement a simple shift cipher like Caesar and a more secure substitution cipher.", + "source": "Substitution Cipher at Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/Substitution_cipher" +} diff --git a/ruby/simple-cipher/.exercism/metadata.json b/ruby/simple-cipher/.exercism/metadata.json new file mode 100644 index 00000000..7c1da968 --- /dev/null +++ b/ruby/simple-cipher/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"ruby","exercise":"simple-cipher","id":"417479f6a0994aa79dd506f6fc55cf50","url":"https://exercism.org/tracks/ruby/exercises/simple-cipher","handle":"vpayno","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/ruby/simple-cipher/HELP.md b/ruby/simple-cipher/HELP.md new file mode 100644 index 00000000..c517db01 --- /dev/null +++ b/ruby/simple-cipher/HELP.md @@ -0,0 +1,54 @@ +# Help + +## Running the tests + +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 +``` + + +Run the tests from the exercise directory using the following command: + +``` +ruby _test.rb +``` + +Please replace `` with your exercise name in snake_case. + +## Color output + +You can `require 'minitest/pride'` or run the following command to get colored output: + +``` +ruby -r minitest/pride _test.rb +``` + +## Submitting your solution + +You can submit your solution using the `exercism submit simple_cipher.rb` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Ruby track's documentation](https://exercism.org/docs/tracks/ruby) +- The [Ruby track's programming category on the forum](https://forum.exercism.org/c/programming/ruby) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Ruby Documentation](http://ruby-doc.org/) +- [StackOverflow](http://stackoverflow.com/questions/tagged/ruby) +- [/r/ruby](https://www.reddit.com/r/ruby) is the Ruby subreddit. \ No newline at end of file diff --git a/ruby/simple-cipher/README.md b/ruby/simple-cipher/README.md new file mode 100644 index 00000000..03567418 --- /dev/null +++ b/ruby/simple-cipher/README.md @@ -0,0 +1,100 @@ +# Simple Cipher + +Welcome to Simple Cipher on Exercism's Ruby Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Implement a simple shift cipher like Caesar and a more secure substitution cipher. + +## Step 1 + +"If he had anything confidential to say, he wrote it in cipher, that is, by so changing the order of the letters of the alphabet, that not a word could be made out. +If anyone wishes to decipher these, and get at their meaning, he must substitute the fourth letter of the alphabet, namely D, for A, and so with the others." +—Suetonius, Life of Julius Caesar + +Ciphers are very straight-forward algorithms that allow us to render text less readable while still allowing easy deciphering. +They are vulnerable to many forms of cryptanalysis, but Caesar was lucky that his enemies were not cryptanalysts. + +The Caesar Cipher was used for some messages from Julius Caesar that were sent afield. +Now Caesar knew that the cipher wasn't very good, but he had one ally in that respect: almost nobody could read well. +So even being a couple letters off was sufficient so that people couldn't recognize the few words that they did know. + +Your task is to create a simple shift cipher like the Caesar Cipher. +This image is a great example of the Caesar Cipher: + +![Caesar Cipher][img-caesar-cipher] + +For example: + +Giving "iamapandabear" as input to the encode function returns the cipher "ldpdsdqgdehdu". +Obscure enough to keep our message secret in transit. + +When "ldpdsdqgdehdu" is put into the decode function it would return the original "iamapandabear" letting your friend read your original message. + +## Step 2 + +Shift ciphers quickly cease to be useful when the opposition commander figures them out. +So instead, let's try using a substitution cipher. +Try amending the code to allow us to specify a key and use that for the shift distance. + +Here's an example: + +Given the key "aaaaaaaaaaaaaaaaaa", encoding the string "iamapandabear" +would return the original "iamapandabear". + +Given the key "ddddddddddddddddd", encoding our string "iamapandabear" +would return the obscured "ldpdsdqgdehdu" + +In the example above, we've set a = 0 for the key value. +So when the plaintext is added to the key, we end up with the same message coming out. +So "aaaa" is not an ideal key. +But if we set the key to "dddd", we would get the same thing as the Caesar Cipher. + +## Step 3 + +The weakest link in any cipher is the human being. +Let's make your substitution cipher a little more fault tolerant by providing a source of randomness and ensuring that the key contains only lowercase letters. + +If someone doesn't submit a key at all, generate a truly random key of at least 100 lowercase characters in length. + +## Extensions + +Shift ciphers work by making the text slightly odd, but are vulnerable to frequency analysis. +Substitution ciphers help that, but are still very vulnerable when the key is short or if spaces are preserved. +Later on you'll see one solution to this problem in the exercise "crypto-square". + +If you want to go farther in this field, the questions begin to be about how we can exchange keys in a secure way. +Take a look at [Diffie-Hellman on Wikipedia][dh] for one of the first implementations of this scheme. + +[img-caesar-cipher]: https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Caesar_cipher_left_shift_of_3.svg/320px-Caesar_cipher_left_shift_of_3.svg.png +[dh]: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange + +## Source + +### Created by + +- @vosechu + +### Contributed to by + +- @budmc29 +- @dalexj +- @dkinzer +- @hilary +- @iHiD +- @Insti +- @kotp +- @kytrinyx +- @markijbema +- @snoozer05 +- @tryantwit + +### Based on + +Substitution Cipher at Wikipedia - https://en.wikipedia.org/wiki/Substitution_cipher + +### My Solution + +- [my solution](./simple_cipher.rb) +- [run-tests](./run-tests-ruby.txt) diff --git a/ruby/simple-cipher/coverage/.last_run.json b/ruby/simple-cipher/coverage/.last_run.json new file mode 100644 index 00000000..52d2bf29 --- /dev/null +++ b/ruby/simple-cipher/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "line": 100.0 + } +} diff --git a/ruby/simple-cipher/coverage/.resultset.json b/ruby/simple-cipher/coverage/.resultset.json new file mode 100644 index 00000000..cd0f7373 --- /dev/null +++ b/ruby/simple-cipher/coverage/.resultset.json @@ -0,0 +1,55 @@ +{ + "test:exercism": { + "coverage": { + "/home/vpayno/git_vpayno/exercism-workspace/ruby/simple-cipher/simple_cipher.rb": { + "lines": [ + null, + null, + null, + null, + 1, + 1, + null, + 1, + 417, + null, + 17, + 16, + null, + null, + 1, + 8, + 83, + null, + null, + null, + 1, + 6, + 60, + null, + null, + null, + 1, + null, + 1, + 83, + null, + null, + 1, + 60, + null, + null, + 1, + 286, + null, + null, + 1, + 143, + null, + null + ] + } + }, + "timestamp": 1698525013 + } +} diff --git a/ruby/simple-cipher/coverage/.resultset.json.lock b/ruby/simple-cipher/coverage/.resultset.json.lock new file mode 100644 index 00000000..e69de29b diff --git a/ruby/simple-cipher/coverage/coverage.xml b/ruby/simple-cipher/coverage/coverage.xml new file mode 100644 index 00000000..b8f3457a --- /dev/null +++ b/ruby/simple-cipher/coverage/coverage.xml @@ -0,0 +1,40 @@ + + + + + + /home/vpayno/git_vpayno/exercism-workspace/ruby/simple-cipher + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ruby/simple-cipher/run-tests-ruby.txt b/ruby/simple-cipher/run-tests-ruby.txt new file mode 100644 index 00000000..63bb83ea --- /dev/null +++ b/ruby/simple-cipher/run-tests-ruby.txt @@ -0,0 +1,232 @@ +Running automated test file(s): + + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-lint-rubycritic + +Running RubyCritic + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + rbenv 1.2.0-11-ge4f61e6 + + + ============================================================================== + +Running: rubycritic --path .rubycritic --format console --no-browser . + +running flay smells +. +running flog smells +.. +running reek smells +.. +running complexity +.. +running attributes +.. +running churn +.. +running simple_cov +.. +/home/vpayno/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubycritic-4.6.1/lib/rubycritic/generators/text/list.rb:13: warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments. +/home/vpayno/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubycritic-4.6.1/lib/rubycritic/generators/text/list.rb:13: warning: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead. +Cipher: + Rating: B + Churn: 0 + Complexity: 54.66 + Duplication: 32 + Smells: 4 + * (DuplicateCode) Similar code found in 2 nodes + - simple_cipher.rb:15 + - simple_cipher.rb:21 + * (ControlParameter) Cipher#initialize is controlled by argument 'key' + - simple_cipher.rb:9 + * (UtilityFunction) Cipher#to_char doesn't depend on instance state (maybe move it to another class?) + - simple_cipher.rb:41 + * (UtilityFunction) Cipher#to_ord doesn't depend on instance state (maybe move it to another class?) + - simple_cipher.rb:37 + +RandomKeyCipherTest: + Rating: B + Churn: 0 + Complexity: 62.74 + Duplication: 0 + Smells: 8 + * (InstanceVariableAssumption) PseudoShiftCipherTest assumes too much for instance variable '@cipher' + - simple_cipher_test.rb:128 + * (InstanceVariableAssumption) RandomKeyCipherTest assumes too much for instance variable '@cipher' + - simple_cipher_test.rb:28 + * (InstanceVariableAssumption) SubstitutionCipherTest assumes too much for instance variable '@cipher' + - simple_cipher_test.rb:82 + * (InstanceVariableAssumption) SubstitutionCipherTest assumes too much for instance variable '@key' + - simple_cipher_test.rb:82 + * (IrresponsibleModule) IncorrectKeyCipherTest has no descriptive comment + - simple_cipher_test.rb:59 + * (IrresponsibleModule) PseudoShiftCipherTest has no descriptive comment + - simple_cipher_test.rb:128 + * (IrresponsibleModule) RandomKeyCipherTest has no descriptive comment + - simple_cipher_test.rb:28 + * (IrresponsibleModule) SubstitutionCipherTest has no descriptive comment + - simple_cipher_test.rb:82 +Score: 82.2 + +real 0m0.652s +user 0m0.544s +sys 0m0.104s + + + ============================================================================== + +Exit code: 0 + +real 0m0.740s +user 0m0.588s +sys 0m0.154s + +real 0m0.742s +user 0m0.589s +sys 0m0.155s + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-lint-formatter + +Running Ruby Formatter + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + rbenv 1.2.0-11-ge4f61e6 + + + ============================================================================== + +Running: rubocop -a . + +Inspecting 2 files +.C + +Offenses: + +simple_cipher_test.rb:28:1: C: Style/Documentation: Missing top-level documentation comment for class RandomKeyCipherTest. +class RandomKeyCipherTest < Minitest::Test +^^^^^^^^^^^^^^^^^^^^^^^^^ +simple_cipher_test.rb:59:1: C: Style/Documentation: Missing top-level documentation comment for class IncorrectKeyCipherTest. +class IncorrectKeyCipherTest < Minitest::Test +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +simple_cipher_test.rb:82:1: C: Style/Documentation: Missing top-level documentation comment for class SubstitutionCipherTest. +class SubstitutionCipherTest < Minitest::Test +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +simple_cipher_test.rb:128:1: C: Style/Documentation: Missing top-level documentation comment for class PseudoShiftCipherTest. +class PseudoShiftCipherTest < Minitest::Test +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +2 files inspected, 4 offenses detected + +real 0m0.944s +user 0m0.809s +sys 0m0.225s + + + ============================================================================== + +Exit code: -1 + +real 0m1.039s +user 0m0.857s +sys 0m0.276s + +real 0m1.041s +user 0m0.858s +sys 0m0.277s + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-test-with-coverage + +Running Ruby Tests With Coverage + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + rbenv 1.2.0-11-ge4f61e6 + + + ============================================================================== + +Running: rm -rf ./coverage + + +real 0m0.001s +user 0m0.001s +sys 0m0.000s + + + ============================================================================== + +Running: ruby ./simple_cipher_test.rb -v + +Run options: -v --seed 5422 + +# Running: + +RandomKeyCipherTest#test_cipher_encode = 0.00 s = . +RandomKeyCipherTest#test_cipher_key_is_letters = 0.00 s = . +RandomKeyCipherTest#test_cipher_decode = 0.00 s = . +RandomKeyCipherTest#test_cipher_reversible = 0.00 s = . +SubstitutionCipherTest#test_cipher_decode = 0.00 s = . +SubstitutionCipherTest#test_cipher_encode = 0.00 s = . +SubstitutionCipherTest#test_cipher_encode_wrap = 0.00 s = . +SubstitutionCipherTest#test_cipher_key_is_as_submitted = 0.00 s = . +SubstitutionCipherTest#test_cipher_reversible = 0.00 s = . +SubstitutionCipherTest#test_double_shift_encode = 0.00 s = . +PseudoShiftCipherTest#test_cipher_encode = 0.00 s = . +PseudoShiftCipherTest#test_cipher_reversible = 0.00 s = . +PseudoShiftCipherTest#test_cipher_decode = 0.00 s = . +IncorrectKeyCipherTest#test_cipher_with_empty_key = 0.00 s = . +IncorrectKeyCipherTest#test_cipher_with_caps_key = 0.00 s = . +IncorrectKeyCipherTest#test_cipher_with_numeric_key = 0.00 s = . + +Finished in 0.006156s, 2599.2398 runs/s, 2761.6922 assertions/s. + +16 runs, 17 assertions, 0 failures, 0 errors, 0 skips +Coverage report generated for test:exercism to /home/vpayno/git_vpayno/exercism-workspace/ruby/simple-cipher/coverage/coverage.xml. 21 / 21 LOC (100.00%) covered + +real 0m0.189s +user 0m0.133s +sys 0m0.057s + + + ============================================================================== + +Coverage: 100.0% + + ============================================================================== + +Exit code: 0 + +real 0m0.251s +user 0m0.160s +sys 0m0.095s + +real 0m0.253s +user 0m0.161s +sys 0m0.096s + +=============================================================================== + +Running: misspell . + +real 0m0.025s +user 0m0.024s +sys 0m0.013s + +=============================================================================== + +/home/vpayno/git_vpayno/exercism-workspace/ruby + +=============================================================================== + diff --git a/ruby/simple-cipher/simple_cipher.rb b/ruby/simple-cipher/simple_cipher.rb new file mode 100644 index 00000000..9a40daff --- /dev/null +++ b/ruby/simple-cipher/simple_cipher.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: false + +# https://exercism.org/tracks/ruby/exercises/simple-cipher +# Simple Cipher 12in23 challenge +class Cipher + attr_reader :key + + def initialize(key = nil) + @key = key || 100.times.map { ('a'.ord + rand(26)).chr }.join + + raise ArgumentError, 'empty key' if @key.empty? + raise ArgumentError, 'key not composed of only a-z letters' if @key.match?(/[^a-z]/) + end + + def encode(plain_text) + plain_text.chars.zip(@key.chars).map do |rune, key| + to_char(shift_right(rune, key)).chr + end.join + end + + def decode(cipher_text) + cipher_text.chars.zip(@key.chars).map do |rune, key| + to_char(shift_left(rune, key)).chr + end.join + end + + private + + def shift_right(rune, key) + to_ord(rune) + to_ord(key) + end + + def shift_left(rune, key) + to_ord(rune) - to_ord(key) + end + + def to_ord(rune) + rune.ord - 'a'.ord + end + + def to_char(ordinal) + (ordinal % 26 + 'a'.ord).chr + end +end diff --git a/ruby/simple-cipher/simple_cipher_test.rb b/ruby/simple-cipher/simple_cipher_test.rb new file mode 100644 index 00000000..f38406f5 --- /dev/null +++ b/ruby/simple-cipher/simple_cipher_test.rb @@ -0,0 +1,152 @@ +# frozen_string_literal: false + +# https://github.com/simplecov-ruby/simplecov +require 'simplecov' + +# https://about.codecov.io/blog/getting-started-with-code-coverage-for-ruby/ +require 'simplecov-cobertura' +SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter + +# line coverage +SimpleCov.start if ENV['COVERAGE'] != 'branch' + +# branch coverage +if ENV['COVERAGE'] == 'branch' + SimpleCov.start do + enable_coverage :branch + primary_coverage :branch + end +end + +# name the test file/group +SimpleCov.command_name 'test:exercism' + +# original exercism tests +require 'minitest/autorun' +require_relative 'simple_cipher' + +class RandomKeyCipherTest < Minitest::Test + def setup + @cipher = Cipher.new + end + + def test_cipher_key_is_letters + assert_match(/\A[a-z]+\z/, @cipher.key) + end + + # Here we take advantage of the fact that plaintext of "aaa..." doesn't + # outputs the key. This is a critical problem with shift ciphers, some + # characters will always output the key verbatim. + def test_cipher_encode + # skip + plaintext = 'aaaaaaaaaa' + assert_equal(@cipher.key[0, 10], @cipher.encode(plaintext)) + end + + def test_cipher_decode + # skip + plaintext = 'aaaaaaaaaa' + assert_equal(plaintext, @cipher.decode(@cipher.key[0, 10])) + end + + def test_cipher_reversible + # skip + plaintext = 'abcdefghij' + assert_equal(plaintext, @cipher.decode(@cipher.encode(plaintext))) + end +end + +class IncorrectKeyCipherTest < Minitest::Test + def test_cipher_with_caps_key + # skip + assert_raises ArgumentError do + Cipher.new('ABCDEF') + end + end + + def test_cipher_with_numeric_key + # skip + assert_raises ArgumentError do + Cipher.new('12345') + end + end + + def test_cipher_with_empty_key + # skip + assert_raises ArgumentError do + Cipher.new('') + end + end +end + +class SubstitutionCipherTest < Minitest::Test + def setup + @key = 'abcdefghij' + @cipher = Cipher.new(@key) + end + + def test_cipher_key_is_as_submitted + # skip + assert_equal(@cipher.key, @key) + end + + def test_cipher_encode + # skip + plaintext = 'aaaaaaaaaa' + ciphertext = 'abcdefghij' + assert_equal(ciphertext, @cipher.encode(plaintext)) + end + + def test_cipher_decode + # skip + plaintext = 'aaaaaaaaaa' + ciphertext = 'abcdefghij' + assert_equal(plaintext, @cipher.decode(ciphertext)) + end + + def test_cipher_reversible + # skip + plaintext = 'abcdefghij' + assert_equal(plaintext, @cipher.decode(@cipher.encode(plaintext))) + end + + def test_double_shift_encode + # skip + plaintext = 'iamapandabear' + ciphertext = 'qayaeaagaciai' + assert_equal(ciphertext, Cipher.new('iamapandabear').encode(plaintext)) + end + + def test_cipher_encode_wrap + # skip + plaintext = 'zzzzzzzzzz' + ciphertext = 'zabcdefghi' + assert_equal(ciphertext, @cipher.encode(plaintext)) + end +end + +class PseudoShiftCipherTest < Minitest::Test + def setup + @cipher = Cipher.new('dddddddddd') + end + + def test_cipher_encode + # skip + plaintext = 'aaaaaaaaaa' + ciphertext = 'dddddddddd' + assert_equal(ciphertext, @cipher.encode(plaintext)) + end + + def test_cipher_decode + # skip + plaintext = 'aaaaaaaaaa' + ciphertext = 'dddddddddd' + assert_equal(plaintext, @cipher.decode(ciphertext)) + end + + def test_cipher_reversible + # skip + plaintext = 'abcdefghij' + assert_equal(plaintext, @cipher.decode(@cipher.encode(plaintext))) + end +end