├── Gemfile ├── solver.rb ├── .github └── workflows │ └── linters.yml ├── Gemfile.lock ├── LICENSE ├── .rubocop.yml ├── spec └── solver_spec.rb └── README.md /Gemfile: -------------------------------------------------------------------------------- 1 | gem 'rubocop', '>= 1.0', '< 2.0' 2 | -------------------------------------------------------------------------------- /solver.rb: -------------------------------------------------------------------------------- 1 | class Solver 2 | def self.factorial(number) 3 | raise ArgumentError, 'Only accepts 0 and positive integers' if number.negative? 4 | 5 | (1..number).reduce(1, :*) 6 | end 7 | 8 | def self.reverse(word) 9 | word.reverse 10 | end 11 | 12 | def self.fizzbuzz(number) 13 | return 'fizzbuzz' if (number % 3).zero? && (number % 5).zero? 14 | return 'fizz' if (number % 3).zero? 15 | return 'buzz' if (number % 5).zero? 16 | 17 | number.to_s 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /.github/workflows/linters.yml: -------------------------------------------------------------------------------- 1 | name: Linters 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | rubocop: 7 | name: Rubocop 8 | runs-on: ubuntu-22.04 9 | 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-ruby@v1 13 | with: 14 | ruby-version: ">=3.1.x" 15 | - name: Setup Rubocop 16 | run: | 17 | gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/ 18 | [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml 19 | - name: Rubocop Report 20 | run: rubocop --color -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | specs: 3 | ast (2.4.2) 4 | base64 (0.1.1) 5 | json (2.5.1) 6 | language_server-protocol (3.17.0.3) 7 | parallel (1.23.0) 8 | parser (3.2.2.3) 9 | ast (~> 2.4.1) 10 | racc 11 | racc (1.7.1) 12 | rainbow (3.1.1) 13 | regexp_parser (2.8.1) 14 | rexml (3.2.5) 15 | rubocop (1.56.1) 16 | base64 (~> 0.1.1) 17 | json (~> 2.3) 18 | language_server-protocol (>= 3.17.0) 19 | parallel (~> 1.10) 20 | parser (>= 3.2.2.3) 21 | rainbow (>= 2.2.2, < 4.0) 22 | regexp_parser (>= 1.8, < 3.0) 23 | rexml (>= 3.2.5, < 4.0) 24 | rubocop-ast (>= 1.28.1, < 2.0) 25 | ruby-progressbar (~> 1.7) 26 | unicode-display_width (>= 2.4.0, < 3.0) 27 | rubocop-ast (1.29.0) 28 | parser (>= 3.2.1.0) 29 | ruby-progressbar (1.13.0) 30 | unicode-display_width (2.4.2) 31 | 32 | PLATFORMS 33 | x86_64-linux 34 | 35 | DEPENDENCIES 36 | rubocop (>= 1.0, < 2.0) 37 | 38 | BUNDLED WITH 39 | 2.4.19 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Nitcelis Bravo and Ahmed Eid. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | NewCops: enable 3 | Exclude: 4 | - "Guardfile" 5 | - "Rakefile" 6 | - "node_modules/**/*" 7 | 8 | DisplayCopNames: true 9 | 10 | Layout/LineLength: 11 | Max: 120 12 | Metrics/MethodLength: 13 | Max: 20 14 | Metrics/AbcSize: 15 | Max: 50 16 | Metrics/ClassLength: 17 | Max: 150 18 | Metrics/BlockLength: 19 | IgnoredMethods: ['describe'] 20 | Max: 30 21 | 22 | 23 | Style/Documentation: 24 | Enabled: false 25 | Style/ClassAndModuleChildren: 26 | Enabled: false 27 | Style/EachForSimpleLoop: 28 | Enabled: false 29 | Style/AndOr: 30 | Enabled: false 31 | Style/DefWithParentheses: 32 | Enabled: false 33 | Style/FrozenStringLiteralComment: 34 | EnforcedStyle: never 35 | 36 | Layout/HashAlignment: 37 | EnforcedColonStyle: key 38 | Layout/ExtraSpacing: 39 | AllowForAlignment: false 40 | Layout/MultilineMethodCallIndentation: 41 | Enabled: true 42 | EnforcedStyle: indented 43 | Lint/RaiseException: 44 | Enabled: false 45 | Lint/StructNewOverride: 46 | Enabled: false 47 | Style/HashEachMethods: 48 | Enabled: false 49 | Style/HashTransformKeys: 50 | Enabled: false 51 | Style/HashTransformValues: 52 | Enabled: false -------------------------------------------------------------------------------- /spec/solver_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../solver' 2 | 3 | describe Solver do 4 | describe '#factorial' do 5 | it 'returns 1 for factorial of 0' do 6 | expect(Solver.factorial(0)).to eq(1) 7 | end 8 | 9 | it 'returns the factorial of a positive number' do 10 | expect(Solver.factorial(5)).to eq(120) 11 | end 12 | 13 | it 'raises an exception for a negative number' do 14 | expect { Solver.factorial(-1) }.to raise_error(ArgumentError) 15 | end 16 | end 17 | 18 | describe '#reverse' do 19 | it 'returns the reversed word' do 20 | expect(Solver.reverse('hello')).to eq('olleh') 21 | end 22 | end 23 | 24 | describe '#fizzbuzz' do 25 | it 'returns "fizz" when the number is divisible by 3' do 26 | expect(Solver.fizzbuzz(9)).to eq('fizz') 27 | end 28 | 29 | it 'returns "buzz" when the number is divisible by 5' do 30 | expect(Solver.fizzbuzz(10)).to eq('buzz') 31 | end 32 | 33 | it 'returns "fizzbuzz" when the number is divisible by 3 and 5' do 34 | expect(Solver.fizzbuzz(15)).to eq('fizzbuzz') 35 | end 36 | 37 | it 'returns the number as a string for any other case' do 38 | expect(Solver.fizzbuzz(7)).to eq('7') 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |
A code editor (we recommend Visual Studio Code)
Git and a GitHub account