Advertisement
Guest User

Untitled

a guest
Jan 12th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.33 KB | None | 0 0
  1. package net.verdagon.vcompiler.carpenter
  2.  
  3. object TetrisTableGeneratorTests {
  4.   def generateRandomNums(numRandoms: Int): Set[Int] = {
  5.     var result: Set[Int] = Set();
  6.     while (result.size < numRandoms) {
  7.       result = result + (Math.random() * 2000000000).toInt;
  8.     }
  9.     result
  10.   }
  11.  
  12.   def main(args: Array[String]): Unit = {
  13.     (1 until 100).map(_ * 1000).foreach(i => {
  14.       val numTrials = 1000;
  15.       val results =
  16.         (0 until numTrials).map(j => {
  17.           val map = generateRandomNums(i).map(i => i -> i).toMap;
  18.           val table = new TetrisTableGenerator[Int, Int]().generateTetrisTable(map, key => key);
  19.           val space = table.topLevel.length + table.combinedBuckets.length
  20.           val fillRatio = (table.topLevel.count(_.nonEmpty) + table.combinedBuckets.count(_.nonEmpty)) * 1.0 / space;
  21.           (space, fillRatio)
  22.         });
  23.       val worstSpace = results.map(_._1).max * 1.0;
  24.       val averageSpace = results.map(_._1).sum * 1.0 / numTrials;
  25.       val worstFillRatio = results.map(_._2).min * 1.0;
  26.       val averageFillRatio = results.map(_._2).sum * 1.0 / numTrials;
  27.       println("For " + i + " elements, space " + averageSpace + " fill ratio " + averageFillRatio + " worst fill ratio " + worstFillRatio + " space cost " + averageSpace / i + " worst space cost " + worstSpace / i)
  28.     })
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement