len = 100;

for iter = 1:1000
    str = '';
    for i = 1:len
        if rand > 0.45
            str = [str 'A']; %#ok<AGROW>
        else
            str = [str 'B']; %#ok<AGROW>
        end
    end
% %     str = 'AAAAABBAAA';
% str = 'ABABBABCABBABBA';
% str = 'ABABBABCABABBA';
    [packed, dictionary, alphabet] = lzw_compress(str);
    [unpacked, utable] = lzw_decompress(packed, alphabet);
    unpacked = char(alphabet(unpacked));
    unpacked = unpacked(:)';
    
    if ~strcmp(str, unpacked)
        error('The decompressed output does not match the input.');
    end
end