Skip to content

Commit

Permalink
Chapter13.15 bug fix (#794)
Browse files Browse the repository at this point in the history
## Summary
This pull request addresses an issue in
`Chapter13.15.ParameterlessStatementLambdas.cs` where `getUserInput` was
only taking white space as input. The method has been updated to ensure
that only valid, non-whitespace strings are accepted.

## Changes Made
- Removed the Not (`!`) on the while loop condition in `getUserInput` to
properly handle whitespace inputs.
- Updated 'Main' to call `Console.WriteLine(input);` for testing.
- Added unit test to verify correct behavior for valid inputs.

---------

Co-authored-by: Benjamin Michaelis <[email protected]>
  • Loading branch information
twoody0 and BenjaminMichaelis authored Nov 26, 2024
1 parent 07b7eac commit 99d6952
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Errata.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ Zhou Jing | 23 | 1080 | Change "DWORD flProtect); // The type of memory allocati
Zhou Jing | 22 | 1065 - 1066 | Changed 'Thread' to 'Task' and "Application exiting" to "Application shutting down"
Zhou Jing | 4 | 161 | Fix `input < 9` to `input < 0` in Listing 4.24
Zhou Jing | 4 | 119 | Show inconsistent size multi-dimensional array in listing 3.16
Zhou Jing | 3 | 114 | Replace `second` with `third` in "// Retrieve third item from the end (Python)"
Zhou Jing | 3 | 114 | Replace `second` with `third` in "// Retrieve third item from the end (Python)"
Tyler Woody | 13 | 702 | Remove the `!` negation in `string.IsNullOrWhiteSpace(input)` in the while loop to properly allow looping
15 changes: 15 additions & 0 deletions src/Chapter13.Tests/Listing13.15.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_15.Tests;

[TestClass]
public class ProgramTests
{
[TestMethod]
public void MainTest()
{
const string expected = "<<ValidInput>>ValidInput";

IntelliTect.TestTools.Console.ConsoleAssert.Expect(
expected, Program.Main
);
}
}
5 changes: 3 additions & 2 deletions src/Chapter13/Listing13.15.ParameterlessStatementLambdas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ public static void Main()
{
input = Console.ReadLine();
}
while(!string.IsNullOrWhiteSpace(input));
while(string.IsNullOrWhiteSpace(input));
return input!;
};
//...
#endregion INCLUDE
getUserInput();
string input = getUserInput();
Console.WriteLine(input);
}
}

0 comments on commit 99d6952

Please sign in to comment.