Skip to content

Commit 26b61ea

Browse files
author
Jarvis@LNMIIT
committed
Scala Implementation of Eulcidean Algorithm
1 parent 644fc83 commit 26b61ea

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
3+
4+
class EuclideanAlgorithm {
5+
6+
def calculateGCD(number1:Int, number2:Int): Int = {
7+
8+
if(number2 == 0) number1
9+
else
10+
calculateGCD(number2, number1%number2)
11+
}
12+
}
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
import org.scalatest.{Matchers, FunSuite}
4+
5+
class EuclideanAlgorithmTest extends FunSuite with Matchers {
6+
7+
test("Euclidean Algorithm should give") {
8+
val objectForEuclideanAlgorithm = new EuclideanAlgorithm
9+
10+
objectForEuclideanAlgorithm.calculateGCD(12,4) should be(4)
11+
objectForEuclideanAlgorithm.calculateGCD(8,2) should be(2)
12+
objectForEuclideanAlgorithm.calculateGCD(16,8) should be(8)
13+
}
14+
}

0 commit comments

Comments
 (0)