1from bandit
import BaseBandit
7 This is a fake child class.
9 Since Bandit is an abstract class, it can't be instantiated directly. So
10 it's methods can't be called, and therefore tested. So create a fake class
11 that defines the required methods in the simplist terms and use that
25class TestBaseBandit(unittest.TestCase):
27 Tests the base class that all bandits rely on. Since this is an abstract
28 class, it uses a simple inheriting class to allow testing of the
29 defined functionality.
34 Test that the bandit properly sets the number of arms. Any positive
35 integer is permitted and everything else is rejected. This mimics real
36 life where you can't have a non-natural number of arms. Zero is
37 explicitly excluded, since it makes the object trivial.
43 bandit.k, k, msg=
'Static bandit did not create the correct number of arms.')
45 for k
in (0, -1, 0.5,
'1',
'the',
None):
46 with self.assertRaises(ValueError, msg=
'Static bandit did not reject invalid k input.'):
A base class for the various bandit implementations.
This is a fake child class.
select(self, index)
The method to select one of the arms of the bandit.
__init__(self, k)
Initialize the object with a set number of arms.
trueValues(self)
Return the true reward values of the bandit.
test_instantiate_k(self)
Test that the bandit properly sets the number of arms.