new tests
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@9684 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
2566f7a20c
commit
235853099f
|
@ -0,0 +1,4 @@
|
|||
bug908.scala:8: error: not found: value makeA
|
||||
this(makeA)
|
||||
^
|
||||
one error found
|
|
@ -0,0 +1,11 @@
|
|||
abstract class A[T <% Ordered[T]] {
|
||||
def makeA = new Object
|
||||
// case object default extends Object
|
||||
}
|
||||
|
||||
class C[T <% Ordered[T]](foo: Object) extends A[T] {
|
||||
def this() = {
|
||||
this(makeA)
|
||||
// this(default)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
bug909.scala:6: error: type mismatch;
|
||||
found : java.lang.String("Hello")
|
||||
required: scala.Int
|
||||
case Foo("Hello") =>
|
||||
^
|
||||
one error found
|
|
@ -0,0 +1,9 @@
|
|||
case class Foo(x:Int)
|
||||
|
||||
object Bar {
|
||||
def main(args:Array[String]) {
|
||||
Foo(2) match {
|
||||
case Foo("Hello") =>
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
***** mutable.HashSet:
|
||||
test1: 14005
|
||||
test2: 25005003, iters = 5000
|
||||
test3: 25005003
|
||||
***** immutable.Set:
|
||||
test1: 14005
|
||||
test2: 25005003, iters = 5000
|
||||
test3: 25005003
|
||||
***** immutable.ListSet:
|
||||
test1: 14005
|
||||
test2: 25005003, iters = 5000
|
||||
test3: 25005003
|
||||
***** immutable.TreeSet:
|
||||
test1: 14005
|
||||
test2: 25005003, iters = 5000
|
||||
test3: 25005003
|
||||
***** mutable.HashMap:
|
||||
test1: 14005
|
||||
test2: 25005003, iters = 5000
|
||||
test3: 25005003
|
||||
***** immutable.Map:
|
||||
test1: 14005
|
||||
test2: 25005003, iters = 5000
|
||||
test3: 25005003
|
||||
test4: 25005003
|
||||
***** immutable.TreeMap:
|
||||
test1: 14005
|
||||
test2: 25005003, iters = 5000
|
||||
test3: 25005003
|
||||
test4: 25005003
|
||||
***** immutable.ListMap:
|
||||
test1: 14005
|
||||
test2: 9007003, iters = 3000
|
||||
test3: 9007003
|
||||
***** immutable.UnBalancedTreeMap:
|
||||
test1: 14005
|
||||
test2: 1013003, iters = 1000
|
||||
test3: 1013003
|
|
@ -0,0 +1,116 @@
|
|||
import collection._
|
||||
|
||||
object Test extends Application {
|
||||
|
||||
val printTime = false
|
||||
|
||||
def sum[A](xs: Iterable[int]) = (0 /: xs)((x, y) => x + y)
|
||||
|
||||
def time(op: => unit): unit = {
|
||||
val start = System.currentTimeMillis;
|
||||
op
|
||||
if (printTime) Console.println(" time = "+(System.currentTimeMillis - start)+"ms")
|
||||
}
|
||||
|
||||
def test(msg: String, s0: collection.immutable.Set[int], iters: int) = {
|
||||
Console.println("***** "+msg+":")
|
||||
var s = s0
|
||||
s = s + 2
|
||||
s = s + (3, 4000, 10000)
|
||||
Console.println("test1: "+sum(s))
|
||||
time {
|
||||
s = s ++ (List.range(0, iters) map (2*))
|
||||
Console.println("test2: "+sum(s)+", iters = "+iters)
|
||||
}
|
||||
time {
|
||||
var x = 0
|
||||
for (val i <- (0 to 10000))
|
||||
if (s contains i) x = x + i
|
||||
Console.println("test3: "+x)
|
||||
}
|
||||
}
|
||||
|
||||
def test(msg: String, s0: collection.mutable.Set[int], iters: int) = {
|
||||
Console.println("***** "+msg+":")
|
||||
var s = s0
|
||||
s = s + 2
|
||||
s = s + (3, 4000, 10000)
|
||||
Console.println("test1: "+sum(s))
|
||||
time {
|
||||
s = s ++ (List.range(0, iters) map (2*))
|
||||
Console.println("test2: "+sum(s)+", iters = "+iters)
|
||||
}
|
||||
time {
|
||||
var x = 0
|
||||
for (val i <- (0 to 10000))
|
||||
if (s contains i) x = x + i
|
||||
Console.println("test3: "+x)
|
||||
}
|
||||
}
|
||||
|
||||
def test(msg: String, s0: collection.immutable.Map[int, int], iters: int) = {
|
||||
Console.println("***** "+msg+":")
|
||||
var s = s0
|
||||
s = s + (2 -> 2)
|
||||
s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000)
|
||||
Console.println("test1: "+sum(s map (._2)))
|
||||
time {
|
||||
s = s ++ (List.range(0, iters) map (x => x * 2 -> x * 2))
|
||||
Console.println("test2: "+sum(s map (._2))+", iters = "+iters)
|
||||
}
|
||||
time {
|
||||
var x = 0
|
||||
for (val i <- (0 to 10000))
|
||||
s get i match {
|
||||
case Some(i) => x = x + i
|
||||
case None =>
|
||||
}
|
||||
Console.println("test3: "+x)
|
||||
}
|
||||
if (iters == 5000) {
|
||||
time {
|
||||
var s1 = s
|
||||
var x = 0
|
||||
for (val i <- (0 to 10000)) {
|
||||
s get i match {
|
||||
case Some(i) => x = x + i
|
||||
case None =>
|
||||
}
|
||||
s1 = s1 + ((i + 10000) -> i)
|
||||
}
|
||||
Console.println("test4: "+x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def test(msg: String, s0: collection.mutable.Map[int, int], iters: int) = {
|
||||
Console.println("***** "+msg+":")
|
||||
var s = s0
|
||||
s = s + (2 -> 2)
|
||||
s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000)
|
||||
Console.println("test1: "+sum(s map (._2)))
|
||||
time {
|
||||
s = s ++ (List.range(0, iters) map (x => x * 2 -> x * 2))
|
||||
Console.println("test2: "+sum(s map (._2))+", iters = "+iters)
|
||||
}
|
||||
time {
|
||||
var x = 0
|
||||
for (val i <- (0 to 10000))
|
||||
s get i match {
|
||||
case Some(i) => x = x + i
|
||||
case None =>
|
||||
}
|
||||
Console.println("test3: "+x)
|
||||
}
|
||||
}
|
||||
|
||||
test("mutable.HashSet", new mutable.HashSet[int], 5000)
|
||||
test("immutable.Set", new immutable.HashSet[int], 5000)
|
||||
test("immutable.ListSet", new immutable.ListSet[int], 5000)
|
||||
test("immutable.TreeSet", new immutable.TreeSet[int], 5000)
|
||||
test("mutable.HashMap", new mutable.HashMap[int, int], 5000)
|
||||
test("immutable.Map", immutable.Map[int, int](), 5000)
|
||||
test("immutable.TreeMap", new immutable.TreeMap[int, int], 5000)
|
||||
test("immutable.ListMap", new immutable.ListMap[int, int], 3000)
|
||||
test("immutable.UnBalancedTreeMap", new immutable.UnbalancedTreeMap[int, int], 1000)
|
||||
}
|
Loading…
Reference in New Issue