@@ -1052,6 +1052,49 @@ def test_setrange(self, r):
1052
1052
assert r .setrange ('a' , 6 , '12345' ) == 11
1053
1053
assert r ['a' ] == b'abcdef12345'
1054
1054
1055
+ @skip_if_server_version_lt ('6.0.0' )
1056
+ def test_stralgo_lcs (self , r ):
1057
+ key1 = 'key1'
1058
+ key2 = 'key2'
1059
+ value1 = 'ohmytext'
1060
+ value2 = 'mynewtext'
1061
+ res = 'mytext'
1062
+ # test LCS of strings
1063
+ assert r .stralgo ('LCS' , value1 , value2 ) == res
1064
+ # test using keys
1065
+ r .mset ({key1 : value1 , key2 : value2 })
1066
+ assert r .stralgo ('LCS' , key1 , key2 , specific_argument = "keys" ) == res
1067
+ # test other labels
1068
+ assert r .stralgo ('LCS' , value1 , value2 , len = True ) == len (res )
1069
+ assert r .stralgo ('LCS' , value1 , value2 , idx = True ) == \
1070
+ {
1071
+ 'len' : len (res ),
1072
+ 'matches' : [[(4 , 7 ), (5 , 8 )], [(2 , 3 ), (0 , 1 )]]
1073
+ }
1074
+ assert r .stralgo ('LCS' , value1 , value2 ,
1075
+ idx = True , withmatchlen = True ) == \
1076
+ {
1077
+ 'len' : len (res ),
1078
+ 'matches' : [[4 , (4 , 7 ), (5 , 8 )], [2 , (2 , 3 ), (0 , 1 )]]
1079
+ }
1080
+ assert r .stralgo ('LCS' , value1 , value2 ,
1081
+ idx = True , minmatchlen = 4 , withmatchlen = True ) == \
1082
+ {
1083
+ 'len' : len (res ),
1084
+ 'matches' : [[4 , (4 , 7 ), (5 , 8 )]]
1085
+ }
1086
+
1087
+ @skip_if_server_version_lt ('6.0.0' )
1088
+ def test_stralgo_negative (self , r ):
1089
+ with pytest .raises (exceptions .DataError ):
1090
+ r .stralgo ('ISSUB' , 'value1' , 'value2' )
1091
+ with pytest .raises (exceptions .DataError ):
1092
+ r .stralgo ('LCS' , 'value1' , 'value2' , len = True , idx = True )
1093
+ with pytest .raises (exceptions .DataError ):
1094
+ r .stralgo ('LCS' , 'value1' , 'value2' , specific_argument = "INT" )
1095
+ with pytest .raises (ValueError ):
1096
+ r .stralgo ('LCS' , 'value1' , 'value2' , idx = True , minmatchlen = "one" )
1097
+
1055
1098
def test_strlen (self , r ):
1056
1099
r ['a' ] = 'foo'
1057
1100
assert r .strlen ('a' ) == 3
0 commit comments