5 // Alexander Chebaturkin (chebaturkin@gmail.com)
7 // Copyright (C) 2012 Alexander Chebaturkin
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using Mono.CodeContracts.Static.Analysis.Numerical;
30 using Mono.CodeContracts.Static.DataStructures;
32 using NUnit.Framework;
34 namespace MonoTests.Mono.CodeContracts {
36 class DisIntervalTests : DomainTestBase<DisInterval> {
37 protected override DisInterval Top { get { return DisInterval.TopValue; } }
38 protected override DisInterval Bottom { get { return DisInterval.BottomValue; } }
39 protected override DisInterval Normal { get { return DisInterval.For (this._1__2); } }
41 readonly Interval _0__1 = Interval.For (0, 1);
42 readonly Interval _0__4 = Interval.For (0, 4);
43 readonly Interval _1__2 = Interval.For (1, 2);
44 readonly Interval _1__3 = Interval.For (1, 3);
45 readonly Interval _1__4 = Interval.For (1, 4);
46 readonly Interval _1__5 = Interval.For (1, 5);
47 readonly Interval _2__4 = Interval.For (2, 4);
48 readonly Interval _2__5 = Interval.For (2, 5);
49 readonly Interval _3__4 = Interval.For (3, 4);
51 static Interval JoinAll (params Interval[] intervals)
53 return DisInterval.JoinAll (Sequence<Interval>.From (intervals));
57 public void ForSingleInterval ()
59 DisInterval disInterval = DisInterval.For (this._1__2);
61 Assert.That (disInterval.AsInterval, Is.EqualTo (this._1__2));
65 public void JoinAllForIntervals ()
67 Assert.That (JoinAll (this._1__2), Is.EqualTo (this._1__2));
68 Assert.That (JoinAll (this._1__2, this._3__4), Is.EqualTo (this._1__4));
69 Assert.That (JoinAll (), Is.EqualTo (Interval.TopValue));
73 public void NormalizeTests ()
77 DisInterval.Normalize (Sequence<Interval>.From (this._1__2, this._3__4), out isBottom),
78 Sequence<Interval>.From (this._1__4));
81 DisInterval.Normalize (Sequence<Interval>.From (this._1__4, this._1__2), out isBottom),
82 Sequence<Interval>.From (this._1__4));
85 DisInterval.Normalize (Sequence<Interval>.From (this._1__2, this._1__4), out isBottom),
86 Sequence<Interval>.From (this._1__4));
89 DisInterval.Normalize (Sequence<Interval>.From (this._1__4, this._2__4), out isBottom),
90 Sequence<Interval>.From (this._1__4));
93 DisInterval.Normalize (Sequence<Interval>.From (this._1__3, this._2__5), out isBottom),
94 Sequence<Interval>.From (this._1__5));
97 DisInterval.Normalize (Sequence<Interval>.From (Interval.BottomValue, Interval.BottomValue), out isBottom),
98 Sequence<Interval>.Empty);
99 Assert.IsTrue (isBottom);
102 DisInterval.Normalize (Sequence<Interval>.From (Interval.BottomValue), out isBottom),
103 Sequence<Interval>.Empty);
104 Assert.IsTrue (isBottom);
108 public void ShouldHaveAddOperation ()
110 Assert.That (DisInterval.For (this._1__2) + DisInterval.For (this._3__4),
111 Is.EqualTo (DisInterval.For (Interval.For (4, 6))));
115 public void ShouldHaveJoinOperation ()
117 DisInterval left = DisInterval.For (this._0__1).Join (DisInterval.For (this._3__4));
118 DisInterval right = DisInterval.For (this._1__2).Join (DisInterval.For (this._1__4));
119 Assert.That (left.Join (right), Is.EqualTo (DisInterval.For (this._0__4)));
123 public void ShouldHaveMeetOperation ()
125 Assert.That (DisInterval.For (this._1__4).Meet (DisInterval.For (this._1__2)),
126 Is.EqualTo (DisInterval.For (this._1__2)));
130 public void ShouldHaveSubOperation ()
132 Assert.That (DisInterval.For (this._1__2) - DisInterval.For (this._3__4),
133 Is.EqualTo (DisInterval.For (Interval.For (-3, -1))));