mirror of
https://bitbucket.org/Mattrixwv/csclasses.git
synced 2025-12-06 18:23:58 -05:00
Added function to get factorial of number
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
//C#/CSClasses/TestCSClasses/TestAlgorithms.cs
|
||||
//Matthew Ellison
|
||||
// Created: 03-11-21
|
||||
//Modified: 03-11-21
|
||||
//Modified: 06-01-21
|
||||
//This file contains the tests for the Algorithms class
|
||||
/*
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
Copyright (C) 2021 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -300,5 +300,35 @@ namespace TestCSClasses{
|
||||
answer = mee.Algorithms.FindNumOccurrence(testString, testChar);
|
||||
Assert.AreEqual(correctAnswer, answer, "FindNumOccurrence 3 failed");
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestFactorial(){
|
||||
//Test 1
|
||||
int num = 1;
|
||||
int correctAnswer = 1;
|
||||
int answer = mee.Algorithms.Factorial(num);
|
||||
Assert.AreEqual(correctAnswer, answer, "Factorial 1 failed");
|
||||
//Test 2
|
||||
num = 10;
|
||||
correctAnswer = 3628800;
|
||||
answer = mee.Algorithms.Factorial(num);
|
||||
Assert.AreEqual(correctAnswer, answer, "Factorial 2 failed");
|
||||
//Test 3
|
||||
num = -5;
|
||||
correctAnswer = 1;
|
||||
answer = mee.Algorithms.Factorial(num);
|
||||
Assert.AreEqual(correctAnswer, answer, "Factorial 3 failed");
|
||||
|
||||
//Test 4
|
||||
long numLong = 10;
|
||||
long correctAnswerLong = 3628800;
|
||||
long answerLong = mee.Algorithms.Factorial(numLong);
|
||||
Assert.AreEqual(correctAnswerLong, answerLong, "Factorial 4 failed");
|
||||
|
||||
//Test 5
|
||||
BigInteger numBig = 10;
|
||||
BigInteger correctAnswerBig = 3628800;
|
||||
BigInteger answerBig = mee.Algorithms.Factorial(numBig);
|
||||
Assert.AreEqual(correctAnswerBig, answerBig, "Factorial 5 failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user