-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary.spec.wren
More file actions
44 lines (38 loc) · 1.56 KB
/
binary.spec.wren
File metadata and controls
44 lines (38 loc) · 1.56 KB
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
import "wren-assert/Assert" for Assert
import "./binary" for Decimal
Assert.aborts(
Fn.new { Decimal.new(-9007199254740992) },
"Decimal.new(_) accepts only integers >= `Num.minSafeInteger`."
)
Assert.aborts(
Fn.new { Decimal.new(9007199254740992) },
"Decimal.new(_) accepts only integers up to `Num.maxSafeInteger`."
)
Assert.doesNotAbort {
Assert.equal(Decimal.new(Num.minSafeInteger).num, Num.minSafeInteger)
Assert.equal(Decimal.new(Num.maxSafeInteger).num, Num.maxSafeInteger)
Assert.equal(Decimal.new(0).num, 0)
Assert.equal(Decimal.new(-340).significand, -340)
Assert.equal(Decimal.new(-340).exponent, 0)
}
Assert.doesNotAbort {
Assert.equal(Decimal.fromFloat32(0x0).num, 0)
}
Assert.doesNotAbort {
var sixAndChange = Decimal.fromNum(6.44562)
Assert.notEqual(sixAndChange.float32, 0x7F800000, "Float is infinite!")
// TODO: Use `Num.smallest` to check for "close enough" numbers
// FIXME: System.print("exponent: %(sixAndChange.exponent)")
// FIXME: System.print("significand: %(sixAndChange.significand)")
// FIXME: Assert.equal(sixAndChange.num, 6.44562)
// FIXME: Assert.equal(sixAndChange.float32, 0x40CE4285)
}
Assert.doesNotAbort {
Assert.equal(Decimal.fromFloat32(0x0).toString(16), "0x0")
Assert.equal(Decimal.fromFloat32(0).toString(16), "0x0")
Assert.equal(Decimal.new(1).toString(16), "0x1")
Assert.equal(Decimal.new(10).toString(16), "0xA")
Assert.equal(Decimal.new(20).toString(16), "0x14")
Assert.equal(Decimal.new(218).toString(16), "0xDA")
Assert.equal(Decimal.new(Num.maxSafeInteger).toString(16), "0x1FFFFFFFFFFFFF")
}