PowerCollections - 多词典“删除”未找到值时删除所有值
我正在使用 http://powercollections.codeplex.com/ 中的 powercollections 库
第一个测试通过了,但是第二次测试失败。如果找不到值,我不希望 Remove
从字典中删除所有项目。
这是一个问题还是我误解了 Remove
的功能?
[Test]
public void passing_test()
{
var classes = new MultiDictionary<string, object>(false);
classes.Add("class", "class_name1");
classes.Add("class", "class_name2");
classes.Remove("class", "class_name2");
Assert.AreEqual(1, classes.Count);
}
[Test]
public void failing_test()
{
var classes = new MultiDictionary<string, object>(false);
classes.Add("class", "class_name1");
classes.Remove("class", "class_name2");
Assert.AreEqual(1, classes.Count);
}
I am using the powercollections library from http://powercollections.codeplex.com/
The first test passes, however the second test fails. I wouldn't expect Remove
to remove all items from the dictionary if a value was not found.
Is this an issue or am I misunderstanding how Remove
functions ?
[Test]
public void passing_test()
{
var classes = new MultiDictionary<string, object>(false);
classes.Add("class", "class_name1");
classes.Add("class", "class_name2");
classes.Remove("class", "class_name2");
Assert.AreEqual(1, classes.Count);
}
[Test]
public void failing_test()
{
var classes = new MultiDictionary<string, object>(false);
classes.Add("class", "class_name1");
classes.Remove("class", "class_name2");
Assert.AreEqual(1, classes.Count);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它实际上看起来像代码中的一个错误:
注意到他们如何检查
existingCount == 1
吗?尽管您输入的值不同,但没有代码可以检查在hash.Delete
调用之前是否在搜索中找到了索引。解决此问题的正确方法是执行以下操作:这是完整的源代码: http ://powercollections.codeplex.com/SourceControl/changeset/view/6259#71508
It actually looks like a bug in the code:
Notice how they are checking for
existingCount == 1
? Although the values you entered differ, there is no code to check whether the index was found in the search prior to thehash.Delete
call. The correct way to fix this would be to do something like:Here's the full source: http://powercollections.codeplex.com/SourceControl/changeset/view/6259#71508