euclidean norm

See On Github



euclid, length

Source Code

/* SCALA Implementation of Euclidean Norm.
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.

import scala.math

class EuclideanNorm {

  def calculateEuclideanNorm(listofIntegers: List[Int]):Int = {

    val squaredElements = => x*x).sum
import org.scalatest.{Matchers, FunSuite}

class calculateEuclideanNormTest extends FunSuite with Matchers {

  test("Euclidean Norm should give") {
    val objectForEuclideanNorm = new EuclideanNorm

    objectForEuclideanNorm.calculateEuclideanNorm(List(1,2,3)) should be(3)
    objectForEuclideanNorm.calculateEuclideanNorm(List(3,4)) should be(5)
    objectForEuclideanNorm.calculateEuclideanNorm(List(1,1,1,1)) should be(2)