Aliendreamer

unittesting07HackProblem

Apr 9th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1.  public interface IMath
  2.     {
  3.         int ReturnAbsValue(double i);
  4.         int ReturnFloorValue(double i);
  5.  
  6.     }
  7.  
  8.  
  9.     using System;
  10.  
  11. public class MockMatchClass:IMath
  12.     {
  13.         public MockMatchClass()
  14.         {
  15.             Value = 0.0;
  16.         }
  17.  
  18.         public double Value { get; set; }
  19.  
  20.         public int ReturnAbsValue(double i)
  21.         {
  22.             this.Value = Math.Abs(i);
  23.             return (int)this.Value;
  24.         }
  25.  
  26.         public int ReturnFloorValue(double i)
  27.         {
  28.         this.Value = Math.Floor(i);
  29.             return (int)this.Value;
  30.     }
  31.    }
  32.  
  33. using System;
  34. using Moq;
  35. using NUnit.Framework;
  36.  
  37. public class HackTests
  38. {
  39.    public  Mock<MockMatchClass> mockMatchClass;
  40.  
  41.     [SetUp]
  42.     public void Create_Mock_Math_Object()
  43.     {
  44.        
  45.         mockMatchClass=new Mock<MockMatchClass>();
  46.        
  47.     }
  48.  
  49.     [TestCase(-5.55)]
  50.     [TestCase(66.11)]
  51.     public void Get_The_Abs_Value(double num)
  52.     {  
  53.         MockMatchClass absClass = mockMatchClass.Object;
  54.        
  55.  
  56.         int someAbsResult = absClass.ReturnAbsValue(num);    
  57.         int fixedAbsValue=(int)Math.Abs(num);
  58.        
  59.         Assert.That(someAbsResult ==fixedAbsValue);
  60.     }
  61.  
  62.     [TestCase(4.55)]
  63.     [TestCase(99.12)]
  64.     public void Get_The_Floor_Value(double num)
  65.     {      
  66.         MockMatchClass floorValuesClass = mockMatchClass.Object;
  67.  
  68.         int someFloorResult = floorValuesClass.ReturnAbsValue(num);
  69.         int fixedFloorValue = (int)Math.Floor(num);
  70.  
  71.         Assert.That(someFloorResult==fixedFloorValue);
  72.     }
  73.    
  74. }
Add Comment
Please, Sign In to add comment