Ejemplo n.º 1
0
        public void Regp_Factorial()
        {
            program = Factorial.BuildSample();
            RunTest(program.Procedures.Values.Take(1));

            var sExp =
                #region Expected
                @"// fact
// Return size: 0
void fact()
fact_entry:
	def fp
	def r1
	def r3
	// succ:  l1
l1:
	r63_1 = fp
	r2_3 = r1
	r1_4 = 0x00000001
	cc_5 = cond(r2_3 - r1_4)
	branch Test(LE,cc_5) m_done
	// succ:  l2 m_done
l2:
	r63_12 = r63_1 - 0x00000004
	Mem13[r63_12:word32] = r2_3
	r1_14 = r2_3 - r1_4
	call fact (retsize: 0;)
		uses: cc_5,r1_14,r2_3,r3,r63_12
		defs: cc_19,r1_16,r2_17,r3_18,r63_15
	r2_20 = Mem13[r63_15:word32]
	r63_21 = r63_15 + 0x00000004
	r1_22 = r1_16 * r2_20
	// succ:  m_done
m_done:
	cc_7 = PHI(cc_5, cc_19)
	r3_8 = PHI(r3, r3_18)
	r2_9 = PHI(r2_3, r2_20)
	r63_10 = PHI(r63_1, r63_21)
	r1_11 = PHI(r1_4, r1_22)
	return
	// succ:  fact_exit
fact_exit:
	use cc_7
	use fp
	use r1_11
	use r2_9
	use r3_8
	use r63_10

fact:
    Preserved: fp
    Trashed:   Flags r1 r2 r3 r63
";

            #endregion
            AssertProgram(sExp, program.Procedures.Values.Take(1));
        }
Ejemplo n.º 2
0
        public void Run()
        {
            BigInteger bigInteger = Factorial.FactBig(100);
            String     s          = bigInteger.ToString();

            Int32 sum = s.Select(p => Convert.ToInt32(p.ToString())).Sum();

            Console.WriteLine(sum);
        }
Ejemplo n.º 3
0
 public void Factorial_OnNegativeInput_Throws()
 {
     //Arrange
     int input = -1;
     //Act
     int output = Factorial.FactorialBadExceptionless(input);
     //Assert
     //Assert je prázdný, protože v tomto testu zjištujěme vyjímku, která je uvedena v hlavičce.
 }
Ejemplo n.º 4
0
        public void Test()
        {
            int fact1 = Factorial.Recursive(5);
            int fact2 = Factorial.Iterator().ElementAt(5);
            int fact3 = Enumerable.Range(0, 6).Aggregate((acc, cur) => acc == 0 ? 1 : acc * cur);

            Assert.That(fact1, Is.EqualTo(120));
            Assert.That(fact2, Is.EqualTo(120));
            Assert.That(fact3, Is.EqualTo(120));
        }
Ejemplo n.º 5
0
        public static void GetsFactorial(int input, long expected)
        {
            // Arrange

            // Act
            var result = Factorial.Calculate(input);

            // Assert
            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 6
0
        public void Get_InputBulk_ReturnCorrect(int input, int expected)
        {
            var actual = Factorial.Get(input);

            // Xunit
            Assert.Equal(expected, actual);

            // FluentAssertions
            actual.Should().Be(expected);
        }
Ejemplo n.º 7
0
        public void FactorialTestLowInts(int value)
        {
            //Arrange
            var expected = (value == 2)? 2 : 1;
            //Act
            var result = Factorial.FBigInt(value);

            //Assert
            Assert.True(result == expected);
        }
Ejemplo n.º 8
0
        public void FiveFactorialIsOneHundredAndTwenty()
        {
            //Arrange
            var NumberUnderTestFive = 5;

            //Act
            var resultTwo = Factorial.Calculate(NumberUnderTestFive);

            //Assert
            Assert.AreEqual(120, resultTwo, "The factorial for 5 is not 120");
        }
Ejemplo n.º 9
0
        public void TwoFactorialIsTwo()
        {
            //Arrange
            var NumberUnderTestTwo = 2;

            //Act
            var resultTwo = Factorial.Calculate(NumberUnderTestTwo);

            //Assert
            Assert.AreEqual(2, resultTwo, "The factorial for 2 is not 2");
        }
        public void FactTest()
        {
            // Arrange
            int exp = 120;

            // Act
            var fact = new Factorial();

            // Assert
            Assert.AreEqual(exp, fact.Fact(5));
        }
Ejemplo n.º 11
0
        public void Factorial_OnGeneralInput_CompletesAndCorrect()
        {
            //Arrange
            int input          = 5;
            int expectedOutput = 120;
            //Act
            int output = Factorial.FactorialBadInfinite(input);

            //Assert
            Assert.AreEqual(expectedOutput, output);
        }
Ejemplo n.º 12
0
        public static void GetsFactorialExceptionForNonPositiveNumbers([Random(-1000, -1, 10, Distinct = true)] int input)
        {
            // Arrange

            // Act
            void Act() => Factorial.Calculate(input);

            // Assert

            _ = Assert.Throws <ArgumentException>(Act);
        }
Ejemplo n.º 13
0
        public void recursionTest()
        {
            Factorial     factorialTest = new Factorial();
            PrivateObject privateObj    = new PrivateObject(factorialTest);

            var result = privateObj.Invoke("recursion", factorialNumber);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Double));
            Assert.AreEqual(result, expectedResult);
        }
        public void Calculate_1_1()
        {
            //arrange
            var factorial = new Factorial();

            //action
            var result = factorial.Calculate(1);

            //assert
            Assert.AreEqual(1, result);
        }
