anchor.diff:          Keys::[{?RT:key(), OldExists::boolean()}], Note::string()) -> true.
   check_keys_in_deleted(DB, ChangesInterval, Keys, Note) ->
       {_ChangedEntries, DeletedKeys} = ?TEST_DB:get_changes(DB),
  -    [begin
  -         case intervals:in(Key, ChangesInterval) andalso OldExists of
  -             true ->
  -                 case length([K || K <- DeletedKeys, K =:= Key]) of
  -                     1 -> ok;
  -                     _ -> ?ct_fail("element(2, ?TEST_DB:get_changes(DB)) evaluated "
  -                                   "to \"~w\" and did not contain 1x key ~w~n(~s)~n",
  -                                   [DeletedKeys, Key, lists:flatten(Note)])
  -                 end;
  -             _    -> true
  -         end
  -     end || {Key, OldExists} <- Keys],
  -    true.
  +    [check_key_in_deleted_internal(DeletedKeys, ChangesInterval, Key, OldExists, Note)
  +    || {Key, OldExists} <- Keys],
  +    true.
  +
  +-spec check_key_in_deleted_internal(
  +        DeletedKeys::intervals:interval(), ChangesInterval::intervals:interval(),
  +        Key::?RT:key(), OldExists::boolean(), Note::string()) -> true.
  +check_key_in_deleted_internal(DeletedKeys, ChangesInterval, Key, OldExists, Note) ->
  +    case intervals:in(Key, ChangesInterval) andalso OldExists of
  +        true ->
  +            case length([K || K <- DeletedKeys, K =:= Key]) of
  +                1 -> ok;
  +                _ -> ?ct_fail("element(2, ?TEST_DB:get_changes(DB)) evaluated "
  +                              "to \"~w\" and did not contain 1x key ~w~n(~s)~n",
  +                              [DeletedKeys, Key, lists:flatten(Note)])
  +            end;
  +        _    -> true
  +    end.
   
   %% @doc Checks that an entry is present exactly once in the list of changed
   %%      entries returned by ?TEST_DB:get_changes/1.
  --spec check_entry_in_changes(
  +-spec check_entry_in_changed_entries(
           DB::?TEST_DB:db(), ChangesInterval::intervals:interval(), Entry::db_entry:entry(),
           {OldExists::boolean(), OldEntry::db_entry:entry()}, Note::string()) -> ok.
  -check_entry_in_changes(DB, ChangesInterval, NewEntry, {_OldExists, OldEntry}, Note) ->
  -    case intervals:in(db_entry:get_key(NewEntry), ChangesInterval) andalso 
  +check_entry_in_changed_entries(DB, ChangesInterval, NewEntry, {_OldExists, OldEntry}, Note) ->
  +    {ChangedEntries, _DeletedKeys} = ?TEST_DB:get_changes(DB),
  +    check_entry_in_changed_entries_internal(ChangedEntries, ChangesInterval, NewEntry, OldEntry, Note).
  +
  +-spec check_entry_in_changed_entries_internal(
  +        ChangedEntries::?TEST_DB:db_as_list(), ChangesInterval::intervals:interval(),
  +        NewEntry::db_entry:entry(), OldEntry::db_entry:entry(), Note::string()) -> ok.
  +check_entry_in_changed_entries_internal(ChangedEntries, ChangesInterval, NewEntry, OldEntry, Note) ->
  +    case intervals:in(db_entry:get_key(NewEntry), ChangesInterval) andalso
                OldEntry =/= NewEntry of
           true ->
  -            {ChangedEntries, _DeletedKeys} = ?TEST_DB:get_changes(DB),
               case length([E || E <- ChangedEntries, E =:= NewEntry]) of
                   1 -> ok;
                   _ -> ?ct_fail("~s evaluated to \"~w\" and did not contain 1x entry ~w~n(~s)~n",
  
positive.code:     
      {DB4, _Status} = ?TEST_DB:delete(DB3, Key),
      check_changes(DB4, ChangesInterval, "delete_1"),
      check_key_in_deleted(DB4, ChangesInterval, Key, Old, "delete_2"),
      
      DB5 = check_stop_record_changes(DB4, ChangesInterval, "delete_3"),
  
  
negative.code:     DBEntry2 = create_db_entry(db_entry:get_key(DBEntry1), Value2, WriteLock2, ReadLock2, Version2),
      DB = ?TEST_DB:new(),
      DB2 = ?TEST_DB:set_entry(DB, DBEntry1),
      case db_entry:is_null(DBEntry1) of
          true -> % update not possible
              DB3 = DB2,
              ok; 
          false ->
              DB3 = ?TEST_DB:update_entry(DB2, DBEntry2),
              IsNullEntry = db_entry:is_null(DBEntry2),
              check_entry(DB3, db_entry:get_key(DBEntry2), DBEntry2,
                          {ok, db_entry:get_value(DBEntry2), db_entry:get_version(DBEntry2)},
                          not IsNullEntry, "check_entry_update_entry_1"),
              case not db_entry:is_empty(DBEntry2) andalso
                       not (db_entry:get_writelock(DBEntry2) andalso db_entry:get_readlock(DBEntry2) > 0) andalso
                       db_entry:get_version(DBEntry2) >= 0 of
                  true -> check_db(DB3, {true, []}, 1, [DBEntry2], "check_db_update_entry_0");
                  _ when IsNullEntry ->
                      check_db(DB3, {true, []}, 0, [], "check_db_update_entry_1");
                  _    -> check_db(DB3, {false, [DBEntry2]}, 1, [DBEntry2], "check_db_update_entry_2")
              end
      end,
      ?TEST_DB:close(DB3),
      true.
  