Skip to content

pragonp/challenge

Repository files navigation

C# Coding Challenge – Old Phone Pad

The original challenge PDF asks for a method that converts “old phone keypad” input (digits, pauses, backspace *, send #) into text, plus tests and documentation.

The AI usage can be seen at https://chatgpt.com/share/691b01cc-47e0-8000-9e4f-a32716cb1a3e

Problem summary

  • Keys 29 map to letters (2ABC, 3DEF, …, 9WXYZ).
  • Repeating a key cycles through its letters (for key 2: 2#A, 22#B, 222#C).
  • A space separates sequences on the same key (e.g. 222 2 22#CAB).
  • * acts as backspace, deleting the last output character.
  • # sends the message and terminates input; it is not part of the output.

Examples from the PDF (covered by tests):

  • OldPhonePad("33#")E
  • OldPhonePad("227*#")B
  • OldPhonePad("4433555 555666#")HELLO
  • OldPhonePad("8 88777444666*664#")TURING

Implementation

  • Core logic: OldPhonePad/OldPhonePad.cs (OldPhonePadApp.OldPhonePad.Convert(string input)).
  • Console entry point: OldPhonePad/Program.cs:
    • Writes Enter key sequence:
    • Reads a line (e.g. 4433555 555666#) and prints the decoded output.

How to build and run

From the root:

  • Build the app project:
    dotnet build OldPhonePad/OldPhonePad.csproj

  • Run the app project:
    dotnet run --project OldPhonePad/OldPhonePad.csproj

Example:

  • Input: 4433555 555666#
  • Output: HELLO

Tests and coverage

From the repository root:

  • Run tests with line/branch coverage (coverage.runsettings + XPlat Code Coverage):
    dotnet test OldPhonePad.Tests/OldPhonePad.Tests.csproj --collect:"XPlat Code Coverage" --settings coverage.runsettings

    This produces OldPhonePad.Tests/TestResults/<guid>/coverage.info (LCOV).

  • (Optional) Generate an HTML report with ReportGenerator:

    • Install once (if needed):
      dotnet tool install -g dotnet-reportgenerator-globaltool
    • Generate report:
      reportgenerator -reports:"OldPhonePad.Tests/TestResults/*/coverage.info" -targetdir:"coveragereport" -reporttypes:Html

Open coveragereport/index.html to inspect coverage.

About

C# Coding Challenge

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages