def test_calculate_or(self): left_bit_array_string = '1010111111' right_bit_array_string = '00000111' view_model = BitArrayViewModel() left_bit_array = view_model.bit_array_from_string( left_bit_array_string) right_bit_array = view_model.bit_array_from_string( right_bit_array_string) result = left_bit_array | right_bit_array view_model.set_operation(Operation.OR) view_model.set_left_bit_array(left_bit_array_string) view_model.set_right_bit_array(right_bit_array_string) view_model.calculate() self.assertEqual(result, view_model.get_result())
def test_calculate_invert(self): right_bit_array_string = '00000111' view_model = BitArrayViewModel() right_bit_array = view_model.bit_array_from_string( right_bit_array_string) result = ~right_bit_array view_model.set_operation(Operation.INVERT) view_model.set_right_bit_array(right_bit_array_string) view_model.calculate() self.assertEqual(result, view_model.get_result())
def test_can_convert_from_string(self): string = '000011' bit_array = BitArrayViewModel.bit_array_from_string(string) self.assertTrue(isinstance(bit_array, BitArray))
def test_convert_from_string_returns_true_string(self): string = '00011110' bit_array = BitArrayViewModel.bit_array_from_string(string) print(bit_array.to_string()) self.assertEqual(bit_array.to_string(), string)
def test_can_not_convert_from_invalid_string(self): string = 'god_help_me' with self.assertRaises(ValueError): BitArrayViewModel.bit_array_from_string(string)
def test_convert_from_string_hold_true_length(self): string = '0000110011' bit_array = BitArrayViewModel.bit_array_from_string(string) self.assertEqual(bit_array.get_length(), len(string))