Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Solution._
- import cmpsci220._
- import cmpsci220.hw._
- import cmpsci220.hw.measurement._
- class TrivialTestSuite extends org.scalatest.FunSuite {
- test("The solution object must be defined") {
- val obj : cmpsci220.hw.measurement.MeasurementFunctions = Solution
- }
- test("the revOrder outputs") {
- val nums = Solution.revOrder(5)
- assert(nums === cmpsci220.List(5,4,3,2,1))
- }
- test("revOrder must output Empty() on 0 call") {
- val nums = revOrder(0)
- assert (nums === cmpsci220.Empty())
- }
- test("time function should return accurate ms") {
- val nums = Solution.time((n:Int) => Thread.sleep(n), 10)
- assert(nums === 10)
- }
- test("basic test of average time") {
- val nums = Solution.averageTime(10, (n:Int)=>Thread.sleep(n), 10)
- assert(nums === 10)
- }
- test("basic test of random ints") {
- val nums = Solution.randomInts(5)
- assert (cmpsci220.length(nums) === 5)
- }
- test("THIS TEST DALE") {
- val result = cmpsci220.hw.isMemberAllOrdLst(List(6,2,3,4,5), insertAllOrdLst(List(6,2,3,4,5)))
- assert(result === true)
- }
- /**
- * Calculates the average time needed to insert values into the set
- *
- * @param insertAll a function that inserts a list of values into an empty set
- * @param trials the number of trials to run
- * @param values the list of values to insert
- * @returns A pair (n, t), where n is the number of values and t is the
- * average time needed to insert all values, divided by the
- * number of values
- */
- def timeInsertAll[A](insertAll: List[Int] => A, trials: Int)(values: List[Int]): (Double, Double) = {
- val n = length(values).toDouble
- val t = averageTime(trials, insertAll, values)
- (n, t / n)
- }
- test("timing insertAllAVL on random input") {
- // You may need to tweak this data to suit your computer
- val data = map((x: Int) => randomInts(math.pow(2, x + 1).toInt), revOrder(16))
- val timing = map(timeInsertAll(insertAllAVL, 5), data)
- println(timing)
- }
- test("timing insertAllBST on ordered input") {
- // You may need to tweak this data to suit your computer
- val data = map((x: Int) => revOrder(math.pow(2, x + 1).toInt), revOrder(10))
- val timing = map(timeInsertAll(insertAllBST, 5), data)
- val line = linearRegression(timing)
- assert(line.rSquared >= 0.85)
- }
- def isNonZeroTime(pt: (Double, Double)): Boolean = pt._2 != 0
- test("timing insertAllAVL on ordered input") {
- // You may need to tweak this data to suit your computer
- val data = map((x: Int) => revOrder(math.pow(2, x + 1).toInt), revOrder(14))
- val timing = map(timeInsertAll(insertAllAVL, 5), data)
- // Remove points with 0 as the y-coordinate, so that log is defined
- val zeroesRemoved = filter(isNonZeroTime, timing)
- // Put the X-axis on a log scale, so that we can fit a line
- val logScaleX = map((xy: (Double, Double)) => (math.log(xy._1), xy._2), zeroesRemoved)
- val line = linearRegression(logScaleX)
- assert(line.rSquared >= 0.85)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement