diff --git a/Task1/Task1.sln b/Task1/Task1.sln new file mode 100644 index 0000000..6ac06a5 --- /dev/null +++ b/Task1/Task1.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Task1", "Task1\Task1.csproj", "{C07D4625-89EF-422D-A185-BF155104BAE8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C07D4625-89EF-422D-A185-BF155104BAE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C07D4625-89EF-422D-A185-BF155104BAE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C07D4625-89EF-422D-A185-BF155104BAE8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C07D4625-89EF-422D-A185-BF155104BAE8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Task1/Task1.v11.suo b/Task1/Task1.v11.suo new file mode 100644 index 0000000..b84afab Binary files /dev/null and b/Task1/Task1.v11.suo differ diff --git a/Task1/Task1/App.config b/Task1/Task1/App.config new file mode 100644 index 0000000..9c05822 --- /dev/null +++ b/Task1/Task1/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task1/Task1/OS.cs b/Task1/Task1/OS.cs new file mode 100644 index 0000000..31d5202 --- /dev/null +++ b/Task1/Task1/OS.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; + +namespace Task1 +{ + class OS + { + private Stack _dirs; + + public OS(string path=null) + { + _dirs = new Stack(); + if (string.IsNullOrEmpty(path)) return; + + foreach (string dir in path.Split('\\')) + { + if (dir == "..") + { + _dirs.Pop(); + } + else + { + if (dir!="") + _dirs.Push(dir); + } + } + } + + public string Path() + { + if (_dirs.Count <= 0) + { + return "\\"; + } + string result = ""; + foreach(string dir in _dirs) + { + if (result == "") + { + result = dir; + continue; + } + result = dir + "\\" + result; + } + result = "\\" + result; + return result; + } + + public string Listen(string cmd) + { + string[] _args = cmd.Split(' '); + string _errorMsg = "Incorrect input."; + + if (_args.Count() <= 0) + { + return _errorMsg; + } + switch (_args[0]) + { + case "cd": + { + if (_args.Count() <= 1) return _errorMsg; + + string _path = _args[1]; + if (string.IsNullOrEmpty(_path)) + { + return _errorMsg; + } + + if (_path[0] == '\\') + { + _dirs.Clear(); + + } + + foreach (string dir in _path.Split('\\')) + { + switch (dir) + { + case "": + { + _dirs.Clear(); + break; + } + case "..": + { + if (_dirs.Count>0) + _dirs.Pop(); + break; + } + default: + { + _dirs.Push(dir); + break; + } + } + + } + + return Path(); + } + case "pwd": + { + return Path(); + } + default: + { + return _errorMsg; + } + } + } + + + #region NUnit tests for all methods. + + [TestFixture] + public class TestClass + { + [Test] + public void Path_Test() + { + OS item = new OS(); + item._dirs = new Stack(); + item._dirs.Push("home"); + item._dirs.Push("movies"); + item._dirs.Push("horrors"); + Assert.AreEqual("\\home\\movies\\horrors", item.Path()); + for (int i = 0; i < 3; i++) + { + item._dirs.Pop(); + } + Assert.AreEqual("\\", item.Path()); + } + + [Test] + public void Constructor_Test() + { + OS item = new OS(); + Assert.IsEmpty(item._dirs); + item = new OS("\\"); + Assert.IsEmpty(item._dirs); + item = new OS("\\home\\programs\\..\\movies"); + item = new OS("home\\movies"); + Assert.AreEqual("\\home\\movies", item.Path()); + } + + [Test] + public void Listen_Test() + { + OS item = new OS(); + string errorMsg = "Incorrect input."; + Assert.AreEqual(errorMsg, item.Listen("")); + Assert.AreEqual(errorMsg, item.Listen("cd ")); + Assert.AreEqual(errorMsg, item.Listen("\\")); + Assert.AreEqual("\\", item.Listen("cd \\")); + Assert.AreEqual("\\", item.Listen("cd home\\..")); + item.Listen("cd \\home\\movies\\horrors"); + Assert.AreEqual("\\home\\movies\\horrors", item.Listen("pwd")); + } + } + #endregion + + } +} diff --git a/Task1/Task1/Program.cs b/Task1/Task1/Program.cs new file mode 100644 index 0000000..182f38e --- /dev/null +++ b/Task1/Task1/Program.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Task1 +{ + class Program + { + static void Main() + { + OS vasya = new OS(); + Console.WriteLine(vasya.Listen("pwd")); + vasya.Listen("cd \\home\\myfolder\\vasya\\..\\petya\\.."); + Console.WriteLine(vasya.Listen("pwd")); + Console.ReadLine(); + } + } +} diff --git a/Task1/Task1/Properties/AssemblyInfo.cs b/Task1/Task1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..069907a --- /dev/null +++ b/Task1/Task1/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Управление общими сведениями о сборке осуществляется с помощью +// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения, +// связанные со сборкой. +[assembly: AssemblyTitle("Task1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Task1")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Параметр ComVisible со значением FALSE делает типы в сборке невидимыми +// для COM-компонентов. Если требуется обратиться к типу в этой сборке через +// COM, задайте атрибуту ComVisible значение TRUE для этого типа. +[assembly: ComVisible(false)] + +// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM +[assembly: Guid("6b81b538-139a-44e8-821e-5266075c5133")] + +// Сведения о версии сборки состоят из следующих четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер построения +// Редакция +// +// Можно задать все значения или принять номер построения и номер редакции по умолчанию, +// используя "*", как показано ниже: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Task1/Task1/Task1.csproj b/Task1/Task1/Task1.csproj new file mode 100644 index 0000000..5b469ed --- /dev/null +++ b/Task1/Task1/Task1.csproj @@ -0,0 +1,64 @@ + + + + + Debug + AnyCPU + {C07D4625-89EF-422D-A185-BF155104BAE8} + Exe + Properties + Task1 + Task1 + v4.5.1 + 512 + + + 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/Task1/Task1/bin/Debug/Task1.exe b/Task1/Task1/bin/Debug/Task1.exe new file mode 100644 index 0000000..13dc9db Binary files /dev/null and b/Task1/Task1/bin/Debug/Task1.exe differ diff --git a/Task1/Task1/bin/Debug/Task1.exe.config b/Task1/Task1/bin/Debug/Task1.exe.config new file mode 100644 index 0000000..9c05822 --- /dev/null +++ b/Task1/Task1/bin/Debug/Task1.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task1/Task1/bin/Debug/Task1.pdb b/Task1/Task1/bin/Debug/Task1.pdb new file mode 100644 index 0000000..121491b Binary files /dev/null and b/Task1/Task1/bin/Debug/Task1.pdb differ diff --git a/Task1/Task1/bin/Debug/Task1.vshost.exe b/Task1/Task1/bin/Debug/Task1.vshost.exe new file mode 100644 index 0000000..8c84517 Binary files /dev/null and b/Task1/Task1/bin/Debug/Task1.vshost.exe differ diff --git a/Task1/Task1/bin/Debug/Task1.vshost.exe.config b/Task1/Task1/bin/Debug/Task1.vshost.exe.config new file mode 100644 index 0000000..9c05822 --- /dev/null +++ b/Task1/Task1/bin/Debug/Task1.vshost.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Task1/Task1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Task1/Task1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..73ff57e Binary files /dev/null and b/Task1/Task1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Task1/Task1/obj/Debug/Task1.csproj.FileListAbsolute.txt b/Task1/Task1/obj/Debug/Task1.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..d2705ca --- /dev/null +++ b/Task1/Task1/obj/Debug/Task1.csproj.FileListAbsolute.txt @@ -0,0 +1,9 @@ +E:\Git\Local\xpk\Task1\Task1\bin\Debug\Task1.exe.config +E:\Git\Local\xpk\Task1\Task1\obj\Debug\Task1.csprojResolveAssemblyReference.cache +E:\Git\Local\xpk\Task1\Task1\bin\Debug\Task1.exe +E:\Git\Local\xpk\Task1\Task1\bin\Debug\Task1.pdb +E:\Git\Local\xpk\Task1\Task1\obj\Debug\Task1.exe +E:\Git\Local\xpk\Task1\Task1\obj\Debug\Task1.pdb +E:\Git\Local\xpk\Task1\Task1\bin\Debug\nunit.framework.dll +E:\Git\Local\xpk\Task1\Task1\bin\Debug\nunit.mocks.dll +E:\Git\Local\xpk\Task1\Task1\bin\Debug\nunit.framework.xml diff --git a/Task1/Task1/obj/Debug/Task1.csprojResolveAssemblyReference.cache b/Task1/Task1/obj/Debug/Task1.csprojResolveAssemblyReference.cache new file mode 100644 index 0000000..5f955a4 Binary files /dev/null and b/Task1/Task1/obj/Debug/Task1.csprojResolveAssemblyReference.cache differ diff --git a/Task1/Task1/obj/Debug/Task1.exe b/Task1/Task1/obj/Debug/Task1.exe new file mode 100644 index 0000000..13dc9db Binary files /dev/null and b/Task1/Task1/obj/Debug/Task1.exe differ diff --git a/Task1/Task1/obj/Debug/Task1.pdb b/Task1/Task1/obj/Debug/Task1.pdb new file mode 100644 index 0000000..121491b Binary files /dev/null and b/Task1/Task1/obj/Debug/Task1.pdb differ diff --git a/Task1/Task1/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs b/Task1/Task1/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs new file mode 100644 index 0000000..e69de29 diff --git a/Task1/Task1/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs b/Task1/Task1/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs new file mode 100644 index 0000000..e69de29 diff --git a/Task1/Task1/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs b/Task1/Task1/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs new file mode 100644 index 0000000..e69de29