blob: 94f5ccc7728165b793f4c0a8cca35056cb8ff3b9 (
plain)
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
|
// SPDX-License-Identifier: Apache-2.0
package chiselTests
import chisel3._
import chisel3.experimental._
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
class ScalaIntervalSimulatorSpec extends AnyFreeSpec with Matchers {
"clip tests" - {
"Should work for closed ranges" in {
val sim = ScalaIntervalSimulator(range"[2,4]")
sim.clip(BigDecimal(1.0)) should be(2.0)
sim.clip(BigDecimal(2.0)) should be(2.0)
sim.clip(BigDecimal(3.0)) should be(3.0)
sim.clip(BigDecimal(4.0)) should be(4.0)
sim.clip(BigDecimal(5.0)) should be(4.0)
}
"Should work for closed ranges with binary point" in {
val sim = ScalaIntervalSimulator(range"[2,6].2")
sim.clip(BigDecimal(1.75)) should be(2.0)
sim.clip(BigDecimal(2.0)) should be(2.0)
sim.clip(BigDecimal(2.25)) should be(2.25)
sim.clip(BigDecimal(2.5)) should be(2.5)
sim.clip(BigDecimal(5.75)) should be(5.75)
sim.clip(BigDecimal(6.0)) should be(6.0)
sim.clip(BigDecimal(6.25)) should be(6.0)
sim.clip(BigDecimal(6.5)) should be(6.0)
sim.clip(BigDecimal(8.5)) should be(6.0)
}
"Should work for open ranges" in {
val sim = ScalaIntervalSimulator(range"(2,4)")
sim.clip(BigDecimal(1.0)) should be(3.0)
sim.clip(BigDecimal(2.0)) should be(3.0)
sim.clip(BigDecimal(3.0)) should be(3.0)
sim.clip(BigDecimal(4.0)) should be(3.0)
sim.clip(BigDecimal(5.0)) should be(3.0)
}
"Should work for open ranges with binary point" in {
val sim = ScalaIntervalSimulator(range"(2,6).2")
sim.clip(BigDecimal(1.75)) should be(2.25)
sim.clip(BigDecimal(2.0)) should be(2.25)
sim.clip(BigDecimal(2.25)) should be(2.25)
sim.clip(BigDecimal(2.5)) should be(2.5)
sim.clip(BigDecimal(5.75)) should be(5.75)
sim.clip(BigDecimal(6.0)) should be(5.75)
sim.clip(BigDecimal(6.25)) should be(5.75)
sim.clip(BigDecimal(6.5)) should be(5.75)
sim.clip(BigDecimal(8.5)) should be(5.75)
}
}
"wrap tests" - {
"Should work for closed ranges" in {
val sim = ScalaIntervalSimulator(range"[2,6]")
sim.wrap(BigDecimal(1.0)) should be(6.0)
sim.wrap(BigDecimal(2.0)) should be(2.0)
sim.wrap(BigDecimal(3.0)) should be(3.0)
sim.wrap(BigDecimal(4.0)) should be(4.0)
sim.wrap(BigDecimal(5.0)) should be(5.0)
sim.wrap(BigDecimal(6.0)) should be(6.0)
sim.wrap(BigDecimal(7.0)) should be(2.0)
}
"Should work for closed ranges with binary point" in {
val sim = ScalaIntervalSimulator(range"[2,6].2")
sim.wrap(BigDecimal(1.75)) should be(6.0)
sim.wrap(BigDecimal(2.0)) should be(2.0)
sim.wrap(BigDecimal(2.25)) should be(2.25)
sim.wrap(BigDecimal(2.5)) should be(2.5)
sim.wrap(BigDecimal(5.75)) should be(5.75)
sim.wrap(BigDecimal(6.0)) should be(6.0)
sim.wrap(BigDecimal(6.25)) should be(2.0)
sim.wrap(BigDecimal(6.5)) should be(2.25)
}
"Should work for open ranges" in {
val sim = ScalaIntervalSimulator(range"(2,6)")
sim.wrap(BigDecimal(1.0)) should be(4.0)
sim.wrap(BigDecimal(2.0)) should be(5.0)
sim.wrap(BigDecimal(3.0)) should be(3.0)
sim.wrap(BigDecimal(4.0)) should be(4.0)
sim.wrap(BigDecimal(5.0)) should be(5.0)
sim.wrap(BigDecimal(6.0)) should be(3.0)
sim.wrap(BigDecimal(7.0)) should be(4.0)
}
"Should work for open ranges with binary point" in {
val sim = ScalaIntervalSimulator(range"(2,6).2")
sim.wrap(BigDecimal(1.75)) should be(5.5)
sim.wrap(BigDecimal(2.0)) should be(5.75)
sim.wrap(BigDecimal(2.25)) should be(2.25)
sim.wrap(BigDecimal(2.5)) should be(2.5)
sim.wrap(BigDecimal(5.75)) should be(5.75)
sim.wrap(BigDecimal(6.0)) should be(2.25)
sim.wrap(BigDecimal(6.25)) should be(2.5)
sim.wrap(BigDecimal(7.0)) should be(3.25)
}
}
}
|