Просмотр исходного кода

тест все еще не готов

Алёна Плотникова 3 лет назад
Родитель
Сommit
99476159c8

+ 9 - 1
UnitTestProject/UnitTest1.cs

@@ -1,14 +1,22 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using System;
+using numbersystem;
 
 namespace UnitTestProject
 {
     [TestClass]
-    public class UnitTest1
+    public class NStest
     {
         [TestMethod]
         public void TestMethod1()
         {
+            MainWindow page = new MainWindow();
+
+            string Exp, Res;
+
+            Exp = "10010110";
+            Res = page.TestNS(2, "1010 * 1111");
+            Assert.AreEqual(Exp, Res);
         }
     }
 }

+ 9 - 0
UnitTestProject/UnitTestProject.csproj

@@ -45,8 +45,11 @@
     <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
       <HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
     </Reference>
+    <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
     <Reference Include="System" />
     <Reference Include="System.Core" />
+    <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="UnitTest1.cs" />
@@ -55,6 +58,12 @@
   <ItemGroup>
     <None Include="packages.config" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\numbersystem\numbersystem.csproj">
+      <Project>{64379ba7-f7d5-4318-a174-21f1bf9ff92e}</Project>
+      <Name>numbersystem</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

+ 122 - 0
numbersystem/MainWindow.xaml.cs

@@ -284,6 +284,128 @@ namespace numbersystem
             }
         }
 
+        // для теста
+        public string TestNS(int ss, string inquiry)
+        {
+            string result = "";
+            if (inquiry != "")
+            {
+                if (inquiry[inquiry.Length - 1] != ' ')
+                {
+                    if (ss == 0)
+                    {
+                        MessageBox.Show("Не выбрана система счисления");
+                        return result;
+                    }
+
+                    // записываем выражение в переменную
+                    expression = inquiry;
+
+                    // разбиваем строку на массив
+                    string[] arr = expression.Split(' ');
+
+                        // перебираем массив и считаем высокоприоритетные операции
+                        for (int i = 0; i < arr.Length; i++)
+                        {
+                            // умножение
+                            if (arr[i] == "*")
+                            {
+                                if (arr[i - 1] == "_")
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) * Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 2] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                                else
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) * Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 1] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                            }
+                            // деление
+                            else if (arr[i] == "/")
+                            {
+                                if (arr[i - 1] == "_")
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) / Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 2] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                                else
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) / Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 1] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                            }
+                            // остаток от деления
+                            else if (arr[i] == "%")
+                            {
+                                if (arr[i - 1] == "_")
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) % Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 2] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                                else
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) % Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 1] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                            }
+                        }
+
+                        // узнаем размер будущего массива
+                        int l = 0;
+                        for (int i = 0; i < arr.Length; i++)
+                        {
+                            if (arr[i] != "_")
+                            {
+                                l++;
+                            }
+                        }
+
+                        // записать в новый массив результат предыдущего шага
+                        string[] arr2 = new string[l];
+                        int j = 0;
+                        for (int i = 0; i < arr.Length; i++)
+                        {
+                            if (arr[i] != "_")
+                            {
+                                arr2[j] = arr[i];
+                                j++;
+                            }
+                        }
+
+                        // первое число массива присваиваем переменной
+                        int rest = Convert.ToInt32(arr2[0], ss);
+
+                        // перебираем массив и считаем остальные операции
+                        for (int i = 1; i < arr2.Length; i++)
+                        {
+                            // сложение
+                            if (arr2[i] == "+")
+                            {
+                                rest += Convert.ToInt32(arr2[i + 1], ss);
+                            }
+                            // вычитание
+                            else if (arr2[i] == "-")
+                            {
+                                rest -= Convert.ToInt32(arr2[i + 1], ss);
+                            }
+                        }
+
+                        // выводим результат
+                        result = Convert.ToString(rest, ss);
+
+                        return result;
+                }
+            }
+            return result;
+        }
+
         // при нажатии на кнопки
         private void ca_Click(object sender, RoutedEventArgs e)
         {