     // Keep variables alive.
     _fixLifetime(s1)
     _fixLifetime(s2)
+  }
+}
+
+SetTestSuite.test("COW.Slow.UpdateWithDoesNotReallocate") {
+  do {
+    var s1 = getCOWSlowSet()
+    let identity1 = s1._rawIdentifier()
+
+    // Replace a redundant element.
+    s1.update(with: TestKeyTy(2020))
+    expectEqual(identity1, s1._rawIdentifier())
+
+    expectEqual(3, s1.count)
+    expectTrue(s1.contains(TestKeyTy(1010)))
+    expectTrue(s1.contains(TestKeyTy(2020)))
+    expectTrue(s1.contains(TestKeyTy(3030)))
+
+    // Update with new elements.
+    s1.update(with: TestKeyTy(4040))
+    s1.update(with: TestKeyTy(5050))
+    s1.update(with: TestKeyTy(6060))
+
+    expectEqual(identity1, s1._rawIdentifier())
+    expectEqual(6, s1.count)
+
+    // Keep variables alive.
+    _fixLifetime(s1)
   }
 
   do {

  expectTrue(s1.contains(4040))
}

SetTestSuite.test("replace") {
  // These are anagrams - they should amount to the same sets.
  var s1 = Set<TestKeyTy>([1010, 2020, 3030])


  }
}

SetTestSuite.test("BridgedFromObjC.Verbatim.UpdateWith") {
  do {
    var s = getBridgedVerbatimSet()
    let identity1 = s._rawIdentifier()
    expectTrue(isCocoaSet(s))

    expectFalse(s.contains(TestObjCKeyTy(2040)))
    s.update(with: TestObjCKeyTy(2040))

    let identity2 = s._rawIdentifier()
    expectNotEqual(identity1, identity2)
    expectTrue(isNativeSet(s))
    expectEqual(4, s.count)

    expectTrue(s.contains(TestObjCKeyTy(1010)))
    expectTrue(s.contains(TestObjCKeyTy(2020)))
    expectTrue(s.contains(TestObjCKeyTy(3030)))
    expectTrue(s.contains(TestObjCKeyTy(2040)))
  }
}

SetTestSuite.test("BridgedFromObjC.Nonverbatim.Insert") {
  do {
    var s = getBridgedNonverbatimSet()
    let identity1 = s._rawIdentifier()
    let count1 = s.count
    let capacity1 = s.capacity
    expectTrue(isNativeSet(s))

    expectFalse(s.contains(TestBridgedKeyTy(2040)))
    s.insert(TestObjCKeyTy(2040) as TestBridgedKeyTy)

    let identity2 = s._rawIdentifier()
    // Storage identity may or may not change depending on allocation behavior.
    // (s is eagerly bridged to a regular uniquely referenced native Set.)
    expectTrue((count1 < capacity1) == (identity1 == s._rawIdentifier()))

    expectTrue(isNativeSet(s))
    expectEqual(4, s.count)

    expectTrue(s.contains(TestBridgedKeyTy(1010)))
    expectTrue(s.contains(TestBridgedKeyTy(2020)))
    expectTrue(s.contains(TestBridgedKeyTy(3030)))
    expectTrue(s.contains(TestBridgedKeyTy(2040)))
  }
}

SetTestSuite.test("BridgedFromObjC.Nonverbatim.UpdateWith") {
  do {
    var s = getBridgedNonverbatimSet()
    let identity1 = s._rawIdentifier()
    let count1 = s.count
    let capacity1 = s.capacity
    expectTrue(isNativeSet(s))

    expectFalse(s.contains(TestBridgedKeyTy(2040)))
    s.update(with: TestObjCKeyTy(2040) as TestBridgedKeyTy)

    let identity2 = s._rawIdentifier()
    // Storage identity may or may not change depending on allocation behavior.
    // (s is eagerly bridged to a regular uniquely referenced native Set.)
    expectTrue((count1 < capacity1) == (identity1 == s._rawIdentifier()))

    expectTrue(isNativeSet(s))
    expectEqual(4, s.count)