Ejemplo n.º 15
0
        public void Dfa2_FactorialReg()
        {
            var program = Factorial.BuildSample();
            var dfa     = new DataFlowAnalysis(program, null, new FakeDecompilerEventListener());

            dfa.AnalyzeProgram2();
            var sExp =
                @"@@@";

            AssertProgram(sExp, program);
        }
Ejemplo n.º 16
0
        public void Factorial_OnGeneralInput_Correct()
        {
            //Arrange
            int input          = 5;
            int expectedOutput = 120;
            //Act
            int output = Factorial.FactorialGood(input);

            //Assert
            Assert.AreEqual(expectedOutput, output);
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            Console.WriteLine(" Enter numbers to calculate");
            int num = Convert.ToInt32(Console.ReadLine());

            Factorial f   = new Factorial();
            int       res = f.Fact(num);

            Console.WriteLine(" Factorial is " + res);
            Console.ReadKey();
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            Factorial fact_delegate = new Factorial(FactorialFunc);
            IAsyncResult result = fact_delegate.BeginInvoke(10, new AsyncCallback(CallBack), "Это параметр");

            Console.WriteLine("Можете что-то ввести:");
            Console.ReadLine();

            int fact = fact_delegate.EndInvoke(result);

            Console.WriteLine("Результат: {0}", fact);
        }
Ejemplo n.º 19
0
        public void TestFactorialSixNormalCase()
        {
            // Arrangement
            int       number        = 6;
            int       expectedValue = 720;
            Factorial myFact        = new Factorial();
            // Action
            BigInteger currentValue = myFact.Calculate(number);

            // Assert
            Assert.AreEqual(expectedValue, currentValue);
        }
