File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
TechnitiumLibrary.UnitTests/TechnitiumLibrary.ByteTree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff 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 // ---------------------------
You can’t perform that action at this time.
0 commit comments