private void BtnOpenCode_Click(object sender, EventArgs e) { if (_ofdSourceCode.ShowDialog() != DialogResult.OK) { return; } BtnShowFullSourceCode.Visible = false; try { var sourceCode = ArithmeticFile.Read(_ofdSourceCode.FileName); var decoded = ArithmeticCoding.Decode(sourceCode); _lastSaveSourceCode = sourceCode.ToString(); if (_lastSaveSourceCode.Length > MaxCodeLength) { BtnShowFullSourceCode.Visible = true; } LblSourceCode.Text = "Код: " + _lastSaveSourceCode; RtbDecoded.Text = decoded; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void TestEncodeWriteAndReadDecode() { const string source = "abcdefghklmopqastuvwxyz"; const string fileName = "test1.acode"; var fullPath = Path.Combine(GetTestFolder(), fileName); var encoded = ArithmeticCoding.Encode(source); ArithmeticFile.Write(fullPath, encoded); var read = ArithmeticFile.Read(fullPath); var decoded = ArithmeticCoding.Decode(read); Assert.AreEqual(source, decoded); }