From b97788c19cfcfc5386273e96f2333546d9f076cc Mon Sep 17 00:00:00 2001 From: Piromsurang Rungserichai Date: Sat, 1 Oct 2022 14:11:02 +0700 Subject: [PATCH] add pythagorean theorem and unit test --- src/main/scala/Mathematics/PythagoreanTheorem.scala | 9 +++++++++ .../scala/Mathematics/PythagoreanTheoremSpec.scala | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/scala/Mathematics/PythagoreanTheorem.scala create mode 100644 src/test/scala/Mathematics/PythagoreanTheoremSpec.scala diff --git a/src/main/scala/Mathematics/PythagoreanTheorem.scala b/src/main/scala/Mathematics/PythagoreanTheorem.scala new file mode 100644 index 0000000..40b1d98 --- /dev/null +++ b/src/main/scala/Mathematics/PythagoreanTheorem.scala @@ -0,0 +1,9 @@ +package Mathematics + +object PythagoreanTheorem { + + /** Returns two dimension distant */ + def distance(x: Double, y: Double): Double = { + Math.sqrt(Math.pow(x,2) + Math.pow(y,2)) + } +} \ No newline at end of file diff --git a/src/test/scala/Mathematics/PythagoreanTheoremSpec.scala b/src/test/scala/Mathematics/PythagoreanTheoremSpec.scala new file mode 100644 index 0000000..395ddf8 --- /dev/null +++ b/src/test/scala/Mathematics/PythagoreanTheoremSpec.scala @@ -0,0 +1,11 @@ +package Mathematics + +import org.scalatest.flatspec.AnyFlatSpec + +class PythagoreanTheoremSpec extends AnyFlatSpec { + + "Pythagorean Theorem 1" should "output the correct distant" in { + assert(PythagoreanTheorem.distance(3,4) === 5) + } + +} \ No newline at end of file