From f8cce871eb813d3c6f06571093e8f0a42595d3ba Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Tue, 16 Jan 2018 18:51:15 -0500 Subject: [PATCH 1/5] Set up projects --- .gitignore | 323 ++++++++++++++++++ OnScreenKeyboard.sln | 25 ++ OnScreenKeyboard/App.config | 6 + OnScreenKeyboard/Keyboard.cs | 5 + OnScreenKeyboard/KeyboardPathGenerator.cs | 6 + OnScreenKeyboard/OnScreenKeyboard.csproj | 52 +++ OnScreenKeyboard/Properties/AssemblyInfo.cs | 36 ++ OnScreenKeyboard/README.md | 47 +++ .../KeyboardPathGeneratorTests.cs | 13 + .../OnScreenKeyboardTests.csproj | 67 ++++ .../Properties/AssemblyInfo.cs | 20 ++ OnScreenKeyboardTests/packages.config | 5 + 12 files changed, 605 insertions(+) create mode 100644 .gitignore create mode 100644 OnScreenKeyboard.sln create mode 100644 OnScreenKeyboard/App.config create mode 100644 OnScreenKeyboard/Keyboard.cs create mode 100644 OnScreenKeyboard/KeyboardPathGenerator.cs create mode 100644 OnScreenKeyboard/OnScreenKeyboard.csproj create mode 100644 OnScreenKeyboard/Properties/AssemblyInfo.cs create mode 100644 OnScreenKeyboard/README.md create mode 100644 OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs create mode 100644 OnScreenKeyboardTests/OnScreenKeyboardTests.csproj create mode 100644 OnScreenKeyboardTests/Properties/AssemblyInfo.cs create mode 100644 OnScreenKeyboardTests/packages.config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d3d5371 --- /dev/null +++ b/.gitignore @@ -0,0 +1,323 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# TypeScript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + diff --git a/OnScreenKeyboard.sln b/OnScreenKeyboard.sln new file mode 100644 index 0000000..4e4cf9f --- /dev/null +++ b/OnScreenKeyboard.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2024 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OnScreenKeyboard", "OnScreenKeyboard\OnScreenKeyboard.csproj", "{9CEB7FEC-6F4F-4B77-A206-CF26E06724BF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9CEB7FEC-6F4F-4B77-A206-CF26E06724BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9CEB7FEC-6F4F-4B77-A206-CF26E06724BF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9CEB7FEC-6F4F-4B77-A206-CF26E06724BF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9CEB7FEC-6F4F-4B77-A206-CF26E06724BF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D2CED830-FA83-4935-8EC2-78EEFF4655FF} + EndGlobalSection +EndGlobal diff --git a/OnScreenKeyboard/App.config b/OnScreenKeyboard/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/OnScreenKeyboard/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OnScreenKeyboard/Keyboard.cs b/OnScreenKeyboard/Keyboard.cs new file mode 100644 index 0000000..ae63909 --- /dev/null +++ b/OnScreenKeyboard/Keyboard.cs @@ -0,0 +1,5 @@ +namespace SoftWriters { + public class Keyboard { + + } +} diff --git a/OnScreenKeyboard/KeyboardPathGenerator.cs b/OnScreenKeyboard/KeyboardPathGenerator.cs new file mode 100644 index 0000000..fa2c8ce --- /dev/null +++ b/OnScreenKeyboard/KeyboardPathGenerator.cs @@ -0,0 +1,6 @@ +namespace SoftWriters { + public class OnScreenKeyboard { + static void Main(string[] args) { + } + } +} diff --git a/OnScreenKeyboard/OnScreenKeyboard.csproj b/OnScreenKeyboard/OnScreenKeyboard.csproj new file mode 100644 index 0000000..8f0eafb --- /dev/null +++ b/OnScreenKeyboard/OnScreenKeyboard.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {9CEB7FEC-6F4F-4B77-A206-CF26E06724BF} + Exe + OnScreenKeyboard + OnScreenKeyboard + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OnScreenKeyboard/Properties/AssemblyInfo.cs b/OnScreenKeyboard/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2cf5180 --- /dev/null +++ b/OnScreenKeyboard/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OnScreenKeyboard")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OnScreenKeyboard")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9ceb7fec-6f4f-4b77-a206-cf26e06724bf")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OnScreenKeyboard/README.md b/OnScreenKeyboard/README.md new file mode 100644 index 0000000..2c16e5c --- /dev/null +++ b/OnScreenKeyboard/README.md @@ -0,0 +1,47 @@ +On Screen Keyboard +================== + +The Problem +----------- +On screen keyboards are the bane of DVR users. To help alleviate the pain, one local company is asking you to implement part of a voice to text search for their DVR by developing an algorithm to script the on screen keyboard. +The keyboard is laid out as follows: + +``` +ABCDEF +GHIJKL +MNOPQR +STUVWX +YZ1234 +567890 +``` + +Please write a program which scripts the path of the cursor on the keyboard. The program should: + +1. Accept a flat file as input. + 1. Each new line will contain a search term +2. Output the path for the DVR to execute for each line + 1. Assume the cursor will always start on the A + 2. Use the following characters to make up the path + 1. U = up + 2. D = down + 3. L = left + 4. R = right + 5. S = space + 6. \# = select +3. Comma delimit the result + +Sample Input +------------ +IT Crowd + +Sample Output +------------- +D,R,R,#,D,D,L,#,S,U,U,U,R,#,D,D,R,R,R,#,L,L,L,#,D,R,R,#,U,U,U,L,# + +The Fine Print +-------------- +Please use whatever techniques you feel are applicable to solve the problem. We suggest that you approach this exercise as if this code was part of a larger system. The end result should be representative of your abilities and style. We prefer that you submit your solution in a language targeting the .NET Framework to help us better evaluate your code. + +Please fork this repository. If your solution involves code auto generated by a development tool, please commit it separately from your own work. When you have completed your solution, please issue a pull request to notify us that you are ready. + +Have fun. diff --git a/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs b/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs new file mode 100644 index 0000000..8fe4b4c --- /dev/null +++ b/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs @@ -0,0 +1,13 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using SoftWriters; + +namespace OnScreenKeyboardTests { + [TestClass] + public class KeyboardPathGeneratorTests { + [TestMethod] + public void TestMethod1() { + var keyboard = new Keyboard(); + } + } +} diff --git a/OnScreenKeyboardTests/OnScreenKeyboardTests.csproj b/OnScreenKeyboardTests/OnScreenKeyboardTests.csproj new file mode 100644 index 0000000..7ceec5b --- /dev/null +++ b/OnScreenKeyboardTests/OnScreenKeyboardTests.csproj @@ -0,0 +1,67 @@ + + + + + Debug + AnyCPU + {2A9ADA85-7A95-4B78-98E2-A4CFC2177674} + Library + Properties + OnScreenKeyboardTests + OnScreenKeyboardTests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/OnScreenKeyboardTests/Properties/AssemblyInfo.cs b/OnScreenKeyboardTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b1d8dad --- /dev/null +++ b/OnScreenKeyboardTests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("OnScreenKeyboardTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OnScreenKeyboardTests")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("2a9ada85-7a95-4b78-98e2-a4cfc2177674")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OnScreenKeyboardTests/packages.config b/OnScreenKeyboardTests/packages.config new file mode 100644 index 0000000..cf2d094 --- /dev/null +++ b/OnScreenKeyboardTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file From a0de8cdaaf01ecccce0c996ca51630486a8af9be Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Tue, 16 Jan 2018 22:28:22 -0500 Subject: [PATCH 2/5] Keyboard works, tested --- OnScreenKeyboard.sln | 6 ++ OnScreenKeyboard/Input.cs | 24 ++++++ OnScreenKeyboard/Keyboard.cs | 54 ++++++++++++ OnScreenKeyboard/OnScreenKeyboard.csproj | 5 +- OnScreenKeyboard/Position.cs | 17 ++++ .../KeyboardPathGeneratorTests.cs | 5 +- OnScreenKeyboardTests/KeyboardTests.cs | 82 +++++++++++++++++++ .../OnScreenKeyboardTests.csproj | 9 +- 8 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 OnScreenKeyboard/Input.cs create mode 100644 OnScreenKeyboard/Position.cs create mode 100644 OnScreenKeyboardTests/KeyboardTests.cs diff --git a/OnScreenKeyboard.sln b/OnScreenKeyboard.sln index 4e4cf9f..6092abc 100644 --- a/OnScreenKeyboard.sln +++ b/OnScreenKeyboard.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.27130.2024 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OnScreenKeyboard", "OnScreenKeyboard\OnScreenKeyboard.csproj", "{9CEB7FEC-6F4F-4B77-A206-CF26E06724BF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OnScreenKeyboardTests", "OnScreenKeyboardTests\OnScreenKeyboardTests.csproj", "{2A9ADA85-7A95-4B78-98E2-A4CFC2177674}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {9CEB7FEC-6F4F-4B77-A206-CF26E06724BF}.Debug|Any CPU.Build.0 = Debug|Any CPU {9CEB7FEC-6F4F-4B77-A206-CF26E06724BF}.Release|Any CPU.ActiveCfg = Release|Any CPU {9CEB7FEC-6F4F-4B77-A206-CF26E06724BF}.Release|Any CPU.Build.0 = Release|Any CPU + {2A9ADA85-7A95-4B78-98E2-A4CFC2177674}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A9ADA85-7A95-4B78-98E2-A4CFC2177674}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A9ADA85-7A95-4B78-98E2-A4CFC2177674}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A9ADA85-7A95-4B78-98E2-A4CFC2177674}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/OnScreenKeyboard/Input.cs b/OnScreenKeyboard/Input.cs new file mode 100644 index 0000000..894765f --- /dev/null +++ b/OnScreenKeyboard/Input.cs @@ -0,0 +1,24 @@ +using System; + +namespace SoftWriters { + public class Input { + public static Input UP = new Input("UP", keyboard => keyboard.MoveCursor(new Position(0, 1))); + public static Input DOWN = new Input("DOWN", keyboard => keyboard.MoveCursor(new Position(0, -1))); + public static Input LEFT = new Input("LEFT", keyboard => keyboard.MoveCursor(new Position(-1, 0))); + public static Input RIGHT = new Input("RIGHT", keyboard => keyboard.MoveCursor(new Position(1, 0))); + public static Input SPACE = new Input("SPACE", keyboard => keyboard.AddSpace()); + public static Input SELECT = new Input("SELECT", keyboard => keyboard.AddKeyAtCursor()); + + private string name; + private Action keyboardAction; + + public Input(string name, Action keyboardAction) { + this.name = name; + this.keyboardAction = keyboardAction; + } + + public void Trigger(Keyboard keyboard) { + keyboardAction(keyboard); + } + } +} diff --git a/OnScreenKeyboard/Keyboard.cs b/OnScreenKeyboard/Keyboard.cs index ae63909..ea94b50 100644 --- a/OnScreenKeyboard/Keyboard.cs +++ b/OnScreenKeyboard/Keyboard.cs @@ -1,5 +1,59 @@ namespace SoftWriters { public class Keyboard { + public static string[] KeyLayout { get; } = new string[] { + "ABCDEF", + "GHIJKL", + "MNOPQR", + "STUVWX", + "YZ1234", + "567890" + }; + public static int ColumnCount = KeyLayout[0].Length; + public static int RowCount = KeyLayout.Length; + + // In a real application, the Keyboard wouldn't hold the text + // but would likely pass keys to another class that would build up a string + // (e.g., something like Reactive Extensions for event passing) + public string Text { get; set; } + + private Position InitialPosition = new Position(0, 0); + private Position cursor; + + public Keyboard() { + Reset(); + } + + public void Reset() { + cursor = InitialPosition; + Text = ""; + } + + // Handles wrap-around cases + public void MoveCursor(Position movement) { + // Since origin is in upper-left corner, all Y values are <= 0 and + // all X values are >= 0. Therefore, Y wrap-around check subtracts the RowCount, to ensure + // value is in range and negative + cursor = new Position( + (cursor.X + movement.X + ColumnCount) % ColumnCount, + (cursor.Y + movement.Y - RowCount) % RowCount + ); + } + + public void AddKeyAtCursor() { + Text += keyFromPosition(cursor); + } + + private char keyFromPosition(Position position) { + // Since the origin point is the upper-left corner, all Y values are <= 0. + // Invert Y before accessing correct row. + return KeyLayout[-position.Y][position.X]; + } + + public void AddSpace() { + Text += " "; + } } + } + diff --git a/OnScreenKeyboard/OnScreenKeyboard.csproj b/OnScreenKeyboard/OnScreenKeyboard.csproj index 8f0eafb..4457136 100644 --- a/OnScreenKeyboard/OnScreenKeyboard.csproj +++ b/OnScreenKeyboard/OnScreenKeyboard.csproj @@ -42,7 +42,10 @@ - + + + + diff --git a/OnScreenKeyboard/Position.cs b/OnScreenKeyboard/Position.cs new file mode 100644 index 0000000..8290882 --- /dev/null +++ b/OnScreenKeyboard/Position.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftWriters { + public class Position { + public int X {get;set; } + public int Y {get;set; } + + public Position(int x, int y) { + X = x; + Y = y; + } + } +} diff --git a/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs b/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs index 8fe4b4c..b3385cd 100644 --- a/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs +++ b/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs @@ -5,9 +5,10 @@ namespace OnScreenKeyboardTests { [TestClass] public class KeyboardPathGeneratorTests { - [TestMethod] - public void TestMethod1() { + [TestMethod, Ignore] + public void ExampleTest() { var keyboard = new Keyboard(); + } } } diff --git a/OnScreenKeyboardTests/KeyboardTests.cs b/OnScreenKeyboardTests/KeyboardTests.cs new file mode 100644 index 0000000..80eb0a3 --- /dev/null +++ b/OnScreenKeyboardTests/KeyboardTests.cs @@ -0,0 +1,82 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using SoftWriters; +using System; +using System.Collections.Generic; + +namespace OnScreenKeyboardTests { + [TestClass] + public class KeyboardTests { + Keyboard keyboard = new Keyboard(); + + [TestInitialize] + public void Initialize() { + keyboard.Reset(); + } + + [TestMethod] + public void StartsAtA() { + triggerFromShorthand("#"); + Assert.AreEqual("A", keyboard.Text); + } + + [TestMethod] + public void AddingASpace() { + triggerFromShorthand("#,S,#"); + Assert.AreEqual("A A", keyboard.Text); + } + + [TestMethod] + public void MoveRightForB() { + triggerFromShorthand("R,#"); + Assert.AreEqual("B", keyboard.Text); + } + + [TestMethod] + public void MoveLeftForF() { + triggerFromShorthand("L,#"); + Assert.AreEqual("F", keyboard.Text); + } + + [TestMethod] + public void MoveDownForG() { + triggerFromShorthand("D,#"); + Assert.AreEqual("G", keyboard.Text); + } + + [TestMethod] + public void MoveUpFor5() { + triggerFromShorthand("U,#"); + Assert.AreEqual("5", keyboard.Text); + } + + [TestMethod] + public void MovingWithoutSelecting() { + triggerFromShorthand("U,D,D,L,L,R,R,R,R"); + Assert.AreEqual("", keyboard.Text); + } + + [TestMethod] + public void ExampleTest() { + var shorthand = "D,R,R,#,D,D,L,#,S,U,U,U,R,#,D,D,R,R,R,#,L,L,L,#,D,R,R,#,U,U,U,L,#"; + triggerFromShorthand(shorthand); + Assert.AreEqual("IT CROWD", keyboard.Text); + } + + private Dictionary> shorthandLookup = new Dictionary>() { + {"U", keyboard => Input.UP.Trigger(keyboard) }, + {"D", keyboard => Input.DOWN.Trigger(keyboard) }, + {"L", keyboard => Input.LEFT.Trigger(keyboard) }, + {"R", keyboard => Input.RIGHT.Trigger(keyboard) }, + {"#", keyboard => Input.SELECT.Trigger(keyboard) }, + {"S", keyboard => Input.SPACE.Trigger(keyboard) }, + }; + + private void triggerFromShorthand(string shorthand) { + var items = shorthand.Split(','); + foreach(var item in items) { + shorthandLookup[item](keyboard); + } + } + } +} diff --git a/OnScreenKeyboardTests/OnScreenKeyboardTests.csproj b/OnScreenKeyboardTests/OnScreenKeyboardTests.csproj index 7ceec5b..1b48c48 100644 --- a/OnScreenKeyboardTests/OnScreenKeyboardTests.csproj +++ b/OnScreenKeyboardTests/OnScreenKeyboardTests.csproj @@ -48,12 +48,19 @@ - + + + + + {9ceb7fec-6f4f-4b77-a206-cf26e06724bf} + OnScreenKeyboard + + From 4b5a3f5c318e81e48c12f4f506a2fbca5ab0abcb Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Tue, 16 Jan 2018 23:44:19 -0500 Subject: [PATCH 3/5] Path generation largely works, but wrap-around isn't optimized --- OnScreenKeyboard/KeyboardPathGenerator.cs | 89 ++++++++++++++++++- OnScreenKeyboard/OnScreenKeyboard.csproj | 35 +++++++- OnScreenKeyboard/Position.cs | 8 ++ OnScreenKeyboard/Program.cs | 25 ++++++ .../KeyboardPathGeneratorTests.cs | 67 +++++++++++++- 5 files changed, 216 insertions(+), 8 deletions(-) create mode 100644 OnScreenKeyboard/Program.cs diff --git a/OnScreenKeyboard/KeyboardPathGenerator.cs b/OnScreenKeyboard/KeyboardPathGenerator.cs index fa2c8ce..207a662 100644 --- a/OnScreenKeyboard/KeyboardPathGenerator.cs +++ b/OnScreenKeyboard/KeyboardPathGenerator.cs @@ -1,6 +1,89 @@ -namespace SoftWriters { - public class OnScreenKeyboard { - static void Main(string[] args) { +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace SoftWriters { + public class KeyboardPathGenerator { + private static Regex validInputCharacter = new Regex("[a-zA-Z0-9]", RegexOptions.Compiled); + private static Dictionary keyPositions = generateLookupTable(); + private Position InitialPosition = new Position(0, 0); + private Position cursor; + + + public KeyboardPathGenerator() { + Reset(); + } + + public void Reset() { + cursor = InitialPosition; + } + + public string GenerateShorthandFrom(string testCase) { + Reset(); + if(testCase == "") { + return ""; + } + + List shorthand = new List(); + for(var i = 0; i < testCase.Length; i++) { + var character = toUpperCase(testCase[i]); + if (character == ' ') { + shorthand.Add("S"); + } + else if (!validInputCharacter.IsMatch(character.ToString())) { + return "Invalid input: " + testCase; + } + else { + shorthand.Add(ShorthandForMoveTo(character)); + } + } + + return String.Join(",", shorthand); + } + + //Assumes validated input + public string ShorthandForMoveTo(char character) { + var characterPosition = keyPositions[character]; + var distance = characterPosition - cursor; + + cursor = characterPosition; + + var shorthand = ""; + if (distance.Y < 0) { + shorthand += new string('U', -distance.Y); + } + if (distance.Y > 0) { + shorthand += new string('D', distance.Y); + } + if (distance.X > 0) { + shorthand += new string('R', distance.X); + } + if (distance.X < 0) { + shorthand += new string('L', -distance.X); + } + + if(shorthand == "") { + return "#"; + } + else { + return String.Join(",", shorthand) + ",#"; + } + } + + // Assumes character is on keyboard + private static Dictionary generateLookupTable() { + var table = new Dictionary(); + for(var i = 0; i < Keyboard.RowCount; i++) { + for(var j = 0; j < Keyboard.ColumnCount; j++) { + // Positions are x,y, so positions use j,i indexes + table.Add(Keyboard.KeyLayout[i][j], new Position(j, i)); + } + } + return table; + } + + private static char toUpperCase(char character) { + return character.ToString().ToUpper()[0]; } } } diff --git a/OnScreenKeyboard/OnScreenKeyboard.csproj b/OnScreenKeyboard/OnScreenKeyboard.csproj index 4457136..c86d0ef 100644 --- a/OnScreenKeyboard/OnScreenKeyboard.csproj +++ b/OnScreenKeyboard/OnScreenKeyboard.csproj @@ -6,11 +6,26 @@ AnyCPU {9CEB7FEC-6F4F-4B77-A206-CF26E06724BF} Exe - OnScreenKeyboard - OnScreenKeyboard + SoftWriters + SoftWriters v4.6.1 512 true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -31,6 +46,9 @@ prompt 4 + + SoftWriters.Program + @@ -46,10 +64,23 @@ + + + + False + Microsoft .NET Framework 4.6.1 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/OnScreenKeyboard/Position.cs b/OnScreenKeyboard/Position.cs index 8290882..51792dd 100644 --- a/OnScreenKeyboard/Position.cs +++ b/OnScreenKeyboard/Position.cs @@ -13,5 +13,13 @@ public Position(int x, int y) { X = x; Y = y; } + + public static Position operator +(Position a, Position b) { + return new Position(a.X + b.X, a.Y + b.Y); + } + + public static Position operator -(Position a, Position b) { + return new Position(a.X - b.X, a.Y - b.Y); + } } } diff --git a/OnScreenKeyboard/Program.cs b/OnScreenKeyboard/Program.cs new file mode 100644 index 0000000..e82abeb --- /dev/null +++ b/OnScreenKeyboard/Program.cs @@ -0,0 +1,25 @@ +using System.IO; +using System.Threading; + +namespace SoftWriters { + public class Program { + static void Main(string[] args) { + if(args.Length == 0) { + System.Console.WriteLine("Usage: "); + } + + var keyboardPathGenerator = new KeyboardPathGenerator(); + try { + var testCases = File.ReadAllLines(args[0]); + foreach(var testCase in testCases) { + var shorthand = keyboardPathGenerator.GenerateShorthandFrom(testCase); + System.Console.WriteLine(shorthand); + } + } + catch(IOException e) { + System.Console.Error.WriteLine("Error accessing path: " + args[0]); + System.Console.Error.WriteLine(e.Message); + } + } + } +} diff --git a/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs b/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs index b3385cd..87cae84 100644 --- a/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs +++ b/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs @@ -5,10 +5,71 @@ namespace OnScreenKeyboardTests { [TestClass] public class KeyboardPathGeneratorTests { - [TestMethod, Ignore] - public void ExampleTest() { - var keyboard = new Keyboard(); + KeyboardPathGenerator generator = new KeyboardPathGenerator(); + + + [TestMethod] + //Degenerate case + public void EmptyString() { + var shorthand = generator.GenerateShorthandFrom(""); + var expected = ""; + Assert.AreEqual(expected, shorthand); + } + + [TestMethod] + public void ShorthandFor_() { + var shorthand = generator.GenerateShorthandFrom(" "); + var expected = "S"; + Assert.AreEqual(expected, shorthand); + } + [TestMethod] + public void ShorthandForA() { + var shorthand = generator.GenerateShorthandFrom("A"); + var expected = "#"; + Assert.AreEqual(expected, shorthand); + } + [TestMethod] + public void ShorthandForABC() { + var shorthand = generator.GenerateShorthandFrom("ABC"); + var expected = "#,R,#,R,#"; + Assert.AreEqual(expected, shorthand); + } + + [TestMethod] + public void ShorthandForAGM() { + var shorthand = generator.GenerateShorthandFrom("AGM"); + var expected = "#,D,#,D,#"; + Assert.AreEqual(expected, shorthand); + } + + [TestMethod] + public void ShorthandForA50() { + var shorthand = generator.GenerateShorthandFrom("A50"); + var expected = "#,U,#,L,#"; + Assert.AreEqual(expected, shorthand); + } + + [TestMethod] + public void CaseDoesNotMatter() { + var shorthand = generator.GenerateShorthandFrom("Aa"); + var expected = "#,#"; + Assert.AreEqual(expected, shorthand); + } + + [TestMethod] + public void ShorthandForA_A() { + var shorthand = generator.GenerateShorthandFrom("A A"); + var expected = "#,S,#"; + Assert.AreEqual(expected, shorthand); + } + + + [TestMethod] + public void ExampleTest() { + var shorthand = generator.GenerateShorthandFrom("IT Crowd"); + var expected = "D,R,R,#,D,D,L,#,S,U,U,U,R,#,D,D,R,R,R,#,L,L,L,#,D,R,R,#,U,U,U,L,#"; + Assert.AreEqual(expected, shorthand); } } } From 2453eb880662b00419b12ef1fe00e88d6ed44e72 Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Wed, 17 Jan 2018 00:06:26 -0500 Subject: [PATCH 4/5] Wrap around cases now use shortest number of inputs --- OnScreenKeyboard/KeyboardPathGenerator.cs | 36 ++++++++++++------- .../KeyboardPathGeneratorTests.cs | 17 ++++++--- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/OnScreenKeyboard/KeyboardPathGenerator.cs b/OnScreenKeyboard/KeyboardPathGenerator.cs index 207a662..f79c135 100644 --- a/OnScreenKeyboard/KeyboardPathGenerator.cs +++ b/OnScreenKeyboard/KeyboardPathGenerator.cs @@ -34,7 +34,7 @@ public string GenerateShorthandFrom(string testCase) { return "Invalid input: " + testCase; } else { - shorthand.Add(ShorthandForMoveTo(character)); + shorthand.Add(shorthandForMoveTo(character)); } } @@ -42,31 +42,43 @@ public string GenerateShorthandFrom(string testCase) { } //Assumes validated input - public string ShorthandForMoveTo(char character) { + private string shorthandForMoveTo(char character) { var characterPosition = keyPositions[character]; var distance = characterPosition - cursor; cursor = characterPosition; var shorthand = ""; - if (distance.Y < 0) { - shorthand += new string('U', -distance.Y); + if(distance.Y > 0) { + shorthand += optimizedDirection('D', 'U', distance.Y, Keyboard.RowCount); } - if (distance.Y > 0) { - shorthand += new string('D', distance.Y); + else if(distance.Y < 0) { + shorthand += optimizedDirection('U', 'D', -distance.Y, Keyboard.RowCount); } - if (distance.X > 0) { - shorthand += new string('R', distance.X); + if(distance.X > 0) { + shorthand += optimizedDirection('R', 'L', distance.X, Keyboard.ColumnCount); } - if (distance.X < 0) { - shorthand += new string('L', -distance.X); + else if(distance.X < 0) { + shorthand += optimizedDirection('L', 'R', -distance.X, Keyboard.ColumnCount); } - if(shorthand == "") { + if (shorthand == "") { return "#"; } else { - return String.Join(",", shorthand) + ",#"; + return String.Join(",", shorthand.ToCharArray()) + ",#"; + } + } + + + private string optimizedDirection(char forward, char backward, int distance, int dimensionSize) { + if (distance == 0) return ""; + + if(distance <= dimensionSize / 2.0) { + return new string(forward, distance); + } + else { + return new string(backward, dimensionSize - distance); } } diff --git a/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs b/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs index 87cae84..44e4a2f 100644 --- a/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs +++ b/OnScreenKeyboardTests/KeyboardPathGeneratorTests.cs @@ -30,23 +30,23 @@ public void ShorthandForA() { } [TestMethod] - public void ShorthandForABC() { + public void SimpleRight() { var shorthand = generator.GenerateShorthandFrom("ABC"); var expected = "#,R,#,R,#"; Assert.AreEqual(expected, shorthand); } [TestMethod] - public void ShorthandForAGM() { + public void SimpleDown() { var shorthand = generator.GenerateShorthandFrom("AGM"); var expected = "#,D,#,D,#"; Assert.AreEqual(expected, shorthand); } [TestMethod] - public void ShorthandForA50() { - var shorthand = generator.GenerateShorthandFrom("A50"); - var expected = "#,U,#,L,#"; + public void OptimizedWrapping() { + var shorthand = generator.GenerateShorthandFrom("A50FA"); + var expected = "#,U,#,L,#,D,#,R,#"; Assert.AreEqual(expected, shorthand); } @@ -64,6 +64,13 @@ public void ShorthandForA_A() { Assert.AreEqual(expected, shorthand); } + [TestMethod] + public void InvalidInput() { + var shorthand = generator.GenerateShorthandFrom("!"); + var expected = "Invalid input: !"; + Assert.AreEqual(expected, shorthand); + } + [TestMethod] public void ExampleTest() { From 89fb798ce33af0adae663f438d7be6b6d5fbf871 Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Wed, 17 Jan 2018 00:14:17 -0500 Subject: [PATCH 5/5] Accidentally copied README to subdirectory --- OnScreenKeyboard/README.md | 47 -------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 OnScreenKeyboard/README.md diff --git a/OnScreenKeyboard/README.md b/OnScreenKeyboard/README.md deleted file mode 100644 index 2c16e5c..0000000 --- a/OnScreenKeyboard/README.md +++ /dev/null @@ -1,47 +0,0 @@ -On Screen Keyboard -================== - -The Problem ------------ -On screen keyboards are the bane of DVR users. To help alleviate the pain, one local company is asking you to implement part of a voice to text search for their DVR by developing an algorithm to script the on screen keyboard. -The keyboard is laid out as follows: - -``` -ABCDEF -GHIJKL -MNOPQR -STUVWX -YZ1234 -567890 -``` - -Please write a program which scripts the path of the cursor on the keyboard. The program should: - -1. Accept a flat file as input. - 1. Each new line will contain a search term -2. Output the path for the DVR to execute for each line - 1. Assume the cursor will always start on the A - 2. Use the following characters to make up the path - 1. U = up - 2. D = down - 3. L = left - 4. R = right - 5. S = space - 6. \# = select -3. Comma delimit the result - -Sample Input ------------- -IT Crowd - -Sample Output -------------- -D,R,R,#,D,D,L,#,S,U,U,U,R,#,D,D,R,R,R,#,L,L,L,#,D,R,R,#,U,U,U,L,# - -The Fine Print --------------- -Please use whatever techniques you feel are applicable to solve the problem. We suggest that you approach this exercise as if this code was part of a larger system. The end result should be representative of your abilities and style. We prefer that you submit your solution in a language targeting the .NET Framework to help us better evaluate your code. - -Please fork this repository. If your solution involves code auto generated by a development tool, please commit it separately from your own work. When you have completed your solution, please issue a pull request to notify us that you are ready. - -Have fun.