@@ -1029,13 +1029,132 @@ In ``src/cpy/Object/cSeqObject.c``:
10291029 Tests
10301030--------------
10311031
1032- Tests are in ``tests/unit/test_c_seqobject.py `` which includes failure modes:
1032+ Tests are in ``tests/unit/test_c_seqobject.py `` which includes failure modes.
1033+ First setting a value:
10331034
10341035.. code-block :: python
10351036
10361037 from cPyExtPatt import cSeqObject
10371038
1038- pass
1039+ @pytest.mark.parametrize (
1040+ ' initial_sequence, index, value, expected' ,
1041+ (
1042+ (
1043+ [7 , 4 , 1 , ], 0 , 14 , [14 , 4 , 1 , ],
1044+ ),
1045+ (
1046+ [7 , 4 , 1 , ], - 1 , 14 , [7 , 4 , 14 , ],
1047+ ),
1048+ (
1049+ [7 , 4 , 1 , ], - 2 , 14 , [7 , 14 , 1 , ],
1050+ ),
1051+ (
1052+ [7 , 4 , 1 , ], - 3 , 14 , [14 , 4 , 1 , ],
1053+ ),
1054+ )
1055+ )
1056+ def test_SequenceLongObject_setitem (initial_sequence , index , value , expected ):
1057+ obj = cSeqObject.SequenceLongObject(initial_sequence)
1058+ obj[index] = value
1059+ assert list (obj) == expected
1060+
1061+
1062+ Setting a value with an out of range index:
1063+
1064+ .. code-block :: python
1065+
1066+ from cPyExtPatt import cSeqObject
1067+
1068+ @pytest.mark.parametrize (
1069+ ' initial_sequence, index, expected' ,
1070+ (
1071+ (
1072+ [7 , 4 , 1 , ], 3 , ' Index 3 is out of range for length 3' ,
1073+ ),
1074+ (
1075+ [7 , 4 , 1 , ], - 4 , ' Index -4 is out of range for length 3' ,
1076+ ),
1077+ )
1078+ )
1079+ def test_SequenceLongObject_setitem_raises (initial_sequence , index , expected ):
1080+ print ()
1081+ print (initial_sequence, index, expected)
1082+ obj = cSeqObject.SequenceLongObject(initial_sequence)
1083+ with pytest.raises(IndexError ) as err:
1084+ obj[index] = 100
1085+ print (list (obj))
1086+ assert err.value.args[0 ] == expected
1087+
1088+
1089+ Deleting a value:
1090+
1091+ .. code-block :: python
1092+
1093+ from cPyExtPatt import cSeqObject
1094+
1095+ @pytest.mark.parametrize (
1096+ ' initial_sequence, index, expected' ,
1097+ (
1098+ (
1099+ [7 , ], 0 , [],
1100+ ),
1101+ (
1102+ [7 , ], - 1 , [],
1103+ ),
1104+ (
1105+ [7 , 4 , 1 , ], 1 , [7 , 1 , ],
1106+ ),
1107+ (
1108+ [7 , 4 , ], 0 , [4 , ],
1109+ ),
1110+ (
1111+ [7 , 4 , 1 , ], - 1 , [7 , 4 , ],
1112+ ),
1113+ (
1114+ [7 , 4 , 1 , ], - 2 , [7 , 1 , ],
1115+ ),
1116+ (
1117+ [7 , 4 , 1 , ], - 3 , [4 , 1 , ],
1118+ ),
1119+ )
1120+ )
1121+ def test_SequenceLongObject_delitem (initial_sequence , index , expected ):
1122+ obj = cSeqObject.SequenceLongObject(initial_sequence)
1123+ del obj[index]
1124+ assert list (obj) == expected
1125+
1126+
1127+ Deleting a value with an out of range index:
1128+
1129+ .. code-block :: python
1130+
1131+ from cPyExtPatt import cSeqObject
1132+
1133+ @pytest.mark.parametrize (
1134+ ' initial_sequence, index, expected' ,
1135+ (
1136+ (
1137+ [], 0 , ' Index 0 is out of range for length 0' ,
1138+ ),
1139+ (
1140+ [], - 1 , ' Index -1 is out of range for length 0' ,
1141+ ),
1142+ (
1143+ [7 , ], 1 , ' Index 1 is out of range for length 1' ,
1144+ ),
1145+ (
1146+ [7 , ], - 3 , ' Index -3 is out of range for length 1' ,
1147+ ),
1148+ )
1149+ )
1150+ def test_SequenceLongObject_delitem_raises (initial_sequence , index , expected ):
1151+ print ()
1152+ print (initial_sequence, index, expected)
1153+ obj = cSeqObject.SequenceLongObject(initial_sequence)
1154+ print (list (obj))
1155+ with pytest.raises(IndexError ) as err:
1156+ del obj[index]
1157+ assert err.value.args[0 ] == expected
10391158
10401159
10411160
0 commit comments