@@ -160,4 +160,76 @@ public void testIteratorOrdered() throws Exception
160160 }
161161 assertFalse ("No more items" , iterator .hasNext ());
162162 }
163+
164+ public void testSizeOne () {
165+ IntervalTree <Integer , Interval <Integer >> tree = new IntervalTree <>();
166+ tree .add (Interval .toInterval (0 , 1 ));
167+ assertEquals (tree .size (), 1 );
168+ tree .remove (Interval .toInterval (0 , 1 ));
169+ assertEquals (tree .size (), 0 );
170+ }
171+
172+ public void testSizeTwoDeleteLeft () {
173+ IntervalTree <Integer , Interval <Integer >> tree = new IntervalTree <>();
174+ tree .add (Interval .toInterval (0 , 1 ));
175+ assertEquals (tree .size (), 1 );
176+
177+ tree .add (Interval .toInterval (2 , 5 ));
178+ assertEquals (tree .size (), 2 );
179+ assertEquals (tree .root ().maxEnd .intValue (), 5 );
180+
181+ tree .remove (Interval .toInterval (0 , 1 ));
182+ assertEquals (tree .size (), 1 );
183+ assertEquals (tree .root ().maxEnd .intValue (), 5 );
184+
185+ // new tree, insert in opposite order
186+ tree = new IntervalTree <>();
187+ tree .add (Interval .toInterval (2 , 5 ));
188+ assertEquals (tree .size (), 1 );
189+ assertEquals (tree .root ().maxEnd .intValue (), 5 );
190+
191+ tree .add (Interval .toInterval (0 , 1 ));
192+ assertEquals (tree .size (), 2 );
193+ assertEquals (tree .root ().maxEnd .intValue (), 5 );
194+
195+ tree .remove (Interval .toInterval (0 , 1 ));
196+ assertEquals (tree .size (), 1 );
197+ assertEquals (tree .root ().maxEnd .intValue (), 5 );
198+ }
199+
200+ public void testSizeTwoDeleteRight () {
201+ IntervalTree <Integer , Interval <Integer >> tree = new IntervalTree <>();
202+ tree .add (Interval .toInterval (0 , 1 ));
203+ assertEquals (tree .size (), 1 );
204+ assertEquals (tree .root ().maxEnd .intValue (), 1 );
205+
206+ tree .add (Interval .toInterval (2 , 5 ));
207+ assertEquals (tree .size (), 2 );
208+ assertEquals (tree .root ().maxEnd .intValue (), 5 );
209+
210+ tree .remove (Interval .toInterval (2 , 5 ));
211+ assertEquals (tree .size (), 1 );
212+ assertEquals (tree .root ().maxEnd .intValue (), 1 );
213+
214+ tree .remove (Interval .toInterval (0 , 1 ));
215+ assertEquals (tree .size (), 0 );
216+
217+ // new tree, insert in opposite order
218+ tree = new IntervalTree <>();
219+ tree .add (Interval .toInterval (2 , 5 ));
220+ assertEquals (tree .size (), 1 );
221+ assertEquals (tree .root ().maxEnd .intValue (), 5 );
222+
223+ tree .add (Interval .toInterval (0 , 1 ));
224+ assertEquals (tree .size (), 2 );
225+ assertEquals (tree .root ().maxEnd .intValue (), 5 );
226+
227+ tree .remove (Interval .toInterval (2 , 5 ));
228+ assertEquals (tree .size (), 1 );
229+ assertEquals (tree .root ().maxEnd .intValue (), 1 );
230+
231+ tree .remove (Interval .toInterval (0 , 1 ));
232+ assertEquals (tree .size (), 0 );
233+
234+ }
163235}
0 commit comments