OSDN Git Service

テストのビルドが失敗していた
[fooeditengine/FooEditEngine.git] / WPF / UnitTest / RangeCollectionTest.cs
1 /*
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.
5
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.
8
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/>.
10  */
11
12 using System;
13 using System.Collections.Generic;
14 using System.Linq;
15 using System.Text;
16 using System.Threading.Tasks;
17 using Microsoft.VisualStudio.TestTools.UnitTesting;
18 using FooEditEngine;
19
20 namespace UnitTest
21 {
22     [TestClass]
23     public class RangeCollectionTest
24     {
25         class MyRangeItem : IRange
26         {
27             public MyRangeItem(int start,int length)
28             {
29                 this.start = start;
30                 this.length = length;
31             }
32
33             public int start
34             {
35                 get;
36                 set;
37             }
38
39             public int length
40             {
41                 get;
42                 set;
43             }
44         }
45         [TestMethod]
46         public void QueryRangeItemTest()
47         {
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);
52
53             result = collection.Get(0, 20).ToList();
54             Assert.IsTrue(result[0].start == 1 && result[0].length == 10);
55
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);
60         }
61
62         [TestMethod]
63         public void RemoveRangeItemTest()
64         {
65             RangeCollection<MyRangeItem> collection = new RangeCollection<MyRangeItem>();
66             collection.Add(new MyRangeItem(1, 10));
67             collection.Add(new MyRangeItem(20, 10));
68
69             collection.RemoveNearest(0, 15);
70             
71             var result = collection.ToList();
72             Assert.IsTrue(result[0].start == 20 && result[0].length == 10);
73
74             collection.Remove(20,1);
75             Assert.IsTrue(collection.Count == 0);
76         }
77     }
78 }