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); }
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); }
public static void Run() { Fibonacci.Draw(20); int number = 6; long fact = Factorial.Calculate(number); WriteLine($"\nFactorial of {number} is {fact}"); number = 371; WriteLine($"{number} is{(ArmstrongNumber.Find(number) ? "" : " NOT")} Armstrong Number"); }
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); }
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); }
private void Bgw_DoWork(object sender, DoWorkEventArgs e) { myFact = new Factorial(); BigInteger result = myFact.Calculate((int)e.Argument); if (myFact.CancelCalculate) { e.Cancel = true; } e.Result = result; }
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); }
public void CalculateFactorialSmalNumber() { //Arrage var expect = 6; var number = 3; Factorial factorial = new Factorial(); //Act var result = factorial.Calculate(number); //Assert Assert.Equal(expect, result); }
public static void GetsFactorialExceptionForNonPositiveNumbers( [Random(-1000, -1, 10, Distinct = true)] int input) { // Arrange // Act void Act() => Factorial.Calculate(input); // Assert _ = Assert.Throws <ArgumentException>(Act); }
public void BugFactorial21() { // Arrangement int number = 21; BigInteger expectedValue = BigInteger.Parse("51090942171709440000"); Factorial myFact = new Factorial(); // Action BigInteger currentValue = myFact.Calculate(number); // Assert Assert.AreEqual(expectedValue, currentValue); }
public void Test_GetEveryUniquePermutation(string word) { var permutations = Permutation.GetEveryUniquePermutation(word); // We need to make sure that // 1. We have the right number of permutations // 2. Every string in permutations List is a permutation of word // 3. There are no repetitions // Start 1. // The number of unique permutations is // n!/(A1! * A2! * ... An!) // where n is the length of word and Ai is the number of occurrences if ith char in the string var charOccurrence = new Dictionary <char, int>(); foreach (var c in word) { if (charOccurrence.ContainsKey(c)) { charOccurrence[c] += 1; } else { charOccurrence[c] = 1; } } // now we know the values of A1, A2, ..., An // evaluate the above formula var expectedNumberOfAnagrams = Factorial.Calculate(word.Length); expectedNumberOfAnagrams = charOccurrence.Aggregate(expectedNumberOfAnagrams, (current, keyValuePair) => { return(current / Factorial.Calculate(keyValuePair.Value)); }); Assert.AreEqual(expectedNumberOfAnagrams, permutations.Count); // End 1. // Start 2 // string A is a permutation of string B if and only if sorted(A) == sorted(b) var wordSorted = SortString(word); foreach (var permutation in permutations) { Assert.AreEqual(wordSorted, SortString(permutation)); } // End 2 // Start 3 Assert.AreEqual(permutations.Count, new HashSet <string>(permutations).Count); // End 3 }
public void NumberLessThanOneFactorialIsOne() { //Arrange var NumberUnderTestZero = 0; var NumberUnderTestOne = 0; //Act var resultZero = Factorial.Calculate(NumberUnderTestZero); var resultOne = Factorial.Calculate(NumberUnderTestOne); //Assert Assert.AreEqual(1, resultZero, "The factorial for 0 is not 1"); Assert.AreEqual(1, resultOne, "The factorial for 1 is not 1"); }
public override object Run(RunModes runMode, object input, bool Logging) { var sum = 0; for (int i = 3; i < 1000000; i++) { if (i == 145) { sum += 0; } if (i.ToString().Select(item => Factorial.Calculate(Int32.Parse(item.ToString()))).Sum() == i) { sum += i; } } return(sum); }
/// <summary> /// Single term for cos(x) function approximation: (-1)^i * x^(2*i) / (2*i)!. /// </summary> /// <param name="x">Given point.</param> /// <param name="i">Term index from 0 to n.</param> /// <returns>Single term value.</returns> private static double CosTerm(double x, int i) => Math.Pow(-1, i) / Factorial.Calculate(2 * i) * Math.Pow(x, 2 * i);
/// <summary> /// Single term for e^x function approximation: x^i / i!. /// </summary> /// <param name="x">Given point.</param> /// <param name="i">Term index from 0 to n.</param> /// <returns>Single term value.</returns> private static double ExpTerm(double x, int i) => Math.Pow(x, i) / Factorial.Calculate(i);
public void FactorialTestsByNegative() { var calculator = new Factorial(); var result = calculator.Calculate(-4); }
/// <summary> /// Single term for sin(x) function approximation: (-1)^i * x^(2*i + 1) / (2*i + 1)!. /// </summary> /// <param name="x">Given point.</param> /// <param name="i">Term index from 0 to n.</param> /// <returns>Single term value.</returns> private static double SinTerm(double x, int i) => (Math.Pow(-1, i) / Factorial.Calculate(2 * i + 1)) * Math.Pow(x, 2 * i + 1);
public void ShouldThrowFactorialException() { var result = Factorial.Calculate(NegativeInteger); }
public void ShouldCalculateFactorial() { var result = Factorial.Calculate(ZeroInteger); Assert.AreEqual(1, result); }
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Console.WriteLine(Factorial.Calculate(n)); }
public void ShouldCalculateFractorial() { var result = Factorial.Calculate(PositiveInteger); Assert.AreEqual(5040, result); }
public static string Process(string input1, string input2, string input3) { string output = string.Empty; switch (input3) { case "add": output = Addition.Add(input1, input2).ToString(); break; case "subtraction": output = Subtraction.Sub(input1, input2).ToString(); break; case "multiplication": output = Multiplication.Mul(input1, input2).ToString(); break; case "division": output = Division.Div(input1, input2).ToString(); break; case "divby3notby6": output = Divisionbythreenotbysix.Run(input1).ToString(); break; case "armstrongornot": output = Armstrongnumber.Check(input1).ToString(); break; case "factorial": output = Factorial.Calculate(input1).ToString(); break; case "palindrome": output = PalindromeNumber.Find(input1).ToString(); break; case "reverse": output = ReverseNumber.Reverse(input1).ToString(); break; case "sumofdigits": output = Sumofdigits.Find(input1).ToString(); break; case "decimaltobinary": output = DecimaltoBinary.Converts(input1).ToString(); break; case "numberincharacter": output = NumbersInCharacters.Print(input1).ToString(); break; case "strreverse": output = StringReverse.Reverse(input1).ToString(); break; case "duplicate": output = DuplicateElement.Find(input1).ToString(); break; case "unique": output = UniqueElement.Return(input1).ToString(); break; case "strpalindrome": output = StringPalindrome.Find(input1).ToString(); break; case "length": output = StringLength.Calculate(input1).ToString(); break; case "vowels": output = NumofVowels.Print(input1).ToString(); break; case "search": output = CharacterSearching.Search(input1, input2).ToString(); break; case "count": output = WordCount.Count(input1).ToString(); break; case "date": output = DateandTime.Calculate(input1).ToString(); break; } return(output); }