See On Github


Source Code

/* SCALA Implementation of Factorial of Small and Big Numbers.

  Though the corner cases are covered. But still if you find any additions to it,
  please do add a test for it.

  Any improvements/tests in the code is highly appreciated.
class Factorial {

 def computeFactorial(num : Int):String = {

    (2 to num).foldLeft(BigInt(1))(_*_).toString()
import org.scalatest.{Matchers, FunSuite}

class FactorialTest extends FunSuite with Matchers {

  test("Factorial should return") {
    val objectForFactorial = new Factorial

    objectForFactorial.computeFactorial(2) should be("2")
    objectForFactorial.computeFactorial(5) should be("120")
    objectForFactorial.computeFactorial(10) should be("3628800")
    objectForFactorial.computeFactorial(50) should be("30414093201713378043612608166064768844377641568960512000000000000")