@@ -15,6 +15,10 @@ const (
15
15
largeAmount = lnwire .MilliSatoshi (5_000_000_000 )
16
16
capacity = lnwire .MilliSatoshi (10_000_000_000 )
17
17
scale = lnwire .MilliSatoshi (400_000_000 )
18
+
19
+ // defaultTolerance is the default absolute tolerance for comparing
20
+ // probability calculations to expected values.
21
+ defaultTolerance = 0.001
18
22
)
19
23
20
24
// TestSuccessProbability tests that we get correct probability estimates for
@@ -25,7 +29,6 @@ func TestSuccessProbability(t *testing.T) {
25
29
tests := []struct {
26
30
name string
27
31
expectedProbability float64
28
- tolerance float64
29
32
successAmount lnwire.MilliSatoshi
30
33
failAmount lnwire.MilliSatoshi
31
34
amount lnwire.MilliSatoshi
@@ -78,7 +81,6 @@ func TestSuccessProbability(t *testing.T) {
78
81
failAmount : capacity ,
79
82
amount : smallAmount ,
80
83
expectedProbability : 0.684 ,
81
- tolerance : 0.001 ,
82
84
},
83
85
// If we had an unsettled success, we are sure we can send a
84
86
// lower amount.
@@ -110,7 +112,6 @@ func TestSuccessProbability(t *testing.T) {
110
112
failAmount : capacity ,
111
113
amount : smallAmount ,
112
114
expectedProbability : 0.851 ,
113
- tolerance : 0.001 ,
114
115
},
115
116
// If we had a large unsettled success before, we know we can
116
117
// send even larger payments with high probability.
@@ -122,7 +123,6 @@ func TestSuccessProbability(t *testing.T) {
122
123
failAmount : capacity ,
123
124
amount : largeAmount ,
124
125
expectedProbability : 0.998 ,
125
- tolerance : 0.001 ,
126
126
},
127
127
// If we had a failure before, we can't send with the fail
128
128
// amount.
@@ -151,7 +151,6 @@ func TestSuccessProbability(t *testing.T) {
151
151
failAmount : largeAmount ,
152
152
amount : smallAmount ,
153
153
expectedProbability : 0.368 ,
154
- tolerance : 0.001 ,
155
154
},
156
155
// From here on we deal with mixed previous successes and
157
156
// failures.
@@ -183,7 +182,6 @@ func TestSuccessProbability(t *testing.T) {
183
182
successAmount : smallAmount ,
184
183
amount : smallAmount + largeAmount / 10 ,
185
184
expectedProbability : 0.287 ,
186
- tolerance : 0.001 ,
187
185
},
188
186
// We still can't send the fail amount.
189
187
{
@@ -228,7 +226,7 @@ func TestSuccessProbability(t *testing.T) {
228
226
test .failAmount , test .amount ,
229
227
)
230
228
require .InDelta (t , test .expectedProbability , p ,
231
- test . tolerance )
229
+ defaultTolerance )
232
230
require .NoError (t , err )
233
231
})
234
232
}
0 commit comments