def test_get(self): bitfield = FeaturesBitField(9) eq_(bitfield.get(0), False) bitfield.set(0, True) eq_(bitfield.get(0), True) eq_(bitfield.get(8), False) bitfield.set(8, True) eq_(bitfield.get(8), True)
def test_basic(self): bitfield = FeaturesBitField(8) eq_(bitfield.values, [0]) bitfield = FeaturesBitField(9) eq_(bitfield.values, [0, 0]) bitfield = FeaturesBitField(16) eq_(bitfield.values, [0, 0]) bitfield = FeaturesBitField(53) eq_(bitfield.values, [0, 0, 0, 0, 0, 0, 0])
def test_set(self): bitfield = FeaturesBitField(9) bitfield.set(0, True) eq_(bitfield.values, [1, 0]) bitfield.set(1, True) eq_(bitfield.values, [3, 0]) bitfield.set(8, True) eq_(bitfield.values, [3, 1])
def test_from_base64(self): bitfield = FeaturesBitField.from_base64('gQE=', len(self.test_data)) eq_(bitfield.to_list(), self.test_data) eq_(bitfield.to_base64(), 'gQE=')
def test_to_base64(self): bitfield = FeaturesBitField.from_list(self.test_data) eq_(bitfield.to_base64(), 'gQE=')
def test_from_list(self): bitfield = FeaturesBitField.from_list(self.test_data) eq_(bitfield.values, [129, 1]) eq_(bitfield.to_list(), self.test_data)
def test_to_list(self): bitfield = FeaturesBitField(9) bitfield.set(0, True) bitfield.set(7, True) bitfield.set(8, True) eq_(bitfield.to_list(), self.test_data)
def test_basic_values(self): bitfield = FeaturesBitField(8, values=[0, 1, 3]) eq_(bitfield.values, [0, 1, 3])
def test_from_base64_full_of_truth(self): bitfield = FeaturesBitField.from_base64('/wE=', len(self.test_data)) eq_(bitfield.to_list(), [True] * 9) eq_(bitfield.values, [255, 1]) eq_(bitfield.to_base64(), '/wE=')
def test_from_base64_full_of_lies(self): bitfield = FeaturesBitField.from_base64('AAA=', len(self.test_data)) eq_(bitfield.to_list(), [False] * 9) eq_(bitfield.values, [0, 0]) eq_(bitfield.to_base64(), 'AAA=')