-
Notifications
You must be signed in to change notification settings - Fork 4
Feature/spaces #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
whaeck
wants to merge
15
commits into
develop
Choose a base branch
from
feature/spaces
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/spaces #21
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
da023e6
Allowing for spaces between the sign and first digit of the exponent
whaeck 548ba1b
Adding more cases
whaeck 602e5da
More compact test
whaeck dc7973a
Added testing exceptions
whaeck 50c6a2b
Added position testing
whaeck dea50cc
More testing
whaeck 6cba9e2
Some more cleaning up
whaeck 6a1ab27
Just in case it's not obvious these were not legal
whaeck 76e1f36
More cleaning up
whaeck 34823d3
Cleaned up the real read test
whaeck c08ff88
More cleaning up
whaeck d18b59d
Allowing for trailing white space after the fraction value, added mor…
whaeck 72f4ac4
Moving some logic around to fix ENDF issues
whaeck 0fee921
More clean up
whaeck a8fd444
adding some more comments
whaeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 96 additions & 17 deletions
113
src/disco/FixedWidthField/Real/test/parseExponent.test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,103 @@ | ||
| #include <iterator> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "disco.hpp" | ||
| #include "catch.hpp" | ||
|
|
||
| SCENARIO("Real parse exponent", "[Real], [parseExponent]"){ | ||
| std::vector< std::string > | ||
| test_strings{ {"+123"}, {"-123"}, | ||
| {"E123"}, {"E+123"}, {"E-123"}, | ||
| {"e123"}, {"e+123"}, {"e-123"}, | ||
| {"D123"}, {"D+123"}, {"D-123"}, | ||
| {"d123"}, {"d+123"}, {"d-123"} }; | ||
| uint16_t p = 0; | ||
| bool success; | ||
| for (unsigned i = 0; i < test_strings.size(); ++i){ | ||
| p = 0; auto si = test_strings[i].begin(); | ||
| if ( (i + 1) % 3 == 2 ){ | ||
| REQUIRE( -123 == njoy::disco::Real<5>::parseExponent( si, p ) ); | ||
| } else { | ||
| REQUIRE( 123 == njoy::disco::Real<5>::parseExponent( si, p ) ); | ||
| } | ||
| SCENARIO( "Real - parse exponent" ) { | ||
|
|
||
| auto parse = [] ( const std::string string, uint16_t& position ) { | ||
|
|
||
| auto iter = string.begin(); | ||
| position = 0; | ||
| return njoy::disco::Real< 6 >::parseExponent( iter, position ); | ||
| }; | ||
|
|
||
| THEN( "valid exponent strings can be readup to the correct position" ) | ||
| { | ||
| uint16_t position = 0; | ||
|
|
||
| CHECK( +123 == parse( "+123", position ) ); | ||
| CHECK( 4 == position ); | ||
| CHECK( +123 == parse( "+ 123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( +123 == parse( "E+123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( +123 == parse( "E+ 123", position ) ); | ||
| CHECK( 6 == position ); | ||
| CHECK( +123 == parse( "E123", position ) ); | ||
| CHECK( 4 == position ); | ||
| CHECK( +123 == parse( "E 123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( +123 == parse( "e+123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( +123 == parse( "e+ 123", position ) ); | ||
| CHECK( 6 == position ); | ||
| CHECK( +123 == parse( "e123", position ) ); | ||
| CHECK( 4 == position ); | ||
| CHECK( +123 == parse( "e 123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( +123 == parse( "D+123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( +123 == parse( "D+ 123", position ) ); | ||
| CHECK( 6 == position ); | ||
| CHECK( +123 == parse( "D123", position ) ); | ||
| CHECK( 4 == position ); | ||
| CHECK( +123 == parse( "D 123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( +123 == parse( "d+123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( +123 == parse( "d+ 123", position ) ); | ||
| CHECK( 6 == position ); | ||
| CHECK( +123 == parse( "d123", position ) ); | ||
| CHECK( 4 == position ); | ||
| CHECK( +123 == parse( "d 123", position ) ); | ||
| CHECK( 5 == position ); | ||
|
|
||
| CHECK( -123 == parse( "-123", position ) ); | ||
| CHECK( 4 == position ); | ||
| CHECK( -123 == parse( "- 123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( -123 == parse( "E-123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( -123 == parse( "E- 123", position ) ); | ||
| CHECK( 6 == position ); | ||
| CHECK( -123 == parse( "e-123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( -123 == parse( "e- 123", position ) ); | ||
| CHECK( 6 == position ); | ||
| CHECK( -123 == parse( "D-123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( -123 == parse( "D- 123", position ) ); | ||
| CHECK( 6 == position ); | ||
| CHECK( -123 == parse( "d-123", position ) ); | ||
| CHECK( 5 == position ); | ||
| CHECK( -123 == parse( "d- 123", position ) ); | ||
| CHECK( 6 == position ); | ||
|
|
||
| // exponent is only read up to the first non-digit | ||
| CHECK( +123 == parse( "+123 ", position ) ); | ||
| CHECK( 4 == position ); | ||
| CHECK( +123 == parse( "+123a", position ) ); | ||
| CHECK( 4 == position ); | ||
| } | ||
|
|
||
| THEN( "invalid exponent strings cause an exception" ) | ||
| { | ||
| uint16_t position = 0; | ||
|
|
||
| CHECK_THROWS( parse( "-a123", position ) ); | ||
| CHECK_THROWS( parse( "+a123", position ) ); | ||
| CHECK_THROWS( parse( "E-a123", position ) ); | ||
| CHECK_THROWS( parse( "E+a123", position ) ); | ||
| CHECK_THROWS( parse( "D-a123", position ) ); | ||
| CHECK_THROWS( parse( "D+a123", position ) ); | ||
| CHECK_THROWS( parse( "E -123", position ) ); | ||
| CHECK_THROWS( parse( "E +123", position ) ); | ||
| CHECK_THROWS( parse( "D -123", position ) ); | ||
| CHECK_THROWS( parse( "D +123", position ) ); | ||
|
|
||
| CHECK_THROWS( parse( "- a3", position ) ); | ||
| CHECK_THROWS( parse( "- ", position ) ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fortunately, this one is not valid. I did confirm that because I was concerned. |
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are valid in Fortran :)