Skip to content

Commit 63238cf

Browse files
committed
Added GetOrAdd test cases
1 parent a6a0f2f commit 63238cf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

TechnitiumLibrary.UnitTests/TechnitiumLibrary.ByteTree/ByteTreeTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,35 @@ public void TryUpdate_ShouldReturnFalse_WhenKeyMissing()
210210
}
211211

212212

213+
// ---------------------------
214+
// GetOrAdd
215+
// ---------------------------
216+
217+
[TestMethod]
218+
public void GetOrAdd_ShouldReturnExistingValue_WhenKeyExists()
219+
{
220+
ByteTree<string> tree = new ByteTree<string>();
221+
tree.Add(Key(2, 2), "existing");
222+
string val = tree.GetOrAdd(Key(2, 2), "new");
223+
Assert.AreEqual("existing", val);
224+
}
225+
226+
[TestMethod]
227+
public void GetOrAdd_ShouldInsertAndReturnNewValue_WhenKeyMissing()
228+
{
229+
ByteTree<string> tree = new ByteTree<string>();
230+
string val = tree.GetOrAdd(Key(3, 3), "added");
231+
Assert.AreEqual("added", val);
232+
Assert.AreEqual("added", tree[Key(3, 3)]);
233+
}
234+
235+
[TestMethod]
236+
public void GetOrAdd_ShouldThrow_WhenNullKey()
237+
{
238+
ByteTree<string> tree = new ByteTree<string>();
239+
Assert.ThrowsExactly<ArgumentNullException>(() => tree.GetOrAdd(null, "x"));
240+
}
241+
213242
// ---------------------------
214243
// AddOrUpdate
215244
// ---------------------------

0 commit comments

Comments
 (0)