@@ -242,6 +242,39 @@ func TestSuccessProbability(t *testing.T) {
242
242
})
243
243
}
244
244
245
+ // TestSmallScale tests that the probability formula works with small scale
246
+ // values.
247
+ func TestSmallScale (t * testing.T ) {
248
+ var (
249
+ // We use the smallest possible scale value together with a
250
+ // large capacity. This is an extreme form of a bimodal
251
+ // distribution.
252
+ scale lnwire.MilliSatoshi = 1
253
+ capacity lnwire.MilliSatoshi = 7e+09
254
+
255
+ // Success and failure amounts are chosen such that the expected
256
+ // balance must be somewhere in the middle of the channel, a
257
+ // value not expected when dealing with a bimodal distribution.
258
+ // In this case, the bimodal model fails to give good forecasts
259
+ // due to the numerics of the exponential functions, which get
260
+ // evaluated to exact zero floats.
261
+ successAmount lnwire.MilliSatoshi = 1.0e+09
262
+ failAmount lnwire.MilliSatoshi = 4.0e+09
263
+ )
264
+
265
+ estimator := BimodalEstimator {
266
+ BimodalConfig : BimodalConfig {BimodalScaleMsat : scale },
267
+ }
268
+
269
+ // An amount that's close to the success amount should have a very high
270
+ // probability.
271
+ amtCloseSuccess := successAmount + 1
272
+ _ , err := estimator .probabilityFormula (
273
+ capacity , successAmount , failAmount , amtCloseSuccess ,
274
+ )
275
+ require .ErrorContains (t , err , "normalization factor is zero" )
276
+ }
277
+
245
278
// TestIntegral tests certain limits of the probability distribution integral.
246
279
func TestIntegral (t * testing.T ) {
247
280
t .Parallel ()
0 commit comments