Ejemplo n.º 20
0
        public void FactTest()
        {
            // arrange
            int par1 = 5;

            int result = 120;
            // act
            var actual = Factorial.Fact(par1);

            // assert
            Assert.AreEqual(result, actual);
        }
        public void Calculate_100()
        {
            //arrange
            var factorial = new Factorial();
            var parsed    = BigInteger.Parse("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000");

            //action
            var result = factorial.Calculate(100);

            //assert
            Assert.AreEqual(parsed, result);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Log p-value calculation from q_xy of the contingency table.
        /// </summary>
        /// <param name="q00"></param>
        /// <param name="q01"></param>
        /// <param name="q10"></param>
        /// <param name="q11"></param>
        /// <returns></returns>
        public static double GetLogFisherP(int q00, int q01, int q10, int q11)
        {
            int rowSum0 = q00 + q01;
            int rowSum1 = q10 + q11;
            int colSum0 = q00 + q10;
            int colSum1 = q01 + q11;
            int total   = rowSum0 + rowSum1;

            return(Factorial.LnValue(rowSum0) + Factorial.LnValue(rowSum1) + Factorial.LnValue(colSum0) +
                   Factorial.LnValue(colSum1) - Factorial.LnValue(q00) - Factorial.LnValue(q01) - Factorial.LnValue(q10) -
                   Factorial.LnValue(q11) - Factorial.LnValue(total));
        }
Ejemplo n.º 23
0
    static void Main()
    {
        //metodos estaticos son aquello que se puden llamar sin instanciar una clase, no pertenece a ningun objeto.
        //C# es de tipado fuerte
        //tipado estático es aquel, que en tiempo de ejecucion no se pude cambiar el tipo de dato de una variable
        int num = System.Convert.ToInt32(System.Console.ReadLine());

        int fac = Factorial.factorial(num);

        System.Console.WriteLine(fac);
        System.Console.ReadKey(true);
    }
Ejemplo n.º 24
0
        public void BugFactorial13()
        {
            // Arrangement
            int        number        = 13;
            BigInteger expectedValue = 6227020800;
            Factorial  myFact        = new Factorial();
            // Action
            BigInteger currentValue = myFact.Calculate(number);

            // Assert
            Assert.AreEqual(expectedValue, currentValue);
        }
Ejemplo n.º 25
0
        public void TestFactorial100()
        {
            // Arrangement
            int        number        = 100;
            BigInteger expectedValue = BigInteger.Parse("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000");
            Factorial  myFact        = new Factorial();
            // Action
            BigInteger currentValue = myFact.Calculate(number);

            // Assert
            Assert.AreEqual(expectedValue, currentValue);
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            Factorial    fact_delegate = new Factorial(FactorialFunc);
            IAsyncResult result        = fact_delegate.BeginInvoke(10, new AsyncCallback(CallBack), "Это параметр");

            Console.WriteLine("Можете что-то ввести:");
            Console.ReadLine();

            int fact = fact_delegate.EndInvoke(result);

            Console.WriteLine("Результат: {0}", fact);
        }
Ejemplo n.º 27
0
        public override double GetCDF(double x)
        {
            int    k      = (int)(System.Math.Floor(x));
            double sum    = 0;
            double lambda = mMean;

            for (int i = 0; i <= k; ++k)
            {
                sum += (System.Math.Pow(lambda, i) / Factorial.GetFactorial(i));
            }
            return(System.Math.Exp(-lambda) * sum);
        }
Ejemplo n.º 28
0
        public void TestFactorialZero()
        {
            // Arrangement
            int       number        = 0;
            int       expectedValue = 1;
            Factorial myFact        = new Factorial();
            // Action
            BigInteger currentValue = myFact.Calculate(number);

            // Assert
            Assert.AreEqual(expectedValue, currentValue);
        }
Ejemplo n.º 29
0
        private int findN(double aprox)
        {
            double aprVal = 1;
            int    n      = 0;

            while (aprVal > aprox)
            {
                aprVal = 1 * a / Factorial.factorial(n + 1);
                n++;
            }
            return(n);
        }
Ejemplo n.º 30
0
        public override int Run()
        {
            // n!means n × (n − 1) × ... × 3 × 2 × 1

            // For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
            // and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
            // Find the sum of the digits in the number 100!

            var result = Factorial.GetFactorial(100).ToString().Select(c => int.Parse(c.ToString())).Sum();

            return(result);
        }
Ejemplo n.º 31
0
        public void recursionDelegateTest()
        {
            Factorial factorialTest = new Factorial();

            factorialTest.recursionDelegate(factorialNumber);

            Assert.IsNotNull(factorialTest.resultRecursion);
            Assert.IsInstanceOfType(factorialTest.resultRecursion, typeof(String));

            Assert.IsNotNull(factorialTest.calculationTimeRecursion);
            Assert.IsInstanceOfType(factorialTest.calculationTimeRecursion, typeof(String));
        }
Ejemplo n.º 32
0
 public void Visit(Factorial fact)
 {
     fact.Operand.Accept(this);
     _instructions.Add(Instruction.Create(OpCodes.Call, _fact));
 }
Ejemplo n.º 33
0
 public void Visit(Factorial fact)
 {
     fact.Operand.Accept(this);
     _sb.Append("!");
 }
Ejemplo n.º 34
0
 public void Visit(Factorial fact)
 {
     fact.Operand.Accept(this);
     fact.Type = MustBeInt(string.Format("The operand of {0} must be integer", fact));
 }
Ejemplo n.º 35
0
 public void Visit(Factorial fact)
 {
     // Nothing to do here...
 }