@@ -1139,7 +1139,127 @@ TYPED_TEST(Data, Test) {
11391139template <typename Param> class Modifiers : public BasicTest <Param> {};
11401140TYPED_TEST_SUITE (Modifiers, AllTypes);
11411141
1142- TYPED_TEST (Modifiers, Insert) {
1142+ TYPED_TEST (Modifiers, InsertSingleConstRef) {
1143+ // constexpr iterator insert(const_iterator position, const T& x);
1144+
1145+ using IV = TestFixture::IV;
1146+ using T = TestFixture::T;
1147+
1148+ IV device;
1149+ IV reference;
1150+
1151+ if (device.capacity () > 0 ) {
1152+ reference = this ->unique ();
1153+
1154+ auto res = device.insert (device.begin (), reference[0 ]);
1155+ EXPECT_EQ (res, device.begin ());
1156+ EXPECT_EQ (device, IV (reference.begin (), reference.begin () + 1 ));
1157+
1158+ if (device.capacity () > 1 ) {
1159+ res = device.insert (device.end (), reference.back ());
1160+ EXPECT_EQ (res, device.end () - 1 );
1161+ EXPECT_EQ (device, IV ({reference[0 ], reference.back ()}));
1162+
1163+ for (auto i = 1ul ; i < (reference.size () - 1 ); ++i) {
1164+ res = device.insert (device.end () - 1 , reference[i]);
1165+ EXPECT_EQ (res, device.begin () + i);
1166+
1167+ IV correct (reference.begin (), reference.begin () + i + 1 );
1168+ correct.push_back (reference.back ());
1169+
1170+ EXPECT_EQ (device, correct);
1171+ }
1172+ }
1173+ }
1174+
1175+ T val{272 };
1176+ EXPECT_THROW (device.insert (device.begin (), val), beman::bad_alloc);
1177+ EXPECT_EQ (device, reference);
1178+
1179+ EXPECT_THROW (device.insert (device.begin (), val), beman::bad_alloc);
1180+ EXPECT_EQ (device, reference);
1181+ }
1182+
1183+ TYPED_TEST (Modifiers, InsertSingleRV) {
1184+ // constexpr iterator insert(const_iterator position, T&& x);
1185+
1186+ using IV = TestFixture::IV;
1187+ using T = TestFixture::T;
1188+
1189+ IV device;
1190+ IV reference;
1191+
1192+ if (device.capacity () > 0 ) {
1193+ reference = this ->unique ();
1194+
1195+ auto res = device.insert (device.begin (), T{reference[0 ]});
1196+ EXPECT_EQ (res, device.begin ());
1197+ EXPECT_EQ (device, IV (reference.begin (), reference.begin () + 1 ));
1198+
1199+ if (device.capacity () > 1 ) {
1200+ res = device.insert (device.end (), T{reference.back ()});
1201+ EXPECT_EQ (res, device.end () - 1 );
1202+ EXPECT_EQ (device, IV ({reference[0 ], reference.back ()}));
1203+
1204+ for (auto i = 1ul ; i < (reference.size () - 1 ); ++i) {
1205+ res = device.insert (device.end () - 1 , T{reference[i]});
1206+ EXPECT_EQ (res, device.begin () + i);
1207+
1208+ IV correct (reference.begin (), reference.begin () + i + 1 );
1209+ correct.push_back (reference.back ());
1210+
1211+ EXPECT_EQ (device, correct);
1212+ }
1213+ }
1214+ }
1215+
1216+ EXPECT_THROW (device.insert (device.begin (), T{272 }), beman::bad_alloc);
1217+ EXPECT_EQ (device, reference);
1218+
1219+ EXPECT_THROW (device.insert (device.begin (), T{272 }), beman::bad_alloc);
1220+ EXPECT_EQ (device, reference);
1221+ }
1222+
1223+ TYPED_TEST (Modifiers, InsertEmplace) {
1224+ // constexpr iterator emplace(const_iterator position, Args&&... args);
1225+
1226+ using IV = TestFixture::IV;
1227+
1228+ IV device;
1229+ IV reference;
1230+
1231+ if (device.capacity () > 0 ) {
1232+ reference = this ->unique ();
1233+
1234+ auto res = device.emplace (device.begin (), reference[0 ].value );
1235+ EXPECT_EQ (res, device.begin ());
1236+ EXPECT_EQ (device, IV (reference.begin (), reference.begin () + 1 ));
1237+
1238+ if (device.capacity () > 1 ) {
1239+ res = device.emplace (device.end (), reference.back ().value );
1240+ EXPECT_EQ (res, device.end () - 1 );
1241+ EXPECT_EQ (device, IV ({reference[0 ], reference.back ()}));
1242+
1243+ for (auto i = 1ul ; i < (reference.size () - 1 ); ++i) {
1244+ res = device.emplace (device.end () - 1 , reference[i].value );
1245+ EXPECT_EQ (res, device.begin () + i);
1246+
1247+ IV correct (reference.begin (), reference.begin () + i + 1 );
1248+ correct.push_back (reference.back ());
1249+
1250+ EXPECT_EQ (device, correct);
1251+ }
1252+ }
1253+ }
1254+
1255+ EXPECT_THROW (device.emplace (device.begin (), 272 ), beman::bad_alloc);
1256+ EXPECT_EQ (device, reference);
1257+
1258+ EXPECT_THROW (device.emplace (device.begin (), 272 ), beman::bad_alloc);
1259+ EXPECT_EQ (device, reference);
1260+ }
1261+
1262+ TYPED_TEST (Modifiers, InsertMulti) {
11431263 // constexpr iterator insert(const_iterator position, const T& x);
11441264 // constexpr iterator insert(const_iterator position, T&& x);
11451265 // constexpr iterator insert(const_iterator position, size_type n, const T&
@@ -1165,8 +1285,28 @@ TYPED_TEST(Modifiers, Insert) {
11651285 // exception is thrown, then size() ≥ n and elements in the range begin() +
11661286 // [0, n) are not modified.
11671287
1168- // TODO
1169- GTEST_SKIP ();
1288+ using IV = TestFixture::IV;
1289+
1290+ IV device;
1291+
1292+ if (device.capacity () > 0 ) {
1293+ auto duplicate = this ->unique (1 )[0 ];
1294+ IV reference (device.capacity (), duplicate);
1295+
1296+ if (device.capacity () > 1 ) {
1297+ auto front = this ->unique (1 )[0 ];
1298+ reference[0 ] = front;
1299+ device.push_back (front);
1300+ }
1301+
1302+ auto num_fill = device.capacity () - device.size ();
1303+ device.insert (device.end (), num_fill, duplicate);
1304+
1305+ EXPECT_EQ (device, IV (reference.begin (), reference.end ()));
1306+ }
1307+
1308+ EXPECT_NO_THROW (device.insert (device.begin (), 0 , {2538 }));
1309+ EXPECT_THROW (device.insert (device.begin (), 1 , {2538 }), beman::bad_alloc);
11701310}
11711311
11721312TYPED_TEST (Modifiers, PushBackConstRef) {
0 commit comments