def test_warnings_for_all_invalid_codes(self): invalid = [] for i in range(2 ** 12): valid = True bit_pattern = '{0:012b}'.format(i) with warnings.catch_warnings(record=True) as warns: code = int(bit_pattern, base=2) converted_alt = gillham(code) if converted_alt and converted_alt not in self.valid_alts: valid = False if bit_pattern not in self.valid_bits: if not valid: print("failed alts test {0}".format(converted_alt)) print("failed bits test {0}".format(bit_pattern)) valid = False if not valid and not warns: invalid.append(converted_alt) print("No warning for invalid alt: b:{0} g:{1}".format( bit_pattern, converted_alt) ) self.assertEqual(0, len(invalid))
def test_conversion_of_valid_codes(self): all_alts = [] for bits in self.valid_bits: code = int('0' + bits, base=2) g = gillham(code) all_alts.append(g) self.assertSequenceEqual(self.valid_alts, all_alts)
def _get_table(): gillham_codes = list(range(2048)) segment_codes = [] for i in gillham_codes: altitude = gillham(i) if altitude == -975: altitude = -1000 if altitude == -950: altitude == -900 if altitude: altitude /= 100 segment_codes.append(_altitude_to_7_segments(altitude)) return zip(gillham_codes, segment_codes)