-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtestSample.py
More file actions
47 lines (35 loc) · 993 Bytes
/
testSample.py
File metadata and controls
47 lines (35 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# encoding: utf-8
__title__ = "Arithmatic Coding test"
__author__ = "Waleed Yaser (waleedyaser95@gmail.com)"
__version__ = "1.0"
"""
Arithmatic Coding test
~~~~~~~~~~~~~~~~~~~~~~
A test code for implementing Arithmatic coding class.
require:
*python 2.7
"""
from Arithmatic import ArithmaticCoding
symbols = []
probs = []
# Extract data from the file
with file("test_data.txt") as dataFile:
for line in dataFile:
symbols.append(line.split(" ")[0])
probs.append(float(line.split(" ")[1]))
# New object from the class
ArthCode = ArithmaticCoding(symbols, probs, "$")
code = ArthCode.Compress("CAEE$") #Compress
word = ArthCode.Decompress(code) #Decompress
# Output results
print "Arithmatic Coding test:"
print "~~~~~~~~~~~~~~~~~~~~~~~"
print 'Compress "CAEE$"'
print "Result:", code
print "_______________________"
print
print "Decompress:", code
print "Result:", word
print
print "======================="