-
Notifications
You must be signed in to change notification settings - Fork 119
Reject extra compass letters on PBN deals #340
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a9a5d9c
Reject extra compass letters on later hands in PBN deals.
tameware 76695d4
Guard convert_from_pbn against null and short PBN strings.
tameware f795279
Always clear remainCards before convert_from_pbn error returns.
tameware 37fe782
Bounds-check hand and suit indices in convert_from_pbn.
tameware 82f03eb
Fail convert_from_pbn when PBN input exceeds the 80-byte buffer.
tameware 9910158
Test PBN rejection at exactly 80 characters.
tameware 5329d3a
Pad overlong PBN test with card chars so only the length check triggers.
tameware 8140ca5
Derive PBN buffer limit from DealPBN::remainCards instead of hard-cod…
tameware f1782bc
Reject truncated PBN deals with fewer than 4 hands
tameware 6d8e42b
Clarify that extra PBN compass letters fail validation.
tameware 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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /// @file pbn_test.cpp | ||
| /// @brief Unit tests for convert_from_pbn deal-string parsing. | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| #include <api/PBN.h> | ||
| #include <api/dll.h> | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| constexpr char kNorthFirst[] = | ||
| "N:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3"; | ||
|
|
||
| constexpr char kEastFirst[] = | ||
| "E:QJT5432.T.6.QJ82 .J97543.K7532.94 87.A62.QJT4.AT75 AK96.KQ8.A98.K63"; | ||
|
|
||
| auto convert(const char* pbn) -> int | ||
| { | ||
| unsigned int remain[DDS_HANDS][DDS_SUITS]{}; | ||
| return convert_from_pbn(pbn, remain); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| TEST(ConvertFromPbn, AcceptsNorthFirstWithoutLaterDirections) | ||
| { | ||
| unsigned int remain[DDS_HANDS][DDS_SUITS]{}; | ||
| EXPECT_EQ(convert_from_pbn(kNorthFirst, remain), RETURN_NO_FAULT); | ||
| EXPECT_NE(remain[0][0], 0u); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, AcceptsEastFirstWithoutLaterDirections) | ||
| { | ||
| EXPECT_EQ(convert(kEastFirst), RETURN_NO_FAULT); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, AcceptsLowercaseFirstHandDirection) | ||
| { | ||
| EXPECT_EQ( | ||
| convert( | ||
| "n:QJ6.K652.J85.T98 873.J97.AT764.Q4 K5.T83.KQ9.A7652 AT942.AQ4.32.KJ3"), | ||
| RETURN_NO_FAULT); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsClockwiseSeatLettersOnLaterHands) | ||
| { | ||
| EXPECT_EQ( | ||
| convert( | ||
| "N:QJ6.K652.J85.T98 E:873.J97.AT764.Q4 S:K5.T83.KQ9.A7652 " | ||
| "W:AT942.AQ4.32.KJ3"), | ||
| 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsASingleExtraSeatLetter) | ||
| { | ||
| EXPECT_EQ( | ||
| convert( | ||
| "N:QJ6.K652.J85.T98 W:873.J97.AT764.Q4 K5.T83.KQ9.A7652 " | ||
| "AT942.AQ4.32.KJ3"), | ||
| 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsLowercaseExtraSeatLetter) | ||
| { | ||
| EXPECT_EQ( | ||
| convert( | ||
| "N:QJ6.K652.J85.T98 e:873.J97.AT764.Q4 K5.T83.KQ9.A7652 " | ||
| "AT942.AQ4.32.KJ3"), | ||
| 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsNullPointerDealBuffer) | ||
| { | ||
| unsigned int remain[DDS_HANDS][DDS_SUITS]{}; | ||
| EXPECT_EQ(convert_from_pbn(nullptr, remain), 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, ClearsOutputOnNullDealBuffer) | ||
| { | ||
| unsigned int remain[DDS_HANDS][DDS_SUITS]{}; | ||
| remain[0][0] = 0xFFFF; | ||
| EXPECT_EQ(convert_from_pbn(nullptr, remain), 0); | ||
| EXPECT_EQ(remain[0][0], 0u); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, ClearsOutputOnInvalidDeal) | ||
| { | ||
| unsigned int remain[DDS_HANDS][DDS_SUITS]{}; | ||
| remain[0][0] = 0xFFFF; | ||
| EXPECT_EQ(convert_from_pbn("xx", remain), 0); | ||
| EXPECT_EQ(remain[0][0], 0u); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsNullOutputBuffer) | ||
| { | ||
| EXPECT_EQ(convert_from_pbn(kNorthFirst, nullptr), 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsEmptyAndMissingSeatPrefixInputs) | ||
| { | ||
| EXPECT_EQ(convert(""), 0); | ||
| EXPECT_EQ(convert("N"), 0); | ||
| EXPECT_EQ(convert("xx"), 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsTooManySuitsInHand) | ||
| { | ||
| EXPECT_EQ(convert("N:AK.K.K.K.A"), 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsTooManyHands) | ||
| { | ||
| unsigned int remain[DDS_HANDS][DDS_SUITS]{}; | ||
| EXPECT_EQ(convert_from_pbn("N:AK.K.K.K A", remain), 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsTruncatedDealWithFewerThanFourHands) | ||
| { | ||
| EXPECT_EQ(convert("N:AK.QJ.T9.876"), 0); // 1 hand | ||
| EXPECT_EQ(convert("N:AK.QJ.T9.876 AK.QJ.T9.876"), 0); // 2 hands | ||
| EXPECT_EQ(convert("N:AK.QJ.T9.876 AK.QJ.T9.876 AK.QJ.T9.876"), 0); // 3 hands | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsInputLongerThanRemainCardsBuffer) | ||
| { | ||
| constexpr auto kBufSize = sizeof(DealPBN::remainCards); | ||
| std::string pbn = "N:"; | ||
| pbn.append(kBufSize, 'A'); | ||
| ASSERT_GT(pbn.size(), kBufSize); | ||
| EXPECT_EQ(convert(pbn.c_str()), 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, RejectsInputExactlyAtRemainCardsBufferLimit) | ||
| { | ||
| constexpr auto kBufSize = sizeof(DealPBN::remainCards); | ||
| std::string pbn = "N:"; | ||
| pbn.append(kBufSize - 2, 'A'); | ||
| ASSERT_EQ(pbn.size(), kBufSize); | ||
| EXPECT_EQ(convert(pbn.c_str()), 0); | ||
| } | ||
|
|
||
| TEST(ConvertFromPbn, AcceptsInputThatFitsRemainCardsBuffer) | ||
| { | ||
| constexpr auto kBufSize = sizeof(DealPBN::remainCards); | ||
| ASSERT_LT(std::char_traits<char>::length(kNorthFirst), kBufSize); | ||
| EXPECT_EQ(convert(kNorthFirst), RETURN_NO_FAULT); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.