Skip to content

Conversation

@Mechetel
Copy link
Owner

No description provided.

@Mechetel Mechetel requested a review from valter0ff March 18, 2021 09:45
MAX_CODE_NUM = 6
DIGITS_NUM = 4

attr_reader :user, :difficulty, :secret_code, :date, :hints_list, :attempts, :hints
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would remove the secret_code from here

Copy link
Owner Author

Choose a reason for hiding this comment

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

it must be here because console and web app must return secret_code if user win or lose

Copy link
Collaborator

Choose a reason for hiding this comment

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

And if is a user not win and not lose?

Copy link
Owner Author

Choose a reason for hiding this comment

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

what do you mean?
secret_code is necessary to show only if user win or lose
so, it must be in attr_reader

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok

Comment on lines 5 to 7
GUESS_IS_NOT_INTEGER = 'Guess should be Integer class'.freeze
DIGITS_COUNT_ERROR = 'Invalid digits count'.freeze
DIGIT_RANGE_ERROR = 'Digit is not in a range'.freeze
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is displayed then add I18n

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

Comment on lines 18 to 24
def self.validate(guess)
raise ValidationError, GUESS_IS_NOT_INTEGER unless guess[/^\d+$/]
raise ValidationError, DIGITS_COUNT_ERROR unless guess.size == Game::DIGITS_NUM
raise ValidationError, DIGIT_RANGE_ERROR unless guess.chars.all? do |num|
num.to_i.between? Game::MIN_CODE_NUM, Game::MAX_CODE_NUM
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can carry over to 'validation' module

Comment on lines 32 to 33
answer << RIGHT_ANSWER_SYMBOL
@secret_code[index], @user_input[index] = nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can write a separate function

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

Comment on lines 6 to 9
DIFFICULTY_ERROR = 'No such difficulty'.freeze
NAME_IS_NOT_STRING_ERROR = 'Name should be an instance of String'.freeze
SHORT_NAME_ERROR = 'Name is too short'.freeze
LONG_NAME_ERROR = 'Name is too long'.freeze
Copy link
Collaborator

Choose a reason for hiding this comment

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

I18n

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

Comment on lines +14 to +15
validate_name_min_length(@name, @errors) if @errors.empty?
validate_name_max_length(@name, @errors) if @errors.empty?
Copy link
Collaborator

Choose a reason for hiding this comment

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

'if' doesn't need here

Copy link
Owner Author

Choose a reason for hiding this comment

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

it is need here
for example if User.new(322) there will be no sense to check @name.length because there is no method for 322:Integer

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok. Then what about one validation function for a user?

Copy link
Owner Author

Choose a reason for hiding this comment

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

no
my validations in module
functions in module should be suitable for anything, not only for user
Something like that

@Mechetel Mechetel requested a review from Win9XCHI March 20, 2021 18:06
@user_input.compact!
@secret_code.compact!
near_matchers = @secret_code & @user_input
near_matchers.size.times { answer << WRONG_ANSWER_SYMBOL }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest replacing this code with:

Array.new(near_matchers.size) { '-' }.join

and then you don't need answer = '' and answer at all in this case

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

File.new(file_path, 'w') unless File.exist?(file_path)
end

def game_to_h(game)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is rubocop ok with this function length?

Copy link
Owner Author

Choose a reason for hiding this comment

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

ok

let(:level) { 'easy' }
let(:invalid_difficulty) { described_class.new(invalid_level) }
let(:invalid_level) { 'qwerty' }
let(:difficulty_constant) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may just get this constant from the code with Difficulty::DIFFICULTIES, it will be better because if something changes in constant you don't have to change tests

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

require 'spec_helper'

RSpec.describe Codebreaker::GuessChecker do
let(:plus_symbol) { '+' }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here it's better to use constants

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,25 @@
RSpec.describe Codebreaker::StatisticsService do
let(:game) { Codebreaker::Game.new(Codebreaker::User.new('Mechetel'), Codebreaker::Difficulty.new('hell')) }
let(:path) { './lib/codebreaker/test.yaml' }
Copy link
Collaborator

Choose a reason for hiding this comment

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

And here, constant will be better

Copy link
Owner Author

Choose a reason for hiding this comment

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

but here :path is example variable and there is no CONSTANT for it

Copy link
Collaborator

@valter0ff valter0ff left a comment

Choose a reason for hiding this comment

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

all is good

@Mechetel Mechetel requested a review from etherell March 21, 2021 08:15
Copy link
Collaborator

@etherell etherell left a comment

Choose a reason for hiding this comment

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

Good job!

.rubocop.yml Outdated
Comment on lines 11 to 25
Metrics/BlockLength:
Exclude:
- 'spec/codebreaker/**/*'

Metrics/ModuleLength:
Exclude:
- 'spec/codebreaker/**/*'

Lint/AmbiguousBlockAssociation:
Exclude:
- 'spec/codebreaker/**/*'

RSpec/AnyInstance:
Exclude:
- 'spec/codebreaker/**/*'
Copy link
Collaborator

Choose a reason for hiding this comment

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

u do not need this

Copy link
Owner Author

Choose a reason for hiding this comment

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

done, but BlockLength is left

Comment on lines 30 to 40
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'i18n'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'fasterer'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'rubocop-performance'
spec.add_development_dependency 'rubocop-rspec'
spec.add_development_dependency 'rubycritic'
spec.add_development_dependency 'simplecov'

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: add versions

Copy link
Owner Author

Choose a reason for hiding this comment

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

added

end

it 'adds DifficultyError to errors' do
invalid_difficulty.valid?
Copy link
Collaborator

Choose a reason for hiding this comment

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

to before

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

end

it 'adds nothing to errors' do
difficulty.valid?
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

end

it 'adds longnameerror to errors' do
long_name_user.valid?
Copy link
Collaborator

Choose a reason for hiding this comment

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

to before

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants