Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Task1/Task1.sln
Original file line number Diff line number Diff line change
@@ -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
Binary file added Task1/Task1.v11.suo
Binary file not shown.
6 changes: 6 additions & 0 deletions Task1/Task1/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
169 changes: 169 additions & 0 deletions Task1/Task1/OS.cs
Original file line number Diff line number Diff line change
@@ -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<string> _dirs;

public OS(string path=null)
{
_dirs = new Stack<string>();
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<string>();
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

}
}
20 changes: 20 additions & 0 deletions Task1/Task1/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
36 changes: 36 additions & 0 deletions Task1/Task1/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
64 changes: 64 additions & 0 deletions Task1/Task1/Task1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C07D4625-89EF-422D-A185-BF155104BAE8}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Task1</RootNamespace>
<AssemblyName>Task1</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
<Reference Include="nunit.mocks, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="OS.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Binary file added Task1/Task1/bin/Debug/Task1.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions Task1/Task1/bin/Debug/Task1.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
Binary file added Task1/Task1/bin/Debug/Task1.pdb
Binary file not shown.
Binary file added Task1/Task1/bin/Debug/Task1.vshost.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions Task1/Task1/bin/Debug/Task1.vshost.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
Binary file not shown.
9 changes: 9 additions & 0 deletions Task1/Task1/obj/Debug/Task1.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Binary file added Task1/Task1/obj/Debug/Task1.exe
Binary file not shown.
Binary file added Task1/Task1/obj/Debug/Task1.pdb
Binary file not shown.