def test_huffman_encode_decode_reverse(): initial = 'A man, a plan, a canal, Panama' huffman = Huffman(initial) message = initial encoded = huffman.encode(message) decoded = huffman.decode(encoded) assert message == decoded message = 'nana' encoded = huffman.encode(message) decoded = huffman.decode(encoded) assert message == decoded
if (args['compression'] == 'h' and args['dictionary'] == 'g'): if (args['verbose']): print('Dumping huffman-dictionary to file...') try: f = open('./'+args['output']+'.huff', 'wb') pickle.dump(coder.omega, f) except Exception: print('Error while writing huffman-dictionary to file!') quit() # We need to uncompress elif (args['uncompression'] != None): if (args['verbose']): print('Coding-Mode is set to UN-COMPRESSION!') print('Uncompressing data...') outputData = coder.decode(inputData) # WRITE TO OUTPUT FILE # ===================== if (args['verbose']): print('Writing output to file...') try: f = open("./"+args['output'], "w+") try: f.writelines(outputData) finally: f.close() except IOError: print('Error wile writing to output file!') quit()
print('Testground EPR_05') print('Welchen Aufgabenteil moechten Sie testen?'); print('[1|2|3]'); which = input(">> ") ######### AUFGABE 5.2 TESTS ######### if (which == "3"): from huffman import Huffman Huff = Huffman() Huff.buildOwn = True print('Geben Sie einen Text zum codieren ein!'); text = input('>> '); encoded = Huff.encode(text) print(encoded) print('Dekodiert:') print(Huff.decode(encoded)) Huff.verbose() ######### AUFGABE 5.2 TESTS ######### if (which == "2"): from rle import RunLenghtEncoding rle = RunLenghtEncoding(); print('Geben Sie einen Text zum codieren ein!'); text = input('>> '); res = rle.encode(text) print("Der Komprimierte Text lautet:") print(res) print("Der Rück-Kodierte Text lautet:")
from huffman import Huffman if __name__ == '__main__': input_path = 'input.txt' output_path = 'output.txt' huff = Huffman() encoded, root = huff.encode(input_path) huff.decode(encoded, root, output_path)