Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bugfix/prevent base number remapping #55

Merged
merged 3 commits into from
Jan 31, 2022

Conversation

MaciejLipinski
Copy link
Collaborator

No description provided.

@codecov-commenter
Copy link

Codecov Report

Merging #55 (b1572ba) into master (65d873d) will increase coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #55      +/-   ##
============================================
+ Coverage     99.70%   99.85%   +0.15%     
- Complexity      354      357       +3     
============================================
  Files            54       54              
  Lines          1336     1341       +5     
  Branches         42       41       -1     
============================================
+ Hits           1332     1339       +7     
+ Partials          4        2       -2     
Impacted Files Coverage Δ
...portuguese/PortugueseThousandToWordsConverter.java 100.00% <100.00%> (+2.32%) ⬆️
...radukisto/internal/support/BaseNumbersBuilder.java 100.00% <100.00%> (ø)
...o/internal/converters/IntegerToWordsConverter.java 96.00% <0.00%> (+4.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65d873d...b1572ba. Read the comment docs.

@@ -60,8 +59,7 @@ private String twoDigitsNumberAsString(Integer value) {
private String threeDigitsNumberAsString(Integer value) {
Integer tensWithUnits = value % 100;
Integer hundreds = value - tensWithUnits;
boolean hasNextNumber = tensWithUnits != 0;
return format("%s e %s", asWords(hundreds, hasNextNumber), asWords(tensWithUnits));
return format("%s e %s", asWords(hundreds, true), asWords(tensWithUnits));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hasNextNumber was always true, since all full hundreds (100, 200, 300...) are base numbers or an exception (100 is an exception in Portuguese), so they are handled in line 36 and 41

Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, can we add a test for that one specific case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

they are tested in BrazilianPortugueseValuesTest.groovy:59-67 – test cases for full hundred numbers (100 to 900)


then:
thrown(NumberAlreadyMappedException)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also add test:

   def 'i dont know which name is suitable for this test ;)' () {
        given:
        builder.put(1, new GenderForms("some form"))

        when:
        builder.put(1, "some other form")

        then:
        thrown(NumberAlreadyMappedException)
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea. Also added test for String -> GenderForm


class BaseNumbersBuilderTest extends Specification {

def builder = baseNumbersBuilder()
Copy link
Collaborator

@jglaszka jglaszka Jan 28, 2022

Choose a reason for hiding this comment

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

I think it can be not good practice to use shared not-immutable object over multiple test cases. Its better to init new instance inside every test. In these 2 tests it doesnt change anything, but in future tests and developing new functionality - it can produce bugs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right. Moved initialization to setup method

Copy link
Collaborator

@jglaszka jglaszka left a comment

Choose a reason for hiding this comment

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

I think all changes are okay, but please fix the tests - if you think it is needed

@MaciejLipinski MaciejLipinski merged commit f3238cd into master Jan 31, 2022
@MaciejLipinski MaciejLipinski deleted the bugfix/prevent-base-number-remapping branch January 31, 2022 09:50
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants