Skip to content

Commit a49142c

Browse files
jhoofwijkbasnijholt
authored andcommitted
add test for BalancingLearner edge case
1 parent c26ac92 commit a49142c

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from ..learner import Learner1D, BalancingLearner
4+
5+
6+
def test_balancing_learner_loss_cache():
7+
learner = Learner1D(lambda x: x, bounds=(-1, 1))
8+
learner.tell(-1, -1)
9+
learner.tell(1, 1)
10+
learner.tell_pending(0)
11+
12+
real_loss = learner.loss(real=True)
13+
pending_loss = learner.loss(real=False)
14+
15+
# Test if the real and pending loss are cached correctly
16+
bl = BalancingLearner([learner])
17+
assert bl.loss(real=True) == real_loss
18+
assert bl.loss(real=False) == pending_loss
19+
20+
# Test if everything is still fine when executed in the reverse order
21+
bl = BalancingLearner([learner])
22+
assert bl.loss(real=False) == pending_loss
23+
assert bl.loss(real=True) == real_loss

0 commit comments

Comments
 (0)