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..4a513f6 --- /dev/null +++ b/MorseCode/MorseCode.csproj @@ -0,0 +1,68 @@ + + + + + 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 + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + + \ No newline at end of file diff --git a/MorseCode/MorseCodeToEnglishConverter.cs b/MorseCode/MorseCodeToEnglishConverter.cs new file mode 100644 index 0000000..4eebc29 --- /dev/null +++ b/MorseCode/MorseCodeToEnglishConverter.cs @@ -0,0 +1,89 @@ +using MorseCode.Properties; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace MorseCode +{ + /// + /// A converter for Morse code to English + /// Implements the OneWayConverter interface + /// + public class MorseCodeToEnglishConverter : IOneWayConverter + { + //The dictionary used for conversion + private IDictionary morseToCharDict; + + /// + /// Creates a new MorseCodeToEnglishConverter + /// Initializes the dictionary based on Morse code to English + /// + 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]); + } + } + + /// + /// 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) + { + //Add each converted line + result.Add(ConvertLine(line)); + } + + return result; + } + + /// + /// 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 letter in split) + { + //If there are two breaks in a row add a space + if (letter.Length == 0) + { + sb.Append(" "); + } + else if (morseToCharDict.ContainsKey(letter)) + { + //Append character in dictionary if the dictionary contains the current string + sb.Append(morseToCharDict[letter]); + } + 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/Program.cs b/MorseCode/Program.cs new file mode 100644 index 0000000..9d1a834 --- /dev/null +++ b/MorseCode/Program.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using System.Collections.Generic; + +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) + { + //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; + } + + //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/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/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/MorseCodeTests.csproj b/MorseCodeTests/MorseCodeTests.csproj new file mode 100644 index 0000000..cc73e98 --- /dev/null +++ b/MorseCodeTests/MorseCodeTests.csproj @@ -0,0 +1,106 @@ + + + + + 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/MorseCodeToEnglishConverterTests.cs b/MorseCodeTests/MorseCodeToEnglishConverterTests.cs new file mode 100644 index 0000000..f35bcf1 --- /dev/null +++ b/MorseCodeTests/MorseCodeToEnglishConverterTests.cs @@ -0,0 +1,124 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using System.IO; + + +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 converter = new MorseCodeToEnglishConverter(); + + [TestMethod()] + public void ConvertFileTest() + { + CreateFileForTesting("test.txt", "-..||---||--." + + System.Environment.NewLine + + "....||.||.-..||.-..||---||||.--||---||.-.||.-..||-.."); + List result = (List)converter.ConvertFile("test.txt"); + DeleteFileForTesting("test.txt"); + CollectionAssert.AreEqual(new List { "dog", "hello world" }, result); + } + + [TestMethod()] + public void ConvertLineTest() + { + string result = converter.ConvertLine("..-.||---||---"); + Assert.AreEqual("foo", result); + } + + [TestMethod()] + public void NumberTest() + { + string result = converter.ConvertLine(".----||..---||||...--"); + Assert.AreEqual("12 3", result); + } + + [TestMethod()] + public void InvalidCharTest() + { + string result = converter.ConvertLine("........||.-"); + Assert.AreEqual("*a", result); + } + + [TestMethod()] + public void InvalidCharsTest() + { + string result = converter.ConvertLine("f||o||o||.-"); + Assert.AreEqual("***a", result); + } + + [TestMethod()] + public void ThreeBreaksTest() + { + string result = converter.ConvertLine("..-.||---||---||||||-...||.-||.-."); + Assert.AreEqual("foo bar", result); + } + + [TestMethod()] + public void InvalidBreakTest() + { + string result = converter.ConvertLine("..|.-|-.||.-"); + Assert.AreEqual("*a", result); + } + + [TestMethod()] + public void NumberAndCharTest() + { + string result = converter.ConvertLine("..||-.||||-....||...--"); + Assert.AreEqual("in 63", result); + } + + [TestMethod()] + public void NumberAndCharAndInvalidTest() + { + string result = converter.ConvertLine("..||n||||-....||...--"); + Assert.AreEqual("i* 63", result); + } + + [TestMethod()] + public void EmptyFileTest() + { + CreateFileForTesting("empty.txt", ""); + IList result = converter.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)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); + } + + + 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/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 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