1
1
import unittest
2
+ import numpy as np
2
3
3
4
from urh .ainterpretation import AutoInterpretation
4
5
5
-
6
6
class TestAutoInterpretation (unittest .TestCase ):
7
+ def __run_merge (self , data ):
8
+ return list (AutoInterpretation .merge_plateau_lengths (np .array (data , dtype = np .uint64 )))
9
+
7
10
def test_merge_plateau_lengths (self ):
8
11
self .assertEqual (AutoInterpretation .merge_plateau_lengths ([]), [])
9
12
self .assertEqual (AutoInterpretation .merge_plateau_lengths ([42 ]), [42 ])
10
13
self .assertEqual (AutoInterpretation .merge_plateau_lengths ([100 , 100 , 100 ]), [100 , 100 , 100 ])
11
- self .assertEqual (AutoInterpretation .merge_plateau_lengths ([100 , 49 , 1 , 50 , 100 ]), [100 , 100 , 100 ])
12
- self .assertEqual (AutoInterpretation .merge_plateau_lengths ([100 , 48 , 2 , 50 , 100 ]), [100 , 100 , 100 ])
13
- self .assertEqual (AutoInterpretation .merge_plateau_lengths ([100 , 100 , 67 , 1 , 10 , 1 , 21 ]), [100 , 100 , 100 ])
14
- self .assertEqual (AutoInterpretation .merge_plateau_lengths ([100 , 100 , 67 , 1 , 10 , 1 , 21 , 100 , 50 , 1 , 49 ]),
15
- [100 , 100 , 100 , 100 , 100 ])
14
+ self .assertEqual (self .__run_merge ([100 , 49 , 1 , 50 , 100 ]), [100 , 100 , 100 ])
15
+ self .assertEqual (self .__run_merge ([100 , 48 , 2 , 50 , 100 ]), [100 , 100 , 100 ])
16
+ self .assertEqual (self .__run_merge ([100 , 100 , 67 , 1 , 10 , 1 , 21 ]), [100 , 100 , 100 ])
17
+ self .assertEqual (self .__run_merge ([100 , 100 , 67 , 1 , 10 , 1 , 21 , 100 , 50 , 1 , 49 ]), [100 , 100 , 100 , 100 , 100 ])
16
18
17
19
def test_estimate_tolerance_from_plateau_lengths (self ):
18
20
self .assertEqual (AutoInterpretation .estimate_tolerance_from_plateau_lengths ([]), None )
@@ -34,19 +36,19 @@ def test_tolerant_greatest_common_divisor(self):
34
36
def test_get_bit_length_from_plateau_length (self ):
35
37
self .assertEqual (AutoInterpretation .get_bit_length_from_plateau_lengths ([]), 0 )
36
38
self .assertEqual (AutoInterpretation .get_bit_length_from_plateau_lengths ([42 ]), 42 )
37
- plateau_lengths = [2 , 1 , 2 , 73 , 1 , 26 , 100 , 40 , 1 , 59 , 100 , 47 , 1 , 52 , 67 , 1 , 10 , 1 , 21 , 33 , 1 , 66 , 100 , 5 , 1 , 3 , 1 , 48 , 1 , 27 , 1 , 8 ]
39
+ plateau_lengths = np . array ( [2 , 1 , 2 , 73 , 1 , 26 , 100 , 40 , 1 , 59 , 100 , 47 , 1 , 52 , 67 , 1 , 10 , 1 , 21 , 33 , 1 , 66 , 100 , 5 , 1 , 3 , 1 , 48 , 1 , 27 , 1 , 8 ], dtype = np . uint64 )
38
40
merged_lengths = AutoInterpretation .merge_plateau_lengths (plateau_lengths )
39
41
self .assertEqual (AutoInterpretation .get_bit_length_from_plateau_lengths (merged_lengths ), 100 )
40
42
41
43
42
- plateau_lengths = [1 , 292 , 331 , 606 , 647 , 286 , 645 , 291 , 334 , 601 , 339 , 601 , 338 , 602 , 337 , 603 , 338 , 604 , 336 , 605 , 337 , 600 , 338 , 605 , 646 ]
44
+ plateau_lengths = np . array ( [1 , 292 , 331 , 606 , 647 , 286 , 645 , 291 , 334 , 601 , 339 , 601 , 338 , 602 , 337 , 603 , 338 , 604 , 336 , 605 , 337 , 600 , 338 , 605 , 646 ], dtype = np . uint64 )
43
45
merged_lengths = AutoInterpretation .merge_plateau_lengths (plateau_lengths )
44
46
self .assertEqual (AutoInterpretation .get_bit_length_from_plateau_lengths (merged_lengths ), 300 )
45
47
46
- plateau_lengths = [3 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 16 , 8 , 8 , 16 , 32 , 8 , 8 , 8 , 8 , 8 , 24 , 8 , 24 , 8 , 24 , 8 , 24 , 8 , 24 , 16 , 16 , 24 , 8 ]
48
+ plateau_lengths = np . array ( [3 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 16 , 8 , 8 , 16 , 32 , 8 , 8 , 8 , 8 , 8 , 24 , 8 , 24 , 8 , 24 , 8 , 24 , 8 , 24 , 16 , 16 , 24 , 8 ], dtype = np . uint64 )
47
49
merged_lengths = AutoInterpretation .merge_plateau_lengths (plateau_lengths )
48
50
self .assertEqual (AutoInterpretation .get_bit_length_from_plateau_lengths (merged_lengths ), 8 )
49
51
50
52
def test_get_bit_length_from_merged_plateau_lengths (self ):
51
- merged_lengths = [40 , 40 , 40 , 40 , 40 , 30 , 50 , 30 , 90 , 40 , 40 , 80 , 160 , 30 , 50 , 30 ]
53
+ merged_lengths = np . array ( [40 , 40 , 40 , 40 , 40 , 30 , 50 , 30 , 90 , 40 , 40 , 80 , 160 , 30 , 50 , 30 ], dtype = np . uint64 )
52
54
self .assertEqual (AutoInterpretation .get_bit_length_from_plateau_lengths (merged_lengths ), 40 )
0 commit comments