summaryrefslogtreecommitdiff
path: root/test/files/run/ctries-new/lnode.scala
blob: 4cc97050e54b60d5fc2b9d46befa2bf77848a473 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import collection.concurrent.TrieMap


object LNodeSpec extends Spec {

  val initsz = 1500
  val secondsz = 1750

  def test() {
    "accept elements with the same hash codes" in {
      val ct = new TrieMap[DumbHash, Int]
      for (i <- 0 until initsz) ct.update(new DumbHash(i), i)
    }

    "lookup elements with the same hash codes" in {
      val ct = new TrieMap[DumbHash, Int]
      for (i <- 0 until initsz) ct.update(new DumbHash(i), i)
      for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == Some(i))
      for (i <- initsz until secondsz) assert(ct.get(new DumbHash(i)) == None)
    }

    "remove elements with the same hash codes" in {
      val ct = new TrieMap[DumbHash, Int]
      for (i <- 0 until initsz) ct.update(new DumbHash(i), i)
      for (i <- 0 until initsz) {
        val remelem = ct.remove(new DumbHash(i))
        assert(remelem == Some(i), "removing " + i + " yields " + remelem)
      }
      for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == None)
    }

    "put elements with the same hash codes if absent" in {
      val ct = new TrieMap[DumbHash, Int]
      for (i <- 0 until initsz) ct.put(new DumbHash(i), i)
      for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i)
      for (i <- 0 until initsz) assert(ct.putIfAbsent(new DumbHash(i), i) == Some(i))
      for (i <- initsz until secondsz) assert(ct.putIfAbsent(new DumbHash(i), i) == None)
      for (i <- initsz until secondsz) assert(ct.lookup(new DumbHash(i)) == i)
    }

    "replace elements with the same hash codes" in {
      val ct = new TrieMap[DumbHash, Int]
      for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None)
      for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i)
      for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i) == Some(i))
      for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == -i)
      for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i, i) == true)
    }

    "remove elements with the same hash codes if mapped to a specific value" in {
      val ct = new TrieMap[DumbHash, Int]
      for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None)
      for (i <- 0 until initsz) assert(ct.remove(new DumbHash(i), i) == true)
    }

  }

}