From b41e0b15a545a03f0f834607e8c71b516d80085b Mon Sep 17 00:00:00 2001 From: Date: Mon, 18 Mar 2019 19:51:47 -0400 Subject: [PATCH 1/6] Initial commit --- .gitignore | 346 +++++++++++++++++++++++ MorseCode.sln | 37 +++ MorseCode/MorseCode.csproj | 8 + MorseCode/Program.cs | 11 + MorseCodeLibrary/Class1.cs | 7 + MorseCodeLibrary/MorseCodeLibrary.csproj | 7 + MorseCodeTest/MorseCodeTest.csproj | 15 + MorseCodeTest/UnitTest.cs | 12 + 8 files changed, 443 insertions(+) create mode 100644 .gitignore create mode 100644 MorseCode.sln create mode 100644 MorseCode/MorseCode.csproj create mode 100644 MorseCode/Program.cs create mode 100644 MorseCodeLibrary/Class1.cs create mode 100644 MorseCodeLibrary/MorseCodeLibrary.csproj create mode 100644 MorseCodeTest/MorseCodeTest.csproj create mode 100644 MorseCodeTest/UnitTest.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..20522cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,346 @@ +## 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 +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +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/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.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 +*.appxbundle +*.appxupload + +# 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/ +# ASP.NET Core default setup: bower directory is configured as wwwroot/lib/ and bower restore is true +**/wwwroot/lib/ + +# 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 +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# 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/ + +# CodeRush personal settings +.cr/personal + +# 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 + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ \ No newline at end of file diff --git a/MorseCode.sln b/MorseCode.sln new file mode 100644 index 0000000..fa02f49 --- /dev/null +++ b/MorseCode.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.421 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCode", "MorseCode\MorseCode.csproj", "{57067FA1-7108-4AAA-AC18-450BE9D3C037}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCodeLibrary", "MorseCodeLibrary\MorseCodeLibrary.csproj", "{CD3E0A58-5339-42EE-8369-AF24066DBA77}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCodeTest", "MorseCodeTest\MorseCodeTest.csproj", "{9176F838-9B9B-4C9E-A6C3-70344CCC849C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {57067FA1-7108-4AAA-AC18-450BE9D3C037}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57067FA1-7108-4AAA-AC18-450BE9D3C037}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57067FA1-7108-4AAA-AC18-450BE9D3C037}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57067FA1-7108-4AAA-AC18-450BE9D3C037}.Release|Any CPU.Build.0 = Release|Any CPU + {CD3E0A58-5339-42EE-8369-AF24066DBA77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD3E0A58-5339-42EE-8369-AF24066DBA77}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD3E0A58-5339-42EE-8369-AF24066DBA77}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD3E0A58-5339-42EE-8369-AF24066DBA77}.Release|Any CPU.Build.0 = Release|Any CPU + {9176F838-9B9B-4C9E-A6C3-70344CCC849C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9176F838-9B9B-4C9E-A6C3-70344CCC849C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9176F838-9B9B-4C9E-A6C3-70344CCC849C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9176F838-9B9B-4C9E-A6C3-70344CCC849C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {51EA4905-EB17-43E2-9F91-0C9B5B7A47CE} + EndGlobalSection +EndGlobal diff --git a/MorseCode/MorseCode.csproj b/MorseCode/MorseCode.csproj new file mode 100644 index 0000000..01d5113 --- /dev/null +++ b/MorseCode/MorseCode.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/MorseCode/Program.cs b/MorseCode/Program.cs new file mode 100644 index 0000000..a640f70 --- /dev/null +++ b/MorseCode/Program.cs @@ -0,0 +1,11 @@ +using System; + +namespace MorseCode { + + class Program { + + static void Main(string[] args) { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/MorseCodeLibrary/Class1.cs b/MorseCodeLibrary/Class1.cs new file mode 100644 index 0000000..7073a3c --- /dev/null +++ b/MorseCodeLibrary/Class1.cs @@ -0,0 +1,7 @@ +using System; + +namespace MorseCodeLibrary { + + public class Class1 { + } +} diff --git a/MorseCodeLibrary/MorseCodeLibrary.csproj b/MorseCodeLibrary/MorseCodeLibrary.csproj new file mode 100644 index 0000000..3154d95 --- /dev/null +++ b/MorseCodeLibrary/MorseCodeLibrary.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp2.2 + + + diff --git a/MorseCodeTest/MorseCodeTest.csproj b/MorseCodeTest/MorseCodeTest.csproj new file mode 100644 index 0000000..723ea94 --- /dev/null +++ b/MorseCodeTest/MorseCodeTest.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp2.2 + + false + + + + + + + + + diff --git a/MorseCodeTest/UnitTest.cs b/MorseCodeTest/UnitTest.cs new file mode 100644 index 0000000..1464c8d --- /dev/null +++ b/MorseCodeTest/UnitTest.cs @@ -0,0 +1,12 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace MorseCodeTest { + + [TestClass] + public class UnitTest { + + [TestMethod] + public void TestMethod() { + } + } +} From 9b7803eb4ebaf11fae1143c73bdcfc82b4c0b679 Mon Sep 17 00:00:00 2001 From: Date: Mon, 18 Mar 2019 22:53:12 -0400 Subject: [PATCH 2/6] Passing test cases --- MorseCodeLibrary/Class1.cs | 7 -- MorseCodeLibrary/MorseCodeTranslator.cs | 85 ++++++++++++++++++++++++ MorseCodeTest/MorseCodeTest.cs | 86 +++++++++++++++++++++++++ MorseCodeTest/MorseCodeTest.csproj | 4 ++ MorseCodeTest/UnitTest.cs | 12 ---- 5 files changed, 175 insertions(+), 19 deletions(-) delete mode 100644 MorseCodeLibrary/Class1.cs create mode 100644 MorseCodeLibrary/MorseCodeTranslator.cs create mode 100644 MorseCodeTest/MorseCodeTest.cs delete mode 100644 MorseCodeTest/UnitTest.cs diff --git a/MorseCodeLibrary/Class1.cs b/MorseCodeLibrary/Class1.cs deleted file mode 100644 index 7073a3c..0000000 --- a/MorseCodeLibrary/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; - -namespace MorseCodeLibrary { - - public class Class1 { - } -} diff --git a/MorseCodeLibrary/MorseCodeTranslator.cs b/MorseCodeLibrary/MorseCodeTranslator.cs new file mode 100644 index 0000000..9ab0d66 --- /dev/null +++ b/MorseCodeLibrary/MorseCodeTranslator.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace MorseCodeLibrary { + + public class MorseCodeTranslator { + static IDictionary dictionary = 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" } + ,{ ".----", "1" } + ,{ "..---", "2" } + ,{ "...--", "3" } + ,{ "....-", "4" } + ,{ ".....", "5" } + ,{ "-....", "6" } + ,{ "--...", "7" } + ,{ "---..", "8" } + ,{ "----.", "9" } + ,{ "-----", "0" } + ,{ ",", " "} + }; + + /// + /// Translates a file containing morse code. + /// + /// The file to translate + /// A string containing the translation + public static string Translate(string inputFilePath) { + StringBuilder sb = new StringBuilder(); + + var lines = File.ReadLines(inputFilePath); + foreach (var line in lines) { + string translatedLine = TranslateLine(line); + sb.Append(translatedLine); + sb.AppendLine(); + } + + return sb.ToString(); + } + + /// + /// Returns the translation of an individual line. + /// + /// The line to translate + /// The translated line + public static string TranslateLine(string line) { + StringBuilder sb = new StringBuilder(); + string cleanedLine = line.Trim().Replace("||||", "||,||"); + + string[] letters = cleanedLine.Split("||"); + foreach (string letter in letters) { + string value = dictionary.ContainsKey(letter) ? dictionary[letter] : "!"; + sb.Append(value); + } + + return sb.ToString(); + } + } +} diff --git a/MorseCodeTest/MorseCodeTest.cs b/MorseCodeTest/MorseCodeTest.cs new file mode 100644 index 0000000..96898e0 --- /dev/null +++ b/MorseCodeTest/MorseCodeTest.cs @@ -0,0 +1,86 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using MorseCodeLibrary; +using System; +using System.Diagnostics; + +namespace MorseCodeTest { + + [TestClass] + public class MorseCodeTest { + + [TestMethod] + public void Test_Alphabet_A_Through_H() { + string input = ".-||-...||-.-.||-..||.||..-.||--.||...."; + string output = MorseCodeTranslator.TranslateLine(input); + + Assert.AreEqual("abcdefgh", output); + } + + [TestMethod] + public void Test_Alphabet_I_Through_P() { + string input = "..||.---||-.-||.-..||--||-.||---||.--."; + string output = MorseCodeTranslator.TranslateLine(input); + + Assert.AreEqual("ijklmnop", output); + } + + [TestMethod] + public void Test_Alphabet_Q_Through_Z() { + string input = "--.-||.-.||...||-||..-||...-||.--||-..-||-.--||--.."; + string output = MorseCodeTranslator.TranslateLine(input); + + Assert.AreEqual("qrstuvwxyz", output); + } + + [TestMethod] + public void Test_Numerals_One_Through_Five() { + string input = ".----||..---||...--||....-||....."; + string output = MorseCodeTranslator.TranslateLine(input); + + Assert.AreEqual("12345", output); + } + + [TestMethod] + public void Test_Numerals_Six_Through_Zero() { + string input = "-....||--...||---..||----.||-----"; + string output = MorseCodeTranslator.TranslateLine(input); + + Assert.AreEqual("67890", output); + } + + [TestMethod] + public void Test_String_Dog() { + string input = "-..||---||--."; + string output = MorseCodeTranslator.TranslateLine(input); + + Assert.AreEqual("dog", output); + } + + [TestMethod] + public void Test_String_Hello_World() { + string input = "....||.||.-..||.-..||---||||.--||---||.-.||.-..||-.."; + string output = MorseCodeTranslator.TranslateLine(input); + Console.WriteLine(output); + + Assert.AreEqual("hello world", output); + } + + [TestMethod] + public void Test_String_Non_Morse() { + string input = "This is not morse code"; + string output = MorseCodeTranslator.TranslateLine(input); + Console.WriteLine(output); + + Assert.AreEqual("!", output); + } + + [TestMethod] + public void Test_String_Invalid_Morse() { + string input = "....--.-.||-..||---||--.|| fs"; + string output = MorseCodeTranslator.TranslateLine(input); + Console.WriteLine(output); + + Assert.AreEqual("!dog!", output); + } + } +} diff --git a/MorseCodeTest/MorseCodeTest.csproj b/MorseCodeTest/MorseCodeTest.csproj index 723ea94..54b037b 100644 --- a/MorseCodeTest/MorseCodeTest.csproj +++ b/MorseCodeTest/MorseCodeTest.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/MorseCodeTest/UnitTest.cs b/MorseCodeTest/UnitTest.cs deleted file mode 100644 index 1464c8d..0000000 --- a/MorseCodeTest/UnitTest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace MorseCodeTest { - - [TestClass] - public class UnitTest { - - [TestMethod] - public void TestMethod() { - } - } -} From c15a8c95c57146d48249a0c3f12780fdd481f911 Mon Sep 17 00:00:00 2001 From: Date: Tue, 19 Mar 2019 00:06:17 -0400 Subject: [PATCH 3/6] Changed library to implement interface and updated test class --- MorseCodeLibrary/ITranslator.cs | 23 +++++++++++++++++++++++ MorseCodeLibrary/MorseCodeTranslator.cs | 19 ++++++++++--------- MorseCodeTest/MorseCodeTest.cs | 25 +++++++++++++++---------- 3 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 MorseCodeLibrary/ITranslator.cs diff --git a/MorseCodeLibrary/ITranslator.cs b/MorseCodeLibrary/ITranslator.cs new file mode 100644 index 0000000..04e0587 --- /dev/null +++ b/MorseCodeLibrary/ITranslator.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MorseCodeLibrary { + + public interface ITranslator { + + /// + /// Translates a file with the object's method of translation. + /// + /// The file to translate + /// A string containing the translation + string Translate(string inputFilePath); + + /// + /// Translates a string with the object's method of translation. + /// + /// The line to translate + /// The translated line + string TranslateLine(string line); + } +} diff --git a/MorseCodeLibrary/MorseCodeTranslator.cs b/MorseCodeLibrary/MorseCodeTranslator.cs index 9ab0d66..a472dad 100644 --- a/MorseCodeLibrary/MorseCodeTranslator.cs +++ b/MorseCodeLibrary/MorseCodeTranslator.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Text; namespace MorseCodeLibrary { - public class MorseCodeTranslator { - static IDictionary dictionary = new Dictionary() { + public class MorseCodeTranslator : ITranslator { + private IDictionary dictionary = new Dictionary() { { ".-", "a" } ,{ "-...", "b" } ,{ "-.-.", "c" } @@ -51,7 +50,7 @@ public class MorseCodeTranslator { /// /// The file to translate /// A string containing the translation - public static string Translate(string inputFilePath) { + public string Translate(string inputFilePath) { StringBuilder sb = new StringBuilder(); var lines = File.ReadLines(inputFilePath); @@ -65,15 +64,17 @@ public static string Translate(string inputFilePath) { } /// - /// Returns the translation of an individual line. + /// Returns the translation of an individual line of morse code. /// /// The line to translate /// The translated line - public static string TranslateLine(string line) { + public string TranslateLine(string line) { StringBuilder sb = new StringBuilder(); - string cleanedLine = line.Trim().Replace("||||", "||,||"); - string[] letters = cleanedLine.Split("||"); + // Replace two breaks in a row with a comma in between, signifying a space + string formattedLine = line.Trim().Replace("||||", "||,||"); + + string[] letters = formattedLine.Split("||"); foreach (string letter in letters) { string value = dictionary.ContainsKey(letter) ? dictionary[letter] : "!"; sb.Append(value); diff --git a/MorseCodeTest/MorseCodeTest.cs b/MorseCodeTest/MorseCodeTest.cs index 96898e0..5a6b88d 100644 --- a/MorseCodeTest/MorseCodeTest.cs +++ b/MorseCodeTest/MorseCodeTest.cs @@ -1,17 +1,22 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using MorseCodeLibrary; using System; -using System.Diagnostics; namespace MorseCodeTest { [TestClass] public class MorseCodeTest { + static ITranslator translator; + + [AssemblyInitialize] + public static void AssemblyInit(TestContext context) { + translator = new MorseCodeTranslator(); + } [TestMethod] public void Test_Alphabet_A_Through_H() { string input = ".-||-...||-.-.||-..||.||..-.||--.||...."; - string output = MorseCodeTranslator.TranslateLine(input); + string output = translator.TranslateLine(input); Assert.AreEqual("abcdefgh", output); } @@ -19,7 +24,7 @@ public void Test_Alphabet_A_Through_H() { [TestMethod] public void Test_Alphabet_I_Through_P() { string input = "..||.---||-.-||.-..||--||-.||---||.--."; - string output = MorseCodeTranslator.TranslateLine(input); + string output = translator.TranslateLine(input); Assert.AreEqual("ijklmnop", output); } @@ -27,7 +32,7 @@ public void Test_Alphabet_I_Through_P() { [TestMethod] public void Test_Alphabet_Q_Through_Z() { string input = "--.-||.-.||...||-||..-||...-||.--||-..-||-.--||--.."; - string output = MorseCodeTranslator.TranslateLine(input); + string output = translator.TranslateLine(input); Assert.AreEqual("qrstuvwxyz", output); } @@ -35,7 +40,7 @@ public void Test_Alphabet_Q_Through_Z() { [TestMethod] public void Test_Numerals_One_Through_Five() { string input = ".----||..---||...--||....-||....."; - string output = MorseCodeTranslator.TranslateLine(input); + string output = translator.TranslateLine(input); Assert.AreEqual("12345", output); } @@ -43,7 +48,7 @@ public void Test_Numerals_One_Through_Five() { [TestMethod] public void Test_Numerals_Six_Through_Zero() { string input = "-....||--...||---..||----.||-----"; - string output = MorseCodeTranslator.TranslateLine(input); + string output = translator.TranslateLine(input); Assert.AreEqual("67890", output); } @@ -51,7 +56,7 @@ public void Test_Numerals_Six_Through_Zero() { [TestMethod] public void Test_String_Dog() { string input = "-..||---||--."; - string output = MorseCodeTranslator.TranslateLine(input); + string output = translator.TranslateLine(input); Assert.AreEqual("dog", output); } @@ -59,7 +64,7 @@ public void Test_String_Dog() { [TestMethod] public void Test_String_Hello_World() { string input = "....||.||.-..||.-..||---||||.--||---||.-.||.-..||-.."; - string output = MorseCodeTranslator.TranslateLine(input); + string output = translator.TranslateLine(input); Console.WriteLine(output); Assert.AreEqual("hello world", output); @@ -68,7 +73,7 @@ public void Test_String_Hello_World() { [TestMethod] public void Test_String_Non_Morse() { string input = "This is not morse code"; - string output = MorseCodeTranslator.TranslateLine(input); + string output = translator.TranslateLine(input); Console.WriteLine(output); Assert.AreEqual("!", output); @@ -77,7 +82,7 @@ public void Test_String_Non_Morse() { [TestMethod] public void Test_String_Invalid_Morse() { string input = "....--.-.||-..||---||--.|| fs"; - string output = MorseCodeTranslator.TranslateLine(input); + string output = translator.TranslateLine(input); Console.WriteLine(output); Assert.AreEqual("!dog!", output); From ddebca3fc4f5216394109c3cebd96bf676b8b272 Mon Sep 17 00:00:00 2001 From: Date: Tue, 19 Mar 2019 00:13:02 -0400 Subject: [PATCH 4/6] Completed assignment --- MorseCode.sln | 6 ++--- MorseCode/MorseCode.csproj | 4 +++ MorseCode/MorseCodeDriver.cs | 32 ++++++++++++++++++++++++ MorseCode/Program.cs | 11 -------- MorseCode/Properties/launchSettings.json | 7 ++++++ 5 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 MorseCode/MorseCodeDriver.cs delete mode 100644 MorseCode/Program.cs create mode 100644 MorseCode/Properties/launchSettings.json diff --git a/MorseCode.sln b/MorseCode.sln index fa02f49..a7416d6 100644 --- a/MorseCode.sln +++ b/MorseCode.sln @@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28307.421 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCode", "MorseCode\MorseCode.csproj", "{57067FA1-7108-4AAA-AC18-450BE9D3C037}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MorseCode", "MorseCode\MorseCode.csproj", "{57067FA1-7108-4AAA-AC18-450BE9D3C037}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCodeLibrary", "MorseCodeLibrary\MorseCodeLibrary.csproj", "{CD3E0A58-5339-42EE-8369-AF24066DBA77}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MorseCodeLibrary", "MorseCodeLibrary\MorseCodeLibrary.csproj", "{CD3E0A58-5339-42EE-8369-AF24066DBA77}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCodeTest", "MorseCodeTest\MorseCodeTest.csproj", "{9176F838-9B9B-4C9E-A6C3-70344CCC849C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MorseCodeTest", "MorseCodeTest\MorseCodeTest.csproj", "{9176F838-9B9B-4C9E-A6C3-70344CCC849C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/MorseCode/MorseCode.csproj b/MorseCode/MorseCode.csproj index 01d5113..935faad 100644 --- a/MorseCode/MorseCode.csproj +++ b/MorseCode/MorseCode.csproj @@ -5,4 +5,8 @@ netcoreapp2.2 + + + + diff --git a/MorseCode/MorseCodeDriver.cs b/MorseCode/MorseCodeDriver.cs new file mode 100644 index 0000000..7711818 --- /dev/null +++ b/MorseCode/MorseCodeDriver.cs @@ -0,0 +1,32 @@ +using MorseCodeLibrary; +using System; +using System.IO; + +namespace MorseCode { + + class MorseCodeDriver { + + static void Main(string[] args) { + if (ValidArgs(args)) { + string filePath = args[0]; + ITranslator translator = new MorseCodeTranslator(); + Console.WriteLine("Translating file: " + filePath); + Console.WriteLine("Any invalid characters will be denoted by '!'\n"); + Console.WriteLine(translator.Translate(filePath)); + } + } + + private static bool ValidArgs(string[] args) { + bool valid = true; + if (args.Length != 1) { + Console.WriteLine("Error: Must have only one argument specifying a valid file path"); + valid = false; + } else if (!File.Exists(args[0])) { + Console.WriteLine("Error: Could not read file " + args[0]); + valid = false; + } + + return valid; + } + } +} diff --git a/MorseCode/Program.cs b/MorseCode/Program.cs deleted file mode 100644 index a640f70..0000000 --- a/MorseCode/Program.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace MorseCode { - - class Program { - - static void Main(string[] args) { - Console.WriteLine("Hello World!"); - } - } -} diff --git a/MorseCode/Properties/launchSettings.json b/MorseCode/Properties/launchSettings.json new file mode 100644 index 0000000..19e8119 --- /dev/null +++ b/MorseCode/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "MorseCode": { + "commandName": "Project" + } + } +} \ No newline at end of file From b70bcb16a590f81e31a727bbd8e7b24f8cdbc534 Mon Sep 17 00:00:00 2001 From: Date: Tue, 19 Mar 2019 00:48:16 -0400 Subject: [PATCH 5/6] Update README.md --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 605e027..709fdec 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,45 @@ +# Morse Code + +By [Joshua Zinkovsky](mailto:joshua.zky@gmail.com) + +## Instructions + +1. Navigate to [repo](https://github.com/Josh961/MorseCode.git) +2. Clone locally using + `git clone https://github.com/Josh961/MorseCode.git` +3. Open `MorseCode.sln` +4. Right click the `MorseCode` project -> properties +5. Click debug and enter the path of the input file as an argument - application will not run otherwise +6. `ctrl+f5` to run the application +7. Application should display results and any errors in translating a character + +## Troubleshooting + +The application was cloned and tested on multiple machines and should work fine. However, if there +are any problems, please see the following points: + +1. Application is running on .NET Core 2.2 and user must have the SDK installed +2. If any build errors occur, try rebuilding the entire solution + +## Discussion + +I used the following technologies: C# and MSTest + +The solution is split up into three different projects. +1. `MorseCode` contains the driver program. +2. `MorseCodeLibrary` contains the `ITranslator` interface to implement future possible methods of translation. +3. `MorseCodeTest` contains the unit test file. + +## Requirements + +The program accepts a flat file as an input. It reads the file using the proper morse code characters, and outputs their +translation in English. + +#### Tests + +Run tests within visual studio using shortcut `ctrl+r a` + + Morse Code ========== From 15b189be0f65138b54b0a1ae1d001b8175317f00 Mon Sep 17 00:00:00 2001 From: Date: Tue, 19 Mar 2019 09:11:32 -0400 Subject: [PATCH 6/6] Removed unnecessary using statements --- MorseCodeLibrary/ITranslator.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/MorseCodeLibrary/ITranslator.cs b/MorseCodeLibrary/ITranslator.cs index 04e0587..0942806 100644 --- a/MorseCodeLibrary/ITranslator.cs +++ b/MorseCodeLibrary/ITranslator.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace MorseCodeLibrary { +namespace MorseCodeLibrary { public interface ITranslator {