File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -238,10 +238,85 @@ def __str__(self) -> str:
238238 )
239239
240240
241+ # Tests to prove correctness of implementation
242+ def test_ppma_encode ():
243+ """
244+ Simple test for encode function of PPMA.
245+ """
246+ ppma = PPMA (max_order = 2 )
247+ encoded = ppma .encode_text ("ABBAABA" )
248+ assert encoded ["ranges" ] == [
249+ (0 , 1 , 1 ),
250+ (0 , 1 , 1 ),
251+ (0 , 1 , 1 ),
252+ (65 , 66 , 256 ),
253+ (0 , 1 , 1 ),
254+ (0 , 1 , 1 ),
255+ (1 , 2 , 2 ),
256+ (66 , 67 , 256 ),
257+ (0 , 1 , 1 ),
258+ (0 , 1 , 1 ),
259+ (1 , 2 , 3 ),
260+ (0 , 1 , 1 ),
261+ (1 , 2 , 2 ),
262+ (0 , 1 , 4 ),
263+ (0 , 1 , 1 ),
264+ (1 , 2 , 2 ),
265+ (0 , 2 , 5 ),
266+ (0 , 1 , 1 ),
267+ (1 , 2 , 3 ),
268+ (1 , 2 , 2 ),
269+ (0 , 1 , 3 ),
270+ ]
271+
272+
273+ def test_ppma_decode ():
274+ """
275+ Simple test for decode function of PPMA.
276+ """
277+ ppma = PPMA (max_order = 2 )
278+ decoded = ppma .decode_text (
279+ [
280+ (0 , 1 , 1 ),
281+ (0 , 1 , 1 ),
282+ (0 , 1 , 1 ),
283+ (65 , 66 , 256 ),
284+ (0 , 1 , 1 ),
285+ (0 , 1 , 1 ),
286+ (1 , 2 , 2 ),
287+ (66 , 67 , 256 ),
288+ (0 , 1 , 1 ),
289+ (0 , 1 , 1 ),
290+ (1 , 2 , 3 ),
291+ (0 , 1 , 1 ),
292+ (1 , 2 , 2 ),
293+ (0 , 1 , 4 ),
294+ (0 , 1 , 1 ),
295+ (1 , 2 , 2 ),
296+ (0 , 2 , 5 ),
297+ (0 , 1 , 1 ),
298+ (1 , 2 , 3 ),
299+ (1 , 2 , 2 ),
300+ (0 , 1 , 3 ),
301+ ]
302+ )
303+ assert decoded == "ABBAABA"
304+
305+
306+ def test_ppma_circular ():
307+ """
308+ Test for circular context in PPMA.
309+ """
310+ ppma = PPMA (max_order = 2 )
311+ encoded = ppma .encode_text ("ABBAABA" )
312+ decoded = ppma .decode_text (encoded ["ranges" ])
313+ assert decoded == "ABBAABA"
314+
315+
241316if __name__ == "__main__" :
242317 # Example usage
243318 ppma = PPMA (max_order = 2 )
244- text = "ABABAB "
319+ text = "ABBAABA "
245320 encoded = ppma .encode_text (text )
246321
247322 print ("Encoded output:" )
You can’t perform that action at this time.
0 commit comments