-
Notifications
You must be signed in to change notification settings - Fork 96
/
JavaLibTest.scala
150 lines (130 loc) · 3.93 KB
/
JavaLibTest.scala
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package metascala
package full
import org.scalatest.FreeSpec
import metascala.Gen._
import java.math.BigInteger
import java.util.regex.{Matcher, Pattern}
import java.util.concurrent.atomic.{AtomicLong, AtomicInteger, AtomicBoolean}
import java.util.concurrent.{ConcurrentLinkedQueue, ConcurrentHashMap}
import java.util.concurrent.locks.ReentrantLock
class JavaLibTest extends FreeSpec {
implicit val intAll10 = 10 ** Gen.intAll
import Util._
"sudoku" in {
val tester = new Tester("metascala.full.Sudoku")
tester.run("run")
}
"stuff" - {
val tester = new VM()
"sorting" in tester.test{
val arr: Array[Int] = new Array[Int](250)
var current: Int = 94664704
for(i <- 0 until arr.length){
current = 23 * current % 100000000 + 1
arr(i) = current % 100000
}
java.util.Arrays.sort(arr)
arr(52)
}
"collections" in tester.test{
val vec = new java.util.Vector[Integer]()
for(i <- 0 until 10 ){
vec.add(i)
}
val map = new java.util.HashMap[Integer, String]()
var total = 0
for(i <- 0 until 10){
total = total + vec.get(i)
map.put(vec.get(i), ""+total)
}
Integer.parseInt(map.get(10/2))
}
"bigInteger" in tester.test{
val a: BigInteger = new BigInteger("1237923896771092385")
val b: BigInteger = new BigInteger("498658982734992345912340")
val c: BigInteger = new BigInteger("08968240235478367717203984123")
val d: BigInteger = a.add(b)
val e: BigInteger = d.subtract(c)
val f: BigInteger = e.multiply(b)
val g: BigInteger = f.divide(a)
g.toString
}
"regex" in tester.test{
val p: Pattern = Pattern.compile("\\d+([_-]\\d+)*(:? )")
val m: Matcher = p.matcher("123_321_12 i am a cow 123_3-" + "12_990 but my ip is 192-168-1-1 lolz")
var s: String = ""
while (m.find) {
s += m.group(0)
}
s
}
"atomicBooleans" in tester.test{
val b: AtomicBoolean = new AtomicBoolean
val values: Array[Boolean] = new Array[Boolean](4)
b.set(true)
values(0) = b.get
b.compareAndSet(false, false)
values(1) = b.get
values(2) = b.getAndSet(false)
b.compareAndSet(false, true)
values(3) = b.get
values
}
"atomicIntegers" in tester.test{
val b: AtomicInteger = new AtomicInteger
val values: Array[Int] = new Array[Int](4)
b.set(192)
values(0) = b.get
b.compareAndSet(12, 3123)
values(1) = b.get
values(2) = b.getAndSet(31241)
b.compareAndSet(31241, 12451)
values(3) = b.get
values
}
"atomicLongs" in tester.test{
val b: AtomicLong = new AtomicLong
val values: Array[Long] = new Array[Long](4)
b.set(1921231231234124124L)
values(0) = b.get
b.compareAndSet(12124124164865234L, 34934198359342123L)
values(1) = b.get
values(2) = b.getAndSet(98172271923198732L)
b.compareAndSet(981724127399231987L, 123517894187923123L)
values(3) = b.get
values
}
"randoms" in tester.test{
val r = new java.util.Random(241231241251241123L)
for(i <- 0 until 100){
r.nextLong()
}
r.nextLong()
}
"concurrentLinkedQueue" in tester.test{
val struct = new ConcurrentLinkedQueue[Int]()
struct.add(123)
struct.add(456)
val i = struct.poll()
struct.peek() + i + struct.peek()
}
"locks" in tester.test{
val lock = new ReentrantLock()
lock.lock()
lock.unlock()
}
"concurrentHashMap" in tester.test{
val map = new ConcurrentHashMap[Int, Int]()
map.put(123, 456)
}
// "rhino" in tester.test{
// classOf[VMBridge_jdk15].newInstance()
// /*val cx = Context.enter()
// val scope = cx.initStandardObjects()
// val script = "var s = 'omg'"
// val obj = cx.evaluateString(scope, script, "Test Script", 1, null)
// println(obj)
// 1*/
// }
}
}