Ejemplo n.º 1
0
        public void Problem1_FindTheBug()
        {
            var target = new Problem1();

            int x = 5;
            int y = 10;
            var pointStruct = new MutablePointStruct() { X = x, Y = y };
            var result = target.FindTheBug(pointStruct);

            Assert.AreEqual(x * 2, result.X);
            Assert.AreEqual(y * 2, result.Y);
            Assert.AreNotSame(pointStruct, result);
        }
Ejemplo n.º 2
0
        public void IsDivisibleBy_NumbersTest()
        {
            var target = new Problem1();
            Assert.IsTrue(target.IsDivisibleBy(6, 2));
            Assert.IsTrue(target.IsDivisibleBy(100, 5));
            Assert.IsTrue(target.IsDivisibleBy(999, 3));
            Assert.IsTrue(target.IsDivisibleBy(19371, 1));
            Assert.IsTrue(target.IsDivisibleBy(7, 1));
            Assert.IsTrue(target.IsDivisibleBy(0, 15));

            Assert.IsFalse(target.IsDivisibleBy(7, 9));
            Assert.IsFalse(target.IsDivisibleBy(1, 9));
            Assert.IsFalse(target.IsDivisibleBy(10, 100));
        }
Ejemplo n.º 3
0
        public void Problem1_PointStruct_SideAffecting()
        {
            // Instantiate the problem
            var target = new Problem1();

            // Set up the test
            int x = 5;
            int y = 10;
            var pointStruct = new MutablePointStruct() { X = x, Y = y };
            var result = target.DoubleTheTargetPointStruct(pointStruct);

            // Assert truths.
            Assert.AreEqual(x * 2, result.X);
            Assert.AreEqual(y * 2, result.Y);
        }
Ejemplo n.º 4
0
        public void Problem1_PointClass_SideAffecting()
        {
            // Instantiate the problem
            var target = new Problem1();

            // Set up the test
            int x = 5;
            int y = 10;
            var pointClass = new PointClass(x, y);
            target.DoubleTheTargetPointClass(pointClass);

            // Assert truths.
            Assert.IsNotNull(pointClass);
            Assert.AreEqual(x * 2, pointClass.X);
            Assert.AreEqual(y * 2, pointClass.Y);
        }
Ejemplo n.º 5
0
        public void Problem1_PointStruct_WithReturnValue()
        {
            // Instantiate the problem
            var target = new Problem1();

            // Set up the test
            int x = 5;
            int y = 10;
            var pointStruct = new PointStruct(x, y);
            var result = target.ReturnADoubledPointStruct(pointStruct);

            // Assert truths.
            Assert.IsNotNull(result);
            Assert.AreNotSame(result, pointStruct);
            Assert.AreEqual(x * 2, result.X);
            Assert.AreEqual(y * 2, result.Y);
        }
Ejemplo n.º 6
0
 public void IsPalindrome_NullArgument()
 {
     var target = new Problem1();
     target.IsPalindrome(null);
 }
Ejemplo n.º 7
0
 public void IsPalindrome_NotAPalindrome()
 {
     var target = new Problem1();
     Assert.IsFalse(target.IsPalindrome("hello world"));
 }
Ejemplo n.º 8
0
 public void IsPalindrome_EmptyStringIsAPalindrome()
 {
     var target = new Problem1();
     Assert.IsTrue(target.IsPalindrome(string.Empty));
 }
Ejemplo n.º 9
0
 public void IsDivisibleBy_ZeroAsDenominator()
 {
     var target = new Problem1();
     target.IsDivisibleBy(1, 0);
 }
Ejemplo n.º 10
0
 public void IsDivisibleBy_NegativeB()
 {
     var target = new Problem1();
     target.IsDivisibleBy(1, -3);
 }
Ejemplo n.º 11
0
 public void IsDivisibleBy_NegativeA()
 {
     var target = new Problem1();
     target.IsDivisibleBy(-1, 3);
 }
Ejemplo n.º 12
0
 public void Sum_PassZero()
 {
     var target = new Problem1();
     Assert.AreEqual(0, target.Sum(0));
 }
Ejemplo n.º 13
0
        public void Sum_PassValidNumber()
        {
            var target = new Problem1();
            Assert.AreEqual(15, target.Sum(5));
            Assert.AreEqual(1, target.Sum(1));

            // now for some fancy randomized testing.
            var random = new Random();

            // test three different random numbers between 1 and 10000.
            var x = random.Next(1, 10000);
            Assert.AreEqual((x * (x + 1)) / 2, target.Sum(x));
            x = random.Next(1, 10000);
            Assert.AreEqual((x * (x + 1)) / 2, target.Sum(x));
            x = random.Next(1, 10000);
            Assert.AreEqual((x * (x + 1)) / 2, target.Sum(x));
        }
Ejemplo n.º 14
0
 public void Sum_PassNegativeNumber()
 {
     var target = new Problem1();
     target.Sum(-3);
 }
Ejemplo n.º 15
0
 public void IsPalindrome_Palindromes()
 {
     var target = new Problem1();
     Assert.IsTrue(target.IsPalindrome("A man a plan a canal Panama"));
     Assert.IsTrue(target.IsPalindrome("Z"));
     Assert.IsTrue(target.IsPalindrome("A Toyotas a Toyota"));
     Assert.IsTrue(target.IsPalindrome("Go hang a salami Im a lasagna hog"));
     Assert.IsTrue(target.IsPalindrome("zzzxxyyayyxxzzz"));
 }