Created
April 28, 2020 16:03
-
-
Save informz/98dc4bbd2a8b1b1d6338b43226c65096 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalatest.Matchers._ | |
import org.scalatest.FlatSpec | |
/* | |
Implement the mean, median, mode and range methods in Java 8 Functional style with the minimum code necessary to pass the tests. | |
*/ | |
class FunctionalTestSpec extends FlatSpec { | |
"A Range " should "have a value of 14" in { | |
assert(14 === range(3, 17, 15, 11, 9)) | |
} | |
// range: the difference between min and max values | |
def range(input: Seq[Int]): Double = ??? | |
"A Mean " should "have a value of 12.5" in { | |
assert(12.5 === mean(13, 19, null, 14, 16, 5, 8), 0) | |
} | |
// mean: the average of the numbers | |
def mean(input: Seq[Int]): Double = ??? | |
"A median " should "have a value of 6, 13.5" in { | |
assert(6 === median(7, 11, 6, 2, 5)) | |
assert(13.5 === median(13, 18, 14, 16, 5, 8)) | |
} | |
// median: the middle number in a sorted list - if there are two middle values, return the average of the two | |
def median(input: Seq[Int]): Double = ??? | |
"A mode " should "have a value of 3, [3, 5]" in { | |
Array(3) shouldBe mode(5, 2, 3, 6, 4, 1, 3) | |
Array(3, 5) shouldBe mode(4, 5, 3, 1, 3, 2, 5, 6) | |
} | |
// mode: the most commonly occurring number(s) | |
def mode(input: Seq[Int]): Double = ??? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment