-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAboutLiteralNumbers.scala
69 lines (62 loc) · 1.62 KB
/
AboutLiteralNumbers.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
package org.functionalkoans.forscala
import org.scalatest.matchers.ShouldMatchers
import support.KoanSuite
class AboutLiteralNumbers extends KoanSuite with ShouldMatchers {
koan("Integer Literals are 32-bit and can be created from decimal, hexadecimal") {
val a = 2
val b = 31
val c = 0x30F
val e = 0
val f = -2
val g = -31
val h = -0x30F
a should be(2)
b should be(31)
c should be(783) //Hint: 30F = 783
e should be(0)
f should be(-2)
g should be(-31)
h should be(-783) //Hint: 30F = 783
}
koan("""Long Literals are 64 bit, are specified by appending an L or l at the end;
| l is rarely used since it looks like a 1""") {
val a = 2L
val b = 31L
val c = 0x30FL
val e = 0L
val f = -2l
val g = -31L
val h = -0x30FL
a should be(2)
b should be(31)
c should be(783) //Hint: 30F = 783
e should be(0)
f should be(-2)
g should be(-31)
h should be(-783) //Hint: 30F = 783
}
koan("""Float and Double Literals are IEEE 754 for specific,
| Float are 32-bit length, Doubles are 64-bit.
| Floats can be coerced using a f or F suffix, and
| Doubles can be coerced using a d or D suffix.
| Exponent are specified using e or E.""") {
val a = 3.0
val b = 3.00
val c = 2.73
val d = 3f
val e = 3.22d
val f = 93e-9
val g = 93E-9
val h = 0.0
val i = 9.23E-9D
a should be(3)
b should be(3)
c should be(2.73D)
d should be(3)
e should be(3.22)
f should be(93E-9)
g should be(93e-9)
h should be(0)
i should be(9.23e-9d)
}
}