def test_transform_raw_data_packets_to_sample(self): datas = [sample_packet(0), sample_packet(1), sample_packet(2)] parser = ParseRaw(gains=[24, 24, 24, 24, 24, 24, 24, 24]) samples = parser.transform_raw_data_packets_to_sample(datas) self.assertEqual(len(samples), len(datas)) for i in range(len(samples)): self.assertEqual(samples[i].sample_number, i)
def test_transform_raw_data_packet_to_sample_accel(self, mock_parse_packet_standard_accel): data = sample_packet(0) parser = ParseRaw() parser.transform_raw_data_packet_to_sample(data) mock_parse_packet_standard_accel.assert_called_once()
def test_get_data_array_accel(self): expected_sample_number = 0 data = sample_packet(expected_sample_number) parser = ParseRaw(gains=[24, 24, 24, 24, 24, 24, 24, 24], scaled_output=True) expected_accel_data = [] for i in range(Constants.RAW_PACKET_ACCEL_NUMBER_AXIS): expected_accel_data.append(Constants.CYTON_ACCEL_SCALE_FACTOR_GAIN * i) parser.raw_data_to_sample.raw_data_packet = data actual_accel_data = parser.get_data_array_accel(parser.raw_data_to_sample) self.assertListEqual(actual_accel_data, expected_accel_data)
def test_get_channel_data_array(self): expected_gains = [24, 24, 24, 24, 24, 24, 24, 24] expected_sample_number = 0 data = sample_packet(expected_sample_number) parser = ParseRaw(gains=expected_gains, scaled_output=True) scale_factors = parser.get_ads1299_scale_factors(expected_gains) expected_channel_data = [] for i in range(Constants.NUMBER_OF_CHANNELS_CYTON): expected_channel_data.append(scale_factors[i] * (i + 1)) parser.raw_data_to_sample.raw_data_packet = data actual_channel_data = parser.get_channel_data_array(parser.raw_data_to_sample) self.assertListEqual(actual_channel_data, expected_channel_data)
def test_parse_packet_standard_accel(self): data = sample_packet() expected_scale_factor = 4.5 / 24 / (pow(2, 23) - 1) parser = ParseRaw(gains=[24, 24, 24, 24, 24, 24, 24, 24], scaled_output=True) parser.raw_data_to_sample.raw_data_packet = data sample = parser.parse_packet_standard_accel(parser.raw_data_to_sample) self.assertIsNotNone(sample) for i in range(len(sample.channel_data)): self.assertEqual(sample.channel_data[i], expected_scale_factor * (i + 1)) for i in range(len(sample.accel_data)): self.assertEqual(sample.accel_data[i], Constants.CYTON_ACCEL_SCALE_FACTOR_GAIN * i) self.assertEqual(sample.packet_type, Constants.RAW_PACKET_TYPE_STANDARD_ACCEL) self.assertEqual(sample.sample_number, 0x45) self.assertEqual(sample.start_byte, 0xA0) self.assertEqual(sample.stop_byte, 0xC0) self.assertTrue(sample.valid)