Beispiel #1
0
        public void SquareRoot_ValidValues_ReturnsExpected()
        {
            // arrange
            double a = 100;
            MathOperations m = new MathOperations();
            double expected = 10;
            double error = 0.1;

            // act
            double actual = m.SquareRoot(a, error);

            // assert
            Assert.IsTrue(Math.Abs(actual * actual - expected * expected) < error);
        }
Beispiel #2
0
        public void SquareRoot_RandomSamples_ReturnsValue()
        {
            Random r = new Random(1234);
            for (int i = 0; i < 100000; i++)
            {
                // arrange
                double a = r.NextDouble() * (i % 10);
                MathOperations m = new MathOperations();
                double expected = Math.Sqrt(a);
                double error = 0.001;

                // act
                double actual = m.SquareRoot(a, error);

                // assert
                Assert.IsTrue(Math.Abs(actual * actual - expected * expected) < error);
            }
        }