Example #1
0
    def test_code_4(self):
        code_length = 10
        code_distance = 5

        code_generator = CodeGenerator(code_length, code_distance)
        code_words = code_generator.generate_code()

        for word in code_words:
            self.assertEqual(word.get_length(), code_length)

        for i in range(0, len(code_words)):
            for j in range(i + 1, len(code_words)):
                word_distance = CodeWord.get_distance(code_words[i],
                                                      code_words[j])
                self.assertEqual(word_distance >= code_distance, True)
Example #2
0
 def valid_word(self, possible_word):
     for current_word in self.code_words:
         if CodeWord.get_distance(current_word,
                                  possible_word) < self.distance:
             return False
     return True
Example #3
0
 def word_generation(self):
     for number in range(pow(2, self.length)):
         binary_format = "{:0{}b}"
         binary_representation = binary_format.format(number, self.length)
         yield CodeWord(binary_representation)