From e42dfafa5d849c82dc96fddf533f8c612ad795d6 Mon Sep 17 00:00:00 2001 From: Elijahjohnson5 Date: Fri, 22 Mar 2019 15:23:18 -0600 Subject: [PATCH 1/6] Visual studio project --- .gitattributes | 63 ++++++ .gitignore | 261 ++++++++++++++++++++++ MorseCode.sln | 31 +++ MorseCode/App.config | 6 + MorseCode/MorseCode.csproj | 54 +++++ MorseCode/Properties/AssemblyInfo.cs | 36 +++ MorseCodeTests/MorseCodeTests.csproj | 109 +++++++++ MorseCodeTests/Properties/AssemblyInfo.cs | 36 +++ MorseCodeTests/packages.config | 5 + 9 files changed, 601 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 MorseCode.sln create mode 100644 MorseCode/App.config create mode 100644 MorseCode/MorseCode.csproj create mode 100644 MorseCode/Properties/AssemblyInfo.cs create mode 100644 MorseCodeTests/MorseCodeTests.csproj create mode 100644 MorseCodeTests/Properties/AssemblyInfo.cs create mode 100644 MorseCodeTests/packages.config diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c4efe2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,261 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# 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 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# 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 + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_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 + +# 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 + +# 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 +# TODO: 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 +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable 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 + +# 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 +node_modules/ +orleans.codegen.cs + +# 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 + +# 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 + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# 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 \ No newline at end of file diff --git a/MorseCode.sln b/MorseCode.sln new file mode 100644 index 0000000..fe7793b --- /dev/null +++ b/MorseCode.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2010 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCode", "MorseCode\MorseCode.csproj", "{33591ABC-DE3B-468A-895E-2D37743CA90E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCodeTests", "MorseCodeTests\MorseCodeTests.csproj", "{27E9C986-EB73-4DFC-AA80-FA8F65A173C4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {33591ABC-DE3B-468A-895E-2D37743CA90E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {33591ABC-DE3B-468A-895E-2D37743CA90E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {33591ABC-DE3B-468A-895E-2D37743CA90E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {33591ABC-DE3B-468A-895E-2D37743CA90E}.Release|Any CPU.Build.0 = Release|Any CPU + {27E9C986-EB73-4DFC-AA80-FA8F65A173C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {27E9C986-EB73-4DFC-AA80-FA8F65A173C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {27E9C986-EB73-4DFC-AA80-FA8F65A173C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {27E9C986-EB73-4DFC-AA80-FA8F65A173C4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C59D368B-051D-44FA-BFD8-90E5E7CD5344} + EndGlobalSection +EndGlobal diff --git a/MorseCode/App.config b/MorseCode/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/MorseCode/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MorseCode/MorseCode.csproj b/MorseCode/MorseCode.csproj new file mode 100644 index 0000000..b79a13a --- /dev/null +++ b/MorseCode/MorseCode.csproj @@ -0,0 +1,54 @@ + + + + + Debug + AnyCPU + {33591ABC-DE3B-468A-895E-2D37743CA90E} + Exe + MorseCode + MorseCode + 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/MorseCode/Properties/AssemblyInfo.cs b/MorseCode/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1dc4ec7 --- /dev/null +++ b/MorseCode/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("MorseCode")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MorseCode")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[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("33591abc-de3b-468a-895e-2d37743ca90e")] + +// 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/MorseCodeTests/MorseCodeTests.csproj b/MorseCodeTests/MorseCodeTests.csproj new file mode 100644 index 0000000..c4333a9 --- /dev/null +++ b/MorseCodeTests/MorseCodeTests.csproj @@ -0,0 +1,109 @@ + + + + + Debug + AnyCPU + {27E9C986-EB73-4DFC-AA80-FA8F65A173C4} + Library + Properties + MorseCodeTests + MorseCodeTests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.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 + + + + + + + + + + + + + + + + + + + + + {33591ABC-DE3B-468A-895E-2D37743CA90E} + MorseCode + + + + + + + + + + False + + + False + + + False + + + False + + + + + + + + + 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/MorseCodeTests/Properties/AssemblyInfo.cs b/MorseCodeTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..629f51e --- /dev/null +++ b/MorseCodeTests/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("MorseCodeTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MorseCodeTests")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[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("27e9c986-eb73-4dfc-aa80-fa8f65a173c4")] + +// 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/MorseCodeTests/packages.config b/MorseCodeTests/packages.config new file mode 100644 index 0000000..cf2d094 --- /dev/null +++ b/MorseCodeTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file From be8abf823fa2b180744d76668d54c55e84924db5 Mon Sep 17 00:00:00 2001 From: Elijahjohnson5 Date: Fri, 22 Mar 2019 15:24:45 -0600 Subject: [PATCH 2/6] Started the converter --- MorseCode/MorseCodeToEnglishTranslator.cs | 88 +++++++++++++++++++ MorseCode/OneWayTranslator.cs | 15 ++++ MorseCode/Program.cs | 36 ++++++++ .../MorseCodeToEnglishTranslatorTests.cs | 29 ++++++ MorseCodeTests/test.txt | 2 + 5 files changed, 170 insertions(+) create mode 100644 MorseCode/MorseCodeToEnglishTranslator.cs create mode 100644 MorseCode/OneWayTranslator.cs create mode 100644 MorseCode/Program.cs create mode 100644 MorseCodeTests/MorseCodeToEnglishTranslatorTests.cs create mode 100644 MorseCodeTests/test.txt diff --git a/MorseCode/MorseCodeToEnglishTranslator.cs b/MorseCode/MorseCodeToEnglishTranslator.cs new file mode 100644 index 0000000..0613800 --- /dev/null +++ b/MorseCode/MorseCodeToEnglishTranslator.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace MorseCode +{ + public class MorseCodeToEnglishTranslator : IOneWayTranslator + { + private IDictionary morseToCharDict; + + public MorseCodeToEnglishTranslator() + { + morseToCharDict = new Dictionary + { + { ".-", 'a' }, + { "-...", 'b' }, + { "-.-.", 'c' }, + { "-..", 'd' }, + { ".", 'e' }, + { "..-.", 'f' }, + { "--.", 'g' }, + { "....", 'h' }, + { "..", 'i' }, + { ".---", 'j' }, + { "-.-", 'k' }, + { ".-..", 'l' }, + { "--", 'm' }, + { "-.", 'n' }, + { "---", 'o' }, + { ".--.", 'p' }, + { "--.-", 'q' }, + { ".-.", 'r' }, + { "...", 's' }, + { "-", 't' }, + { "..-", 'u' }, + { "...-", 'v' }, + { ".--", 'w' }, + { "-..-", 'x' }, + { "-.--", 'y' }, + { "--..", 'z' }, + { "-----", '0' }, + { ".----", '1' }, + { "..---", '2' }, + { "...--", '3' }, + { "....-", '4' }, + { ".....", '5' }, + { "-....", '6' }, + { "--...", '7' }, + { "---..", '8' }, + { "----.", '9' } + }; + } + + public IList TranslateFile(string file) + { + IList result = new List(); + string[] lines = File.ReadAllLines(file); + foreach (string line in lines) + { + result.Add(TranslateLine(line)); + } + + return result; + } + + public string TranslateLine(string line) + { + string[] split = line.Split(new string[] { "||" }, StringSplitOptions.None); + StringBuilder sb = new StringBuilder(); + foreach (string s in split) + { + if (s.Length == 0) + { + sb.Append(" "); + } else if (morseToCharDict.ContainsKey(s)) + { + sb.Append(morseToCharDict[s]); + } else + { + sb.Append('*'); + } + } + + return sb.ToString(); + } + } +} diff --git a/MorseCode/OneWayTranslator.cs b/MorseCode/OneWayTranslator.cs new file mode 100644 index 0000000..19769fb --- /dev/null +++ b/MorseCode/OneWayTranslator.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MorseCode +{ + interface IOneWayTranslator + { + IList TranslateFile(string file); + + string TranslateLine(string line); + } +} diff --git a/MorseCode/Program.cs b/MorseCode/Program.cs new file mode 100644 index 0000000..f99f257 --- /dev/null +++ b/MorseCode/Program.cs @@ -0,0 +1,36 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MorseCode +{ + class Program + { + static void Main(string[] args) + { + if (args.Length != 1) + { + Console.WriteLine("Program takes one argument that is a file of morse code to translate"); + Console.WriteLine("Example usage: java MorseCode.class test.txt"); + return; + } else if (!File.Exists(args[0])) + { + Console.WriteLine("Could not find specified file " + args[0]); + Console.WriteLine("Make sure the file path and name is correct"); + return; + } + + IOneWayTranslator translator = new MorseCodeToEnglishTranslator(); + Console.WriteLine("Translating file " + args[0] + " to english"); + IList lines = translator.TranslateFile(args[0]); + //Print out translated lines one by one + foreach (string line in lines) + { + Console.WriteLine(line); + } + } + } +} diff --git a/MorseCodeTests/MorseCodeToEnglishTranslatorTests.cs b/MorseCodeTests/MorseCodeToEnglishTranslatorTests.cs new file mode 100644 index 0000000..8299b05 --- /dev/null +++ b/MorseCodeTests/MorseCodeToEnglishTranslatorTests.cs @@ -0,0 +1,29 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using MorseCode; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace MorseCode.Tests +{ + [TestClass()] + public class MorseCodeToEnglishTranslatorTests + { + private MorseCodeToEnglishTranslator translator; + + [TestMethod()] + public void TranslateFileTest() + { + Assert.Fail(); + } + + [TestMethod()] + public void TranslateLineTest() + { + Assert.Fail(); + } + } +} \ No newline at end of file diff --git a/MorseCodeTests/test.txt b/MorseCodeTests/test.txt new file mode 100644 index 0000000..e974356 --- /dev/null +++ b/MorseCodeTests/test.txt @@ -0,0 +1,2 @@ +-..||---||--. +….||.||.-..||.-..||---||||.--||---||.-.||.-..||-.. \ No newline at end of file From c2e0eac7fd718280b1ecd699c91e4251cc5f81ca Mon Sep 17 00:00:00 2001 From: Elijah Johnson Date: Fri, 22 Mar 2019 16:36:32 -0600 Subject: [PATCH 3/6] Added comments and test cases --- MorseCode/MorseCode.csproj | 4 +- ...ator.cs => MorseCodeToEnglishConverter.cs} | 44 +++++-- MorseCode/OneWayConverter.cs | 25 ++++ MorseCode/OneWayTranslator.cs | 15 --- MorseCode/Program.cs | 23 ++-- MorseCodeTests/MorseCodeTests.csproj | 5 +- .../MorseCodeToEnglishConverterTests.cs | 118 ++++++++++++++++++ .../MorseCodeToEnglishTranslatorTests.cs | 29 ----- MorseCodeTests/test.txt | 2 - 9 files changed, 197 insertions(+), 68 deletions(-) rename MorseCode/{MorseCodeToEnglishTranslator.cs => MorseCodeToEnglishConverter.cs} (55%) create mode 100644 MorseCode/OneWayConverter.cs delete mode 100644 MorseCode/OneWayTranslator.cs create mode 100644 MorseCodeTests/MorseCodeToEnglishConverterTests.cs delete mode 100644 MorseCodeTests/MorseCodeToEnglishTranslatorTests.cs delete mode 100644 MorseCodeTests/test.txt diff --git a/MorseCode/MorseCode.csproj b/MorseCode/MorseCode.csproj index b79a13a..0e8d66a 100644 --- a/MorseCode/MorseCode.csproj +++ b/MorseCode/MorseCode.csproj @@ -42,8 +42,8 @@ - - + + diff --git a/MorseCode/MorseCodeToEnglishTranslator.cs b/MorseCode/MorseCodeToEnglishConverter.cs similarity index 55% rename from MorseCode/MorseCodeToEnglishTranslator.cs rename to MorseCode/MorseCodeToEnglishConverter.cs index 0613800..72c68e9 100644 --- a/MorseCode/MorseCodeToEnglishTranslator.cs +++ b/MorseCode/MorseCodeToEnglishConverter.cs @@ -5,11 +5,20 @@ namespace MorseCode { - public class MorseCodeToEnglishTranslator : IOneWayTranslator + /// + /// A converter for Morse code to English + /// Implements the OneWayConverter interface + /// + public class MorseCodeToEnglishConverter : IOneWayConverter { + //The dictionary used for conversion private IDictionary morseToCharDict; - public MorseCodeToEnglishTranslator() + /// + /// Creates a new MorseCodeToEnglishConverter + /// Initializes the dictionary based on Morse code to English + /// + public MorseCodeToEnglishConverter() { morseToCharDict = new Dictionary { @@ -52,36 +61,55 @@ public MorseCodeToEnglishTranslator() }; } - public IList TranslateFile(string file) + /// + /// Converts a file that has lines containing Morse code + /// to English characters + /// + /// The file path of the file, will already have been verified to exist + /// A list containing the English representation of the Morse code of each line of the file + public IList ConvertFile(string file) { + //Create result variable IList result = new List(); + //Read all lines of the file string[] lines = File.ReadAllLines(file); foreach (string line in lines) { - result.Add(TranslateLine(line)); + //Add each converted line + result.Add(ConvertLine(line)); } return result; } - public string TranslateLine(string line) + /// + /// Converts a line of Morse code to a line of English text + /// + /// the line to convert + /// a new string that is converted from Morse code to English + public string ConvertLine(string line) { string[] split = line.Split(new string[] { "||" }, StringSplitOptions.None); StringBuilder sb = new StringBuilder(); foreach (string s in split) { + //If there are two breaks in a row add a space if (s.Length == 0) { sb.Append(" "); - } else if (morseToCharDict.ContainsKey(s)) + } + else if (morseToCharDict.ContainsKey(s)) { + //Append character in dictionary if the dictionary contains the current string sb.Append(morseToCharDict[s]); - } else + } + else { + //If the string of characters is not in the dictionary append a * sb.Append('*'); } } - + //Build the string return sb.ToString(); } } diff --git a/MorseCode/OneWayConverter.cs b/MorseCode/OneWayConverter.cs new file mode 100644 index 0000000..1125009 --- /dev/null +++ b/MorseCode/OneWayConverter.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace MorseCode +{ + /// + /// A one way converter from one character set to another + /// + interface IOneWayConverter + { + /// + /// Converts a file to a list of strings in the new + /// set of chars, each string in the list is a line of the file + /// + /// the file path of the file + /// A list of strings representing the lines of the file after conversion + IList ConvertFile(string file); + + /// + /// Converts a line to a string in the new set of chars + /// + /// the line to be converted + /// a new string with the conversion completed + string ConvertLine(string line); + } +} diff --git a/MorseCode/OneWayTranslator.cs b/MorseCode/OneWayTranslator.cs deleted file mode 100644 index 19769fb..0000000 --- a/MorseCode/OneWayTranslator.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MorseCode -{ - interface IOneWayTranslator - { - IList TranslateFile(string file); - - string TranslateLine(string line); - } -} diff --git a/MorseCode/Program.cs b/MorseCode/Program.cs index f99f257..9d1a834 100644 --- a/MorseCode/Program.cs +++ b/MorseCode/Program.cs @@ -1,36 +1,43 @@ using System; using System.IO; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MorseCode { class Program { + /// + /// Main method runs the converter + /// + /// the command line arguments passed into the program static void Main(string[] args) { + //Check if we have the right amount of arguments if (args.Length != 1) { - Console.WriteLine("Program takes one argument that is a file of morse code to translate"); - Console.WriteLine("Example usage: java MorseCode.class test.txt"); + //Give the user feedback + Console.WriteLine("Program takes one argument that is a file of Morse code to translate"); + Console.WriteLine("Example usage: MorseCode.exe test.txt"); return; } else if (!File.Exists(args[0])) { + //The file does not exist Console.WriteLine("Could not find specified file " + args[0]); Console.WriteLine("Make sure the file path and name is correct"); return; } - IOneWayTranslator translator = new MorseCodeToEnglishTranslator(); - Console.WriteLine("Translating file " + args[0] + " to english"); - IList lines = translator.TranslateFile(args[0]); + //Create a new Morse code to English converter + IOneWayConverter converter = new MorseCodeToEnglishConverter(); + //Convert the file + IList lines = converter.ConvertFile(args[0]); //Print out translated lines one by one foreach (string line in lines) { Console.WriteLine(line); } + //Used for making sure the correct output is there when running from visual studio + Console.ReadLine(); } } } diff --git a/MorseCodeTests/MorseCodeTests.csproj b/MorseCodeTests/MorseCodeTests.csproj index c4333a9..cc73e98 100644 --- a/MorseCodeTests/MorseCodeTests.csproj +++ b/MorseCodeTests/MorseCodeTests.csproj @@ -56,7 +56,7 @@ - + @@ -68,9 +68,6 @@ MorseCode - - - diff --git a/MorseCodeTests/MorseCodeToEnglishConverterTests.cs b/MorseCodeTests/MorseCodeToEnglishConverterTests.cs new file mode 100644 index 0000000..2b278bf --- /dev/null +++ b/MorseCodeTests/MorseCodeToEnglishConverterTests.cs @@ -0,0 +1,118 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using System.IO; + + +namespace MorseCode.Tests +{ + /// + /// Test class for unit testing + /// + [TestClass()] + public class MorseCodeToEnglishConverterTests + { + private readonly MorseCodeToEnglishConverter translator = new MorseCodeToEnglishConverter(); + + [TestMethod()] + public void ConvertFileTest() + { + CreateFileForTesting("test.txt", "-..||---||--." + + System.Environment.NewLine + + "....||.||.-..||.-..||---||||.--||---||.-.||.-..||-.."); + List result = (List)translator.ConvertFile("test.txt"); + DeleteFileForTesting("test.txt"); + CollectionAssert.AreEqual(new List { "dog", "hello world" }, result); + } + + [TestMethod()] + public void ConvertLineTest() + { + string result = translator.ConvertLine("..-.||---||---"); + Assert.AreEqual("foo", result); + } + + [TestMethod()] + public void NumberTest() + { + string result = translator.ConvertLine(".----||..---||||...--"); + Assert.AreEqual("12 3", result); + } + + [TestMethod()] + public void InvalidCharTest() + { + string result = translator.ConvertLine("........||.-"); + Assert.AreEqual("*a", result); + } + + [TestMethod()] + public void InvalidCharsTest() + { + string result = translator.ConvertLine("f||o||o||.-"); + Assert.AreEqual("***a", result); + } + + [TestMethod()] + public void ThreeBreaksTest() + { + string result = translator.ConvertLine("..-.||---||---||||||-...||.-||.-."); + Assert.AreEqual("foo bar", result); + } + + [TestMethod()] + public void InvalidBreakTest() + { + string result = translator.ConvertLine("..|.-|-.||.-"); + Assert.AreEqual("*a", result); + } + + [TestMethod()] + public void NumberAndCharTest() + { + string result = translator.ConvertLine("..||-.||||-....||...--"); + Assert.AreEqual("in 63", result); + } + + [TestMethod()] + public void NumberAndCharAndInvalidTest() + { + string result = translator.ConvertLine("..||n||||-....||...--"); + Assert.AreEqual("i* 63", result); + } + + [TestMethod()] + public void EmptyFileTest() + { + CreateFileForTesting("empty.txt", ""); + IList result = translator.ConvertFile("empty.txt"); + DeleteFileForTesting("empty.txt"); + Assert.IsTrue((result.Count == 0)); + } + + [TestMethod()] + public void BigFileTest() + { + CreateFileForTesting("test.txt", "-..||---||--." + + System.Environment.NewLine + + "....||.||.-..||.-..||---||||.--||---||.-.||.-..||-.." + + System.Environment.NewLine + + "-||....||..||...||||..||...||||.-||||-||.||...||-||||...||-||.-.||..||-.||--." + + System.Environment.NewLine + + ".-..||---||.-.||.||--||||..||.--.||...||..-||--||||-..||---||.-..||---||.-.||||...||..||-||||.-||--||.||-"); + List result = (List)translator.ConvertFile("test.txt"); + DeleteFileForTesting("test.txt"); + CollectionAssert.AreEqual(new List { "dog", "hello world", "this is a test string", "lorem ipsum dolor sit amet" }, result); + } + + + private void CreateFileForTesting(string filename, string text) + { + File.WriteAllText(filename, text); + } + + private void DeleteFileForTesting(string filename) + { + File.Delete(filename); + } + } +} \ No newline at end of file diff --git a/MorseCodeTests/MorseCodeToEnglishTranslatorTests.cs b/MorseCodeTests/MorseCodeToEnglishTranslatorTests.cs deleted file mode 100644 index 8299b05..0000000 --- a/MorseCodeTests/MorseCodeToEnglishTranslatorTests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using MorseCode; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - - -namespace MorseCode.Tests -{ - [TestClass()] - public class MorseCodeToEnglishTranslatorTests - { - private MorseCodeToEnglishTranslator translator; - - [TestMethod()] - public void TranslateFileTest() - { - Assert.Fail(); - } - - [TestMethod()] - public void TranslateLineTest() - { - Assert.Fail(); - } - } -} \ No newline at end of file diff --git a/MorseCodeTests/test.txt b/MorseCodeTests/test.txt deleted file mode 100644 index e974356..0000000 --- a/MorseCodeTests/test.txt +++ /dev/null @@ -1,2 +0,0 @@ --..||---||--. -….||.||.-..||.-..||---||||.--||---||.-.||.-..||-.. \ No newline at end of file From a31785df04e434c99907a9417597421205954aad Mon Sep 17 00:00:00 2001 From: Elijah Johnson Date: Fri, 22 Mar 2019 16:50:01 -0600 Subject: [PATCH 4/6] Updated README --- README.md | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 605e027..48b415a 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,17 @@ -Morse Code -========== +# Morse Code +Written by Elijah Johnson -The Problem ------------ -Morse code is a way to encode messages in a series of long and short sounds or visual signals. During transmission, operators use pauses to split letters and words. +Program to convert from Morse code to English characters. +Written in C# on Visual Studio, with MSTest for unit testing. -Please write a program which will translate lines of Morse code into readable English text. The program should: +## Instructions +* Clone the repo from [here](https://github.com/ElijahJohnson5/MorseCode) +* Open the MorseCode.sln file +* Build the program and either run it from the command line with a text file as an argument +or run it from visual studio with a command line argument set for the text file to convert -1. Accept a flat file as input. -2. Each new line will contain a string of Morse code. The characters used will be: - 1. . = dot - 2. \- = dash - 3. || = break -3. Output the English text for each line +### File Layout +This program accepts a file as input with lines of Morse code that will be converted to English characters, the converted string will be printed to standard out. -Sample Input ------------- --..||---||--. - -….||.||.-..||.-..||---||||.--||---||.-.||.-..||-.. - -Sample Output -------------- -dog - -hello world - -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. +### Tests +Tests are written with MSTest and can be run directly from visual studio, the unit tests attempt to cover most of the edge cases \ No newline at end of file From 5a0e8ad41ad9acae83ea347fd0ebdfcbe03c346b Mon Sep 17 00:00:00 2001 From: Elijah Johnson Date: Fri, 22 Mar 2019 18:35:51 -0600 Subject: [PATCH 5/6] Changed dictionary init to be from file --- MorseCode/MorseCode.csproj | 14 ++ MorseCode/MorseCodeToEnglishConverter.cs | 58 ++------ MorseCode/Properties/Resources.Designer.cs | 72 ++++++++++ MorseCode/Properties/Resources.resx | 124 ++++++++++++++++++ MorseCode/Resources/MorseToEnglish.txt | 36 +++++ .../MorseCodeToEnglishConverterTests.cs | 34 +++-- 6 files changed, 280 insertions(+), 58 deletions(-) create mode 100644 MorseCode/Properties/Resources.Designer.cs create mode 100644 MorseCode/Properties/Resources.resx create mode 100644 MorseCode/Resources/MorseToEnglish.txt diff --git a/MorseCode/MorseCode.csproj b/MorseCode/MorseCode.csproj index 0e8d66a..4a513f6 100644 --- a/MorseCode/MorseCode.csproj +++ b/MorseCode/MorseCode.csproj @@ -46,9 +46,23 @@ + + True + True + Resources.resx + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + \ No newline at end of file diff --git a/MorseCode/MorseCodeToEnglishConverter.cs b/MorseCode/MorseCodeToEnglishConverter.cs index 72c68e9..de2b326 100644 --- a/MorseCode/MorseCodeToEnglishConverter.cs +++ b/MorseCode/MorseCodeToEnglishConverter.cs @@ -1,4 +1,5 @@ -using System; +using MorseCode.Properties; +using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -20,45 +21,14 @@ public class MorseCodeToEnglishConverter : IOneWayConverter /// public MorseCodeToEnglishConverter() { - morseToCharDict = new Dictionary - { - { ".-", 'a' }, - { "-...", 'b' }, - { "-.-.", 'c' }, - { "-..", 'd' }, - { ".", 'e' }, - { "..-.", 'f' }, - { "--.", 'g' }, - { "....", 'h' }, - { "..", 'i' }, - { ".---", 'j' }, - { "-.-", 'k' }, - { ".-..", 'l' }, - { "--", 'm' }, - { "-.", 'n' }, - { "---", 'o' }, - { ".--.", 'p' }, - { "--.-", 'q' }, - { ".-.", 'r' }, - { "...", 's' }, - { "-", 't' }, - { "..-", 'u' }, - { "...-", 'v' }, - { ".--", 'w' }, - { "-..-", 'x' }, - { "-.--", 'y' }, - { "--..", 'z' }, - { "-----", '0' }, - { ".----", '1' }, - { "..---", '2' }, - { "...--", '3' }, - { "....-", '4' }, - { ".....", '5' }, - { "-....", '6' }, - { "--...", '7' }, - { "---..", '8' }, - { "----.", '9' } - }; + morseToCharDict = new Dictionary(); + string[] lines = Resources.MorseToEnglish.Split( + new string[] { System.Environment.NewLine }, + StringSplitOptions.None); + foreach (string line in lines) { + string[] keyValue = line.Split(new char[] { ',' }); + morseToCharDict.Add(keyValue[0], keyValue[1][0]); + } } /// @@ -91,17 +61,17 @@ public string ConvertLine(string line) { string[] split = line.Split(new string[] { "||" }, StringSplitOptions.None); StringBuilder sb = new StringBuilder(); - foreach (string s in split) + foreach (string letter in split) { //If there are two breaks in a row add a space - if (s.Length == 0) + if (letter.Length == 0) { sb.Append(" "); } - else if (morseToCharDict.ContainsKey(s)) + else if (morseToCharDict.ContainsKey(letter)) { //Append character in dictionary if the dictionary contains the current string - sb.Append(morseToCharDict[s]); + sb.Append(morseToCharDict[letter]); } else { diff --git a/MorseCode/Properties/Resources.Designer.cs b/MorseCode/Properties/Resources.Designer.cs new file mode 100644 index 0000000..852652a --- /dev/null +++ b/MorseCode/Properties/Resources.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MorseCode.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MorseCode.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to . + /// + internal static string MorseToEnglish { + get { + return ResourceManager.GetString("MorseToEnglish", resourceCulture); + } + } + } +} diff --git a/MorseCode/Properties/Resources.resx b/MorseCode/Properties/Resources.resx new file mode 100644 index 0000000..72ab82d --- /dev/null +++ b/MorseCode/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\MorseToEnglish.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + \ No newline at end of file diff --git a/MorseCode/Resources/MorseToEnglish.txt b/MorseCode/Resources/MorseToEnglish.txt new file mode 100644 index 0000000..3d25f4c --- /dev/null +++ b/MorseCode/Resources/MorseToEnglish.txt @@ -0,0 +1,36 @@ +.-,a +-...,b +-.-.,c +-..,d +.,e +..-.,f +--.,g +....,h +..,i +.---,j +-.-,k +.-..,l +--,m +-.,n +---,o +.--.,p +--.-,q +.-.,r +...,s +-,t +..-,u +...-,v +.--,w +-..-,x +-.--,y +--..,z +-----,0 +.----,1 +..---,2 +...--,3 +....-,4 +.....,5 +-....,6 +--...,7 +---..,8 +----.,9 \ No newline at end of file diff --git a/MorseCodeTests/MorseCodeToEnglishConverterTests.cs b/MorseCodeTests/MorseCodeToEnglishConverterTests.cs index 2b278bf..f35bcf1 100644 --- a/MorseCodeTests/MorseCodeToEnglishConverterTests.cs +++ b/MorseCodeTests/MorseCodeToEnglishConverterTests.cs @@ -7,11 +7,14 @@ namespace MorseCode.Tests { /// /// Test class for unit testing + /// Calls either ConvertFile or ConvertLine on the converter + /// member variable, and Asserts values based on what the Morse + /// code should be /// [TestClass()] public class MorseCodeToEnglishConverterTests { - private readonly MorseCodeToEnglishConverter translator = new MorseCodeToEnglishConverter(); + private readonly MorseCodeToEnglishConverter converter = new MorseCodeToEnglishConverter(); [TestMethod()] public void ConvertFileTest() @@ -19,7 +22,7 @@ public void ConvertFileTest() CreateFileForTesting("test.txt", "-..||---||--." + System.Environment.NewLine + "....||.||.-..||.-..||---||||.--||---||.-.||.-..||-.."); - List result = (List)translator.ConvertFile("test.txt"); + List result = (List)converter.ConvertFile("test.txt"); DeleteFileForTesting("test.txt"); CollectionAssert.AreEqual(new List { "dog", "hello world" }, result); } @@ -27,56 +30,56 @@ public void ConvertFileTest() [TestMethod()] public void ConvertLineTest() { - string result = translator.ConvertLine("..-.||---||---"); + string result = converter.ConvertLine("..-.||---||---"); Assert.AreEqual("foo", result); } [TestMethod()] public void NumberTest() { - string result = translator.ConvertLine(".----||..---||||...--"); + string result = converter.ConvertLine(".----||..---||||...--"); Assert.AreEqual("12 3", result); } [TestMethod()] public void InvalidCharTest() { - string result = translator.ConvertLine("........||.-"); + string result = converter.ConvertLine("........||.-"); Assert.AreEqual("*a", result); } [TestMethod()] public void InvalidCharsTest() { - string result = translator.ConvertLine("f||o||o||.-"); + string result = converter.ConvertLine("f||o||o||.-"); Assert.AreEqual("***a", result); } [TestMethod()] public void ThreeBreaksTest() { - string result = translator.ConvertLine("..-.||---||---||||||-...||.-||.-."); + string result = converter.ConvertLine("..-.||---||---||||||-...||.-||.-."); Assert.AreEqual("foo bar", result); } [TestMethod()] public void InvalidBreakTest() { - string result = translator.ConvertLine("..|.-|-.||.-"); + string result = converter.ConvertLine("..|.-|-.||.-"); Assert.AreEqual("*a", result); } [TestMethod()] public void NumberAndCharTest() { - string result = translator.ConvertLine("..||-.||||-....||...--"); + string result = converter.ConvertLine("..||-.||||-....||...--"); Assert.AreEqual("in 63", result); } [TestMethod()] public void NumberAndCharAndInvalidTest() { - string result = translator.ConvertLine("..||n||||-....||...--"); + string result = converter.ConvertLine("..||n||||-....||...--"); Assert.AreEqual("i* 63", result); } @@ -84,7 +87,7 @@ public void NumberAndCharAndInvalidTest() public void EmptyFileTest() { CreateFileForTesting("empty.txt", ""); - IList result = translator.ConvertFile("empty.txt"); + IList result = converter.ConvertFile("empty.txt"); DeleteFileForTesting("empty.txt"); Assert.IsTrue((result.Count == 0)); } @@ -98,10 +101,13 @@ public void BigFileTest() + System.Environment.NewLine + "-||....||..||...||||..||...||||.-||||-||.||...||-||||...||-||.-.||..||-.||--." + System.Environment.NewLine - + ".-..||---||.-.||.||--||||..||.--.||...||..-||--||||-..||---||.-..||---||.-.||||...||..||-||||.-||--||.||-"); - List result = (List)translator.ConvertFile("test.txt"); + + ".-..||---||.-.||.||--||||..||.--.||...||..-||--" + + "||||-..||---||.-..||---||.-.||||...||..||-||||.-||--||.||-"); + List result = (List)converter.ConvertFile("test.txt"); DeleteFileForTesting("test.txt"); - CollectionAssert.AreEqual(new List { "dog", "hello world", "this is a test string", "lorem ipsum dolor sit amet" }, result); + CollectionAssert.AreEqual( + new List { "dog", "hello world", "this is a test string", "lorem ipsum dolor sit amet" }, + result); } From f6ff126a3c34345ae56f0ef56f972457f23cd122 Mon Sep 17 00:00:00 2001 From: Elijah Johnson Date: Fri, 22 Mar 2019 18:37:40 -0600 Subject: [PATCH 6/6] Added comments --- MorseCode/MorseCodeToEnglishConverter.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MorseCode/MorseCodeToEnglishConverter.cs b/MorseCode/MorseCodeToEnglishConverter.cs index de2b326..4eebc29 100644 --- a/MorseCode/MorseCodeToEnglishConverter.cs +++ b/MorseCode/MorseCodeToEnglishConverter.cs @@ -22,11 +22,14 @@ public class MorseCodeToEnglishConverter : IOneWayConverter public MorseCodeToEnglishConverter() { morseToCharDict = new Dictionary(); + //Get the resource file string[] lines = Resources.MorseToEnglish.Split( new string[] { System.Environment.NewLine }, StringSplitOptions.None); foreach (string line in lines) { string[] keyValue = line.Split(new char[] { ',' }); + //The first value is the Morse + //The second is the character morseToCharDict.Add(keyValue[0], keyValue[1][0]); } }