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
|
// See LICENSE for license details.
package chiselTests
import chisel3._
import org.scalatest.{Matchers, FreeSpec}
class RangeSpec extends FreeSpec with Matchers {
"Ranges can be specified for UInt, SInt, and FixedPoint" - {
"to specify a UInt" in {
UInt(range"[0, 8)").getWidth should be (3)
UInt(range"[0, 8]").getWidth should be (4)
UInt(range"[0, 0]").getWidth should be (1)
}
"to specify an SInt" in {
SInt(range"[0, 8)").getWidth should be (4)
SInt(range"[0, 8]").getWidth should be (5)
SInt(range"[-4, 4)").getWidth should be (3)
SInt(range"[0, 0]").getWidth should be (1)
}
"it should check that the range is valid for UInt" in {
an [IllegalArgumentException] should be thrownBy {
UInt(range"[1, 0]")
}
an [IllegalArgumentException] should be thrownBy {
UInt(range"[-1, 1]")
}
an [IllegalArgumentException] should be thrownBy {
UInt(range"(0,0]")
}
an [IllegalArgumentException] should be thrownBy {
UInt(range"[0,0)")
}
an [IllegalArgumentException] should be thrownBy {
UInt(range"(0,0)")
}
}
"it should check that the range is valid for SInt" in {
an [IllegalArgumentException] should be thrownBy {
SInt(range"[1, 0]")
}
an [IllegalArgumentException] should be thrownBy {
SInt(range"(0,0]")
}
an [IllegalArgumentException] should be thrownBy {
SInt(range"[0,0)")
}
an [IllegalArgumentException] should be thrownBy {
SInt(range"(0,0)")
}
}
}
}
|