2 * Copyright (C) 2013 FooProject
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
13 using System.Collections.Generic;
16 using System.Threading.Tasks;
17 using Microsoft.VisualStudio.TestTools.UnitTesting;
23 public class RangeCollectionTest
25 class MyRangeItem : IRange
27 public MyRangeItem(int start,int length)
46 public void QueryRangeItemTest()
48 RangeCollection<MyRangeItem> collection = new RangeCollection<MyRangeItem>();
49 collection.Add(new MyRangeItem(1, 10));
50 var result = collection.Get(1).ToList();
51 Assert.IsTrue(result[0].start == 1 && result[0].length == 10);
53 result = collection.Get(0, 20).ToList();
54 Assert.IsTrue(result[0].start == 1 && result[0].length == 10);
56 collection.Add(new MyRangeItem(15, 10));
57 result = collection.Get(0, 20).ToList();
58 Assert.IsTrue(result[0].start == 1 && result[0].length == 10);
59 Assert.IsTrue(result[1].start == 15 && result[0].length == 10);
63 public void RemoveRangeItemTest()
65 RangeCollection<MyRangeItem> collection = new RangeCollection<MyRangeItem>();
66 collection.Add(new MyRangeItem(1, 10));
67 collection.Add(new MyRangeItem(20, 10));
69 collection.RemoveNearest(0, 15);
71 var result = collection.ToList();
72 Assert.IsTrue(result[0].start == 20 && result[0].length == 10);
74 collection.Remove(20,1);
75 Assert.IsTrue(collection.Count == 0);