Алексей Колесов 2 vuotta sitten
vanhempi
commit
43da58cc25
3 muutettua tiedostoa jossa 171 lisäystä ja 65 poistoa
  1. 120 1
      UnitTests/UnitTest1.cs
  2. 6 0
      UnitTests/UnitTests.csproj
  3. 45 64
      WSUniversalLib/Calculation.cs

+ 120 - 1
UnitTests/UnitTest1.cs

@@ -1,14 +1,133 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using System;
 using System;
+using WSUniversalLib;
 
 
 namespace UnitTests
 namespace UnitTests
 {
 {
     [TestClass]
     [TestClass]
     public class UnitTest1
     public class UnitTest1
     {
     {
+        Calculation calculation = new Calculation();
         [TestMethod]
         [TestMethod]
-        public void TestMethod1()
+        public void GetQuantityForProduct_CheckDLL()
         {
         {
+            int expect = calculation.GetPriorityForAgent(2, 23, (float)1.5);
+            int answer = 5;
+            Assert.AreEqual(expect, answer);
+ 
         }
         }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckZeroType()
+        {
+            int expect = calculation.GetPriorityForAgent(0, 23, (float)1.5);
+            int answer = -1;
+            Assert.AreEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_ZeroAge()
+        {
+            int expect = calculation.GetPriorityForAgent(2, 0, (float)1.5);
+            int answer = -1;
+            Assert.AreEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckZeroExp()
+        {
+            int expect = calculation.GetPriorityForAgent(2, 23, 0);
+            int answer = -1;
+            Assert.AreEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckSame()
+        {
+            int expect = calculation.GetPriorityForAgent(2, 23, (float)1.5);
+            int answer = calculation.GetPriorityForAgent(2, 23, (float)1.5); ;
+            Assert.AreNotSame(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckIsNotNull()
+        {
+            int expect = calculation.GetPriorityForAgent(2, 23, (float)1.5);
+            
+            Assert.IsNotNull(expect);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckTypeData()
+        {
+            int expect = calculation.GetPriorityForAgent(2, 23, (float)1.5);
+            
+            Assert.IsInstanceOfType(expect, typeof(int));
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckBigIntType()
+        {
+            int expect = calculation.GetPriorityForAgent(200, 23, (float)1.5);
+            int answer = -1;
+            Assert.AreEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckBigIntAge()
+        {
+            int expect = calculation.GetPriorityForAgent(2, 200, (float)1.5);
+            int answer = -1;
+            Assert.AreEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckBigFloat()
+        {
+            int expect = calculation.GetPriorityForAgent(2, 23, (float)200);
+            int answer = -1;
+            Assert.AreEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckAllZero()
+        {
+            int expect = calculation.GetPriorityForAgent(0, 0, (float)0);
+            int answer = -1;
+            Assert.AreEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_ChecNotEqualType()
+        {
+            int expect = calculation.GetPriorityForAgent(1, 23, (float)1.5);
+            int answer = 4;
+            Assert.AreNotEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_NotEquaAge()
+        {
+            int expect = calculation.GetPriorityForAgent(2, 1, (float)1.5);
+            int answer = 5;
+            Assert.AreEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_NotEualExp()
+        {
+            int expect = calculation.GetPriorityForAgent(2, 23, (float)1);
+            int answer = 3;
+            Assert.AreEqual(expect, answer);
+
+        }
+        [TestMethod]
+        public void GetQuantityForProduct_CheckPriority()
+        {
+            int expect = calculation.GetPriorityForAgent(3, 23, (float)1.5);
+            int answer = 7;
+            Assert.AreEqual(expect, answer);
+
+        }
+
     }
     }
 }
 }

+ 6 - 0
UnitTests/UnitTests.csproj

@@ -55,6 +55,12 @@
   <ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />
     <None Include="packages.config" />
   </ItemGroup>
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\WSUniversalLib\WSUniversalLib.csproj">
+      <Project>{41769c24-bf82-495b-9a89-4363236596f9}</Project>
+      <Name>WSUniversalLib</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
   <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

+ 45 - 64
WSUniversalLib/Calculation.cs

@@ -17,80 +17,61 @@ namespace WSUniversalLib
         /// <returns>Новый приоритет агента</returns>
         /// <returns>Новый приоритет агента</returns>
         public int GetPriorityForAgent(int agentType, float age, float experience)
         public int GetPriorityForAgent(int agentType, float age, float experience)
         {
         {
-            
-
-            int NewPriority = 0;
-            double coeff;
-            if (agentType <= 0 || age <= 0 || experience <= 0)
+            if (agentType<= 0 || age <= 0 || experience<=0 )
             {
             {
-                return -1;
+                return - 1;
             }
             }
-            switch (agentType)
-            {
-                case 1:
-                    coeff = 1.8;
-                    break;
 
 
-                case 2:
+                double coeff;
+                if (agentType == 1 && age < 26 && experience < 4)
+                {
+                    coeff = 1.8 + 0.1;
+                }
+                else if (agentType == 2 && age < 26 && experience < 4)
+                {
+                    coeff = 3.2 + 0.17;
+                }
+                else if (agentType == 3 && age < 26 && experience < 4)
+                {
+                    coeff = 4.1 + 0.26;
+                }
+                else if (agentType == 1 && age > 26 && experience > 4)
+                {
+                    coeff = 1.8;
+                }
+                else if (agentType == 2 && age > 26 && experience > 4)
+                {
                     coeff = 3.2;
                     coeff = 3.2;
-                    break;
-
-                case 3:
+                }
+                else if (agentType == 3 && age > 26 && experience > 4)
+                {
                     coeff = 4.1;
                     coeff = 4.1;
-                    break;
-                default:
-                    coeff = 0;
-                    break;
-            }
-            if (experience > 10)
-            {
-                coeff*= 0.5;
-
-            }
-            else if (experience > 20)
-            {
-                coeff *= 0.7;
-
-            }
-
-            else if (experience > 40)
-            {
-                coeff *= 0.9;
-
-            }
-            else
-            {
-                coeff *= 0;
-            }
-
-            if (age <= 25 && experience < 3)
-            {
-                switch (agentType)
+                }
+                else
                 {
                 {
-                    case 1:
-                        coeff += 0.1;
-                        break;
-
-                    case 2:
-                        coeff += 0.17;
-                        break;
-
-                    case 3:
-                        coeff += 0.26;
-                        break;
-                    default:
-                        coeff = 0;
-                        break;
+                    return -1;
                 }
                 }
-            }
-
 
 
-            NewPriority = Convert.ToInt32(Math.Ceiling(experience * coeff));
 
 
+                if (experience > 11)
+                {
+                    coeff += 0.5;
+                }
+                else if (experience > 21)
+                {
+                    coeff += 0.7;
+                }
+                else if (experience > 41)
+                {
+                    coeff += 0.9;
+                }
 
 
+                int NewPriority = Convert.ToInt32(Math.Round(experience * coeff));
+                return NewPriority;
+            }
 
 
-            return NewPriority;
         }
         }
-
     }
     }
-}
+  
+    
+