Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2012-09-05 15:01:29 +0400
committerMarek Safar <marek.safar@gmail.com>2012-09-05 15:01:29 +0400
commitfbb513c138734289d3e6b2b9039a2ec2e0dabd93 (patch)
treee44cf60e8831355c15a2e16f65498f592b24cc32 /mcs/class/Mono.CodeContracts
parent124770e8a816ebdfaeb337a88cef6917cb52e967 (diff)
Merge more Mono.CodeContracts changes
Diffstat (limited to 'mcs/class/Mono.CodeContracts')
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/DisInterval.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/ExpressionOperator.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Interval.cs4
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/IntervalBase.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Rational.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/RationalThreshold.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Threshold.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/BranchNode.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/EmptyNode.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/LeafNode.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/PatriciaTrieNode.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/IImmutableIntMap.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/ImmutableIntMap.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/Sequence.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/SequenceExtensions.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/AbstractDomainExtensions.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/FlatDomain.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/IAbstractDomain.cs2
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/AbstractDomainExtensionsTests.cs133
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/DisIntervalTests.cs136
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/DomainTestBase.cs123
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/FlatDomainTests.cs40
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/IntervalTests.cs173
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/PatriciaTrieTests.cs121
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalTestExtensions.cs55
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalTests.cs157
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalThresholdTests.cs91
-rw-r--r--mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/SequenceTests.cs80
28 files changed, 1128 insertions, 19 deletions
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/DisInterval.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/DisInterval.cs
index 38d421017ee..19f539f9634 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/DisInterval.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/DisInterval.cs
@@ -36,7 +36,7 @@ using Mono.CodeContracts.Static.DataStructures;
using Mono.CodeContracts.Static.Lattices;
namespace Mono.CodeContracts.Static.Analysis.Numerical {
- class DisInterval : IntervalBase<DisInterval, Rational> {
+ public class DisInterval : IntervalBase<DisInterval, Rational> {
public static readonly DisInterval NotZero =
For (Sequence<Interval>.From (Interval.For (Rational.MinusInfinity, -1L),
Interval.For (1L, Rational.PlusInfinity)));
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/ExpressionOperator.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/ExpressionOperator.cs
index 076b431cef9..5c4333b6faa 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/ExpressionOperator.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/ExpressionOperator.cs
@@ -29,7 +29,7 @@
using System.Collections.Generic;
namespace Mono.CodeContracts.Static.Analysis.Numerical {
- enum ExpressionOperator {
+ public enum ExpressionOperator {
Constant,
Variable,
Not,
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Interval.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Interval.cs
index d473ca6b400..3df3424b38d 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Interval.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Interval.cs
@@ -40,7 +40,7 @@ namespace Mono.CodeContracts.Static.Analysis.Numerical {
/// <summary>
/// Represents a closed interval of <see cref="Rational"/> values.
/// </summary>
- class Interval : IntervalBase<Interval, Rational>, IEquatable<Interval> {
+ public class Interval : IntervalBase<Interval, Rational>, IEquatable<Interval> {
static Interval cached_top_value;
static Interval cached_bottom_value;
@@ -379,7 +379,7 @@ namespace Mono.CodeContracts.Static.Analysis.Numerical {
return For (lower, upper);
}
- public static class Ranges {
+ internal static class Ranges {
static Interval int8Range;
static Interval int32Range;
static Interval int64Range;
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/IntervalBase.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/IntervalBase.cs
index 78d4c88f99b..ffc486812df 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/IntervalBase.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/IntervalBase.cs
@@ -34,7 +34,7 @@ namespace Mono.CodeContracts.Static.Analysis.Numerical {
/// <summary>
/// Represents a generic class for intervals on numeric values.
/// </summary>
- abstract class IntervalBase<TInterval, TNumeric> : IAbstractDomain<TInterval>
+ public abstract class IntervalBase<TInterval, TNumeric> : IAbstractDomain<TInterval>
where TInterval : IntervalBase<TInterval, TNumeric> {
protected IntervalBase (TNumeric lowerBound, TNumeric upperBound)
{
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Rational.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Rational.cs
index b70ea968dfe..b69740a7356 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Rational.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Rational.cs
@@ -34,7 +34,7 @@ namespace Mono.CodeContracts.Static.Analysis.Numerical {
/// <summary>
/// Represents a rational number.
/// </summary>
- struct Rational : IEquatable<Rational> {
+ public struct Rational : IEquatable<Rational> {
public static readonly Rational Zero = new Rational (0L);
public static readonly Rational One = new Rational (1L);
public static readonly Rational MinusOne = new Rational (-1L);
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/RationalThreshold.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/RationalThreshold.cs
index 9050db0d581..27de0a01d22 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/RationalThreshold.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/RationalThreshold.cs
@@ -27,7 +27,7 @@
//
namespace Mono.CodeContracts.Static.Analysis.Numerical {
- class RationalThreshold : Threshold<Rational> {
+ public class RationalThreshold : Threshold<Rational> {
public RationalThreshold (int size) : base (size)
{
}
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Threshold.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Threshold.cs
index 37f817ba22c..ba9ce8c4996 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Threshold.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Analysis.Numerical/Threshold.cs
@@ -29,7 +29,7 @@
using System.Collections.Generic;
namespace Mono.CodeContracts.Static.Analysis.Numerical {
- abstract class Threshold<T> {
+ public abstract class Threshold<T> {
protected int NextFree;
protected readonly List<T> Values;
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/BranchNode.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/BranchNode.cs
index 5c63d97722b..b83cda222aa 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/BranchNode.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/BranchNode.cs
@@ -33,7 +33,7 @@ using System.Text;
namespace Mono.CodeContracts.Static.DataStructures.Patricia
{
- internal class BranchNode<T> : PatriciaTrieNode<T>
+ public class BranchNode<T> : PatriciaTrieNode<T>
{
private readonly int count;
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/EmptyNode.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/EmptyNode.cs
index cdde993afcb..30ca10b3f2d 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/EmptyNode.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/EmptyNode.cs
@@ -33,7 +33,7 @@ using System.Text;
namespace Mono.CodeContracts.Static.DataStructures.Patricia
{
- class EmptyNode<T> : PatriciaTrieNode<T>
+ public class EmptyNode<T> : PatriciaTrieNode<T>
{
public static readonly EmptyNode<T> Instance = new EmptyNode<T>();
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/LeafNode.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/LeafNode.cs
index c8b4b5b62e3..81a98a22cdd 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/LeafNode.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/LeafNode.cs
@@ -33,7 +33,7 @@ using System.Text;
namespace Mono.CodeContracts.Static.DataStructures.Patricia
{
- internal class LeafNode<T> : PatriciaTrieNode<T>
+ public class LeafNode<T> : PatriciaTrieNode<T>
{
private readonly int _key;
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/PatriciaTrieNode.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/PatriciaTrieNode.cs
index f0e99e5ffce..9ec068eccc1 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/PatriciaTrieNode.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures.Patricia/PatriciaTrieNode.cs
@@ -33,7 +33,7 @@ using System.Text;
namespace Mono.CodeContracts.Static.DataStructures.Patricia
{
- abstract class PatriciaTrieNode<T> : IImmutableIntMap<T>
+ public abstract class PatriciaTrieNode<T> : IImmutableIntMap<T>
{
public T this[int key]
{
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/IImmutableIntMap.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/IImmutableIntMap.cs
index d4e0bb20289..9f103a9b3d1 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/IImmutableIntMap.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/IImmutableIntMap.cs
@@ -30,7 +30,7 @@ using System;
using System.Collections.Generic;
namespace Mono.CodeContracts.Static.DataStructures {
- interface IImmutableIntMap<T> {
+ public interface IImmutableIntMap<T> {
T this [int key] { get; }
T Any { get; }
IEnumerable<T> Values { get; }
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/ImmutableIntMap.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/ImmutableIntMap.cs
index 8d2bc096683..0727f852bf9 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/ImmutableIntMap.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/ImmutableIntMap.cs
@@ -29,7 +29,7 @@
using Mono.CodeContracts.Static.DataStructures.Patricia;
namespace Mono.CodeContracts.Static.DataStructures {
- static class ImmutableIntMap<T>
+ public static class ImmutableIntMap<T>
{
public static readonly IImmutableIntMap<T> Empty = EmptyNode<T>.Instance;
}
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/Sequence.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/Sequence.cs
index 6899b4bea00..b5af4a33b10 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/Sequence.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/Sequence.cs
@@ -31,7 +31,7 @@ using System.Collections.Generic;
using System.Text;
namespace Mono.CodeContracts.Static.DataStructures {
- class Sequence<T> : IEquatable<Sequence<T>> {
+ public class Sequence<T> : IEquatable<Sequence<T>> {
public static readonly Sequence<T> Empty = null;
readonly int count;
readonly T element;
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/SequenceExtensions.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/SequenceExtensions.cs
index 5fa7f4b86c3..23733eeb0ae 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/SequenceExtensions.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.DataStructures/SequenceExtensions.cs
@@ -30,7 +30,7 @@ using System;
using System.Collections.Generic;
namespace Mono.CodeContracts.Static.DataStructures {
- static class SequenceExtensions {
+ public static class SequenceExtensions {
public static Sequence<T> Cons<T> (this Sequence<T> rest, T elem)
{
return Sequence<T>.Cons (elem, rest);
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/AbstractDomainExtensions.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/AbstractDomainExtensions.cs
index 5c0ff40fc89..68a6c51f000 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/AbstractDomainExtensions.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/AbstractDomainExtensions.cs
@@ -29,7 +29,7 @@
using Mono.CodeContracts.Static.DataStructures;
namespace Mono.CodeContracts.Static.Lattices {
- static class AbstractDomainExtensions {
+ public static class AbstractDomainExtensions {
public static bool IsNormal<T> (this IAbstractDomain<T> domain)
{
return !domain.IsTop && !domain.IsBottom;
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/FlatDomain.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/FlatDomain.cs
index 8d77aba5c3b..adc9a9a10b3 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/FlatDomain.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/FlatDomain.cs
@@ -41,7 +41,7 @@ namespace Mono.CodeContracts.Static.Lattices {
/// Bot
/// </example>
/// <typeparam name="T"></typeparam>
- struct FlatDomain<T> : IAbstractDomain<FlatDomain<T>>, IEquatable<FlatDomain<T>>
+ public struct FlatDomain<T> : IAbstractDomain<FlatDomain<T>>, IEquatable<FlatDomain<T>>
where T : IEquatable<T> {
public static readonly FlatDomain<T> BottomValue = new FlatDomain<T> (DomainKind.Bottom);
public static readonly FlatDomain<T> TopValue = new FlatDomain<T> (DomainKind.Top);
diff --git a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/IAbstractDomain.cs b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/IAbstractDomain.cs
index c63319ac013..a8401ee22e8 100644
--- a/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/IAbstractDomain.cs
+++ b/mcs/class/Mono.CodeContracts/Mono.CodeContracts.Static.Lattices/IAbstractDomain.cs
@@ -33,7 +33,7 @@ namespace Mono.CodeContracts.Static.Lattices {
/// Represents abstraction of concrete value
/// </summary>
/// <typeparam name="T"></typeparam>
- interface IAbstractDomain<T> {
+ public interface IAbstractDomain<T> {
/// <summary>
/// Represents universe set (which holds every value)
/// </summary>
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/AbstractDomainExtensionsTests.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/AbstractDomainExtensionsTests.cs
new file mode 100644
index 00000000000..ab8931a4c18
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/AbstractDomainExtensionsTests.cs
@@ -0,0 +1,133 @@
+//
+// AbstractDomainExtensionsTests.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+using Mono.CodeContracts.Static.Lattices;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.CodeContracts {
+ [TestFixture]
+ public class AbstractDomainExtensionsTests {
+ readonly FlatDomain<int> top = FlatDomain<int>.TopValue;
+ readonly FlatDomain<int> bottom = FlatDomain<int>.BottomValue;
+ readonly FlatDomain<int> normal = 1;
+
+ const bool Dummy = false;
+
+ /// <summary>
+ /// Checks that Meet(l, r, out result) == trivialSuccess && check(result);
+ /// </summary>
+ static void AssertMeetResultFor (FlatDomain<int> l, FlatDomain<int> r, bool trivialSuccess, Func<FlatDomain<int>, bool> check)
+ {
+ FlatDomain<int> result;
+ Assert.That (l.TryTrivialMeet (r, out result), Is.EqualTo (trivialSuccess));
+ if (trivialSuccess)
+ Assert.That (check (result));
+ }
+
+ /// <summary>
+ /// Checks that Join(l, r, out result) == trivialSuccess && check(result);
+ /// </summary>
+ static void AssertJoinResultFor (FlatDomain<int> l, FlatDomain<int> r, bool trivialSuccess, Func<FlatDomain<int>, bool> check)
+ {
+ FlatDomain<int> result;
+ Assert.That (l.TryTrivialJoin (r, out result), Is.EqualTo (trivialSuccess));
+ if (trivialSuccess)
+ Assert.That (check (result));
+ }
+
+ /// <summary>
+ /// Checks that LessEqual(l, r, out result) == trivialSuccess && result == resultCheck;
+ /// </summary>
+ static void AssertLessEqualResultFor (FlatDomain<int> l, FlatDomain<int> r, bool trivialSuccess, bool resultCheck)
+ {
+ bool result;
+ Assert.That (l.TryTrivialLessEqual (r, out result), Is.EqualTo (trivialSuccess));
+ if (trivialSuccess)
+ Assert.That (result, Is.EqualTo (resultCheck));
+ }
+
+ [Test]
+ public void TestCasesIsNormal ()
+ {
+ Assert.That (this.top.IsNormal (), Is.False);
+ Assert.That (this.bottom.IsNormal (), Is.False);
+ Assert.That (this.normal.IsNormal (), Is.True);
+ }
+
+ [Test]
+ public void TestCasesTrivialJoin ()
+ {
+ AssertJoinResultFor (this.top, this.top, true, (r) => r.IsTop);
+ AssertJoinResultFor (this.top, this.bottom, true, (r) => r.IsTop);
+ AssertJoinResultFor (this.top, this.normal, true, (r) => r.IsTop);
+
+ AssertJoinResultFor (this.bottom, this.top, true, (r) => r.IsTop);
+ AssertJoinResultFor (this.bottom, this.bottom, true, (r) => r.IsBottom);
+ AssertJoinResultFor (this.bottom, this.normal, true, (r) => r.IsNormal ());
+
+ AssertJoinResultFor (this.normal, this.top, true, (r) => r.IsTop);
+ AssertJoinResultFor (this.normal, this.bottom, true, (r) => r.IsNormal ());
+ AssertJoinResultFor (this.normal, this.normal, false, (r) => Dummy);
+ }
+
+ [Test]
+ public void TestCasesTrivialLessEqual ()
+ {
+ AssertLessEqualResultFor (this.top, this.top, true, true);
+ AssertLessEqualResultFor (this.top, this.bottom, true, false);
+ AssertLessEqualResultFor (this.top, this.normal, true, false);
+
+ AssertLessEqualResultFor (this.bottom, this.top, true, true);
+ AssertLessEqualResultFor (this.bottom, this.bottom, true, true);
+ AssertLessEqualResultFor (this.bottom, this.normal, true, true);
+
+ AssertLessEqualResultFor (this.normal, this.top, true, true);
+ AssertLessEqualResultFor (this.normal, this.bottom, true, false);
+ AssertLessEqualResultFor (this.normal, this.normal, false, Dummy);
+ }
+
+ [Test]
+ public void TestCasesTrivialMeet ()
+ {
+ AssertMeetResultFor (this.top, this.top, true, (r) => r.IsTop);
+ AssertMeetResultFor (this.top, this.bottom, true, (r) => r.IsBottom);
+ AssertMeetResultFor (this.top, this.normal, true, (r) => r.IsNormal ());
+
+ AssertMeetResultFor (this.bottom, this.top, true, (r) => r.IsBottom);
+ AssertMeetResultFor (this.bottom, this.bottom, true, (r) => r.IsBottom);
+ AssertMeetResultFor (this.bottom, this.normal, true, (r) => r.IsBottom);
+
+ AssertMeetResultFor (this.normal, this.top, true, (r) => r.IsNormal ());
+ AssertMeetResultFor (this.normal, this.bottom, true, (r) => r.IsBottom);
+ AssertMeetResultFor (this.normal, this.normal, false, (r) => Dummy);
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/DisIntervalTests.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/DisIntervalTests.cs
new file mode 100644
index 00000000000..d3508e2d0c4
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/DisIntervalTests.cs
@@ -0,0 +1,136 @@
+//
+// DisIntervalTests.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.CodeContracts.Static.Analysis.Numerical;
+using Mono.CodeContracts.Static.DataStructures;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.CodeContracts {
+ [TestFixture]
+ class DisIntervalTests : DomainTestBase<DisInterval> {
+ protected override DisInterval Top { get { return DisInterval.TopValue; } }
+ protected override DisInterval Bottom { get { return DisInterval.BottomValue; } }
+ protected override DisInterval Normal { get { return DisInterval.For (this._1__2); } }
+
+ readonly Interval _0__1 = Interval.For (0, 1);
+ readonly Interval _0__4 = Interval.For (0, 4);
+ readonly Interval _1__2 = Interval.For (1, 2);
+ readonly Interval _1__3 = Interval.For (1, 3);
+ readonly Interval _1__4 = Interval.For (1, 4);
+ readonly Interval _1__5 = Interval.For (1, 5);
+ readonly Interval _2__4 = Interval.For (2, 4);
+ readonly Interval _2__5 = Interval.For (2, 5);
+ readonly Interval _3__4 = Interval.For (3, 4);
+
+ static Interval JoinAll (params Interval[] intervals)
+ {
+ return DisInterval.JoinAll (Sequence<Interval>.From (intervals));
+ }
+
+ [Test]
+ public void ForSingleInterval ()
+ {
+ DisInterval disInterval = DisInterval.For (this._1__2);
+
+ Assert.That (disInterval.AsInterval, Is.EqualTo (this._1__2));
+ }
+
+ [Test]
+ public void JoinAllForIntervals ()
+ {
+ Assert.That (JoinAll (this._1__2), Is.EqualTo (this._1__2));
+ Assert.That (JoinAll (this._1__2, this._3__4), Is.EqualTo (this._1__4));
+ Assert.That (JoinAll (), Is.EqualTo (Interval.TopValue));
+ }
+
+ [Test]
+ public void NormalizeTests ()
+ {
+ bool isBottom;
+ Assert.AreEqual (
+ DisInterval.Normalize (Sequence<Interval>.From (this._1__2, this._3__4), out isBottom),
+ Sequence<Interval>.From (this._1__4));
+
+ Assert.AreEqual (
+ DisInterval.Normalize (Sequence<Interval>.From (this._1__4, this._1__2), out isBottom),
+ Sequence<Interval>.From (this._1__4));
+
+ Assert.AreEqual (
+ DisInterval.Normalize (Sequence<Interval>.From (this._1__2, this._1__4), out isBottom),
+ Sequence<Interval>.From (this._1__4));
+
+ Assert.AreEqual (
+ DisInterval.Normalize (Sequence<Interval>.From (this._1__4, this._2__4), out isBottom),
+ Sequence<Interval>.From (this._1__4));
+
+ Assert.AreEqual (
+ DisInterval.Normalize (Sequence<Interval>.From (this._1__3, this._2__5), out isBottom),
+ Sequence<Interval>.From (this._1__5));
+
+ Assert.AreEqual (
+ DisInterval.Normalize (Sequence<Interval>.From (Interval.BottomValue, Interval.BottomValue), out isBottom),
+ Sequence<Interval>.Empty);
+ Assert.IsTrue (isBottom);
+
+ Assert.AreEqual (
+ DisInterval.Normalize (Sequence<Interval>.From (Interval.BottomValue), out isBottom),
+ Sequence<Interval>.Empty);
+ Assert.IsTrue (isBottom);
+ }
+
+ [Test]
+ public void ShouldHaveAddOperation ()
+ {
+ Assert.That (DisInterval.For (this._1__2) + DisInterval.For (this._3__4),
+ Is.EqualTo (DisInterval.For (Interval.For (4, 6))));
+ }
+
+ [Test]
+ public void ShouldHaveJoinOperation ()
+ {
+ DisInterval left = DisInterval.For (this._0__1).Join (DisInterval.For (this._3__4));
+ DisInterval right = DisInterval.For (this._1__2).Join (DisInterval.For (this._1__4));
+ Assert.That (left.Join (right), Is.EqualTo (DisInterval.For (this._0__4)));
+ }
+
+ [Test]
+ public void ShouldHaveMeetOperation ()
+ {
+ Assert.That (DisInterval.For (this._1__4).Meet (DisInterval.For (this._1__2)),
+ Is.EqualTo (DisInterval.For (this._1__2)));
+ }
+
+ [Test]
+ public void ShouldHaveSubOperation ()
+ {
+ Assert.That (DisInterval.For (this._1__2) - DisInterval.For (this._3__4),
+ Is.EqualTo (DisInterval.For (Interval.For (-3, -1))));
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/DomainTestBase.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/DomainTestBase.cs
new file mode 100644
index 00000000000..ce4b7c441c3
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/DomainTestBase.cs
@@ -0,0 +1,123 @@
+//
+// DomainTestBase.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+using Mono.CodeContracts.Static.Lattices;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.CodeContracts {
+ [TestFixture]
+ abstract class DomainTestBase<T> where T : IAbstractDomain<T> {
+ protected abstract T Top { get; }
+ protected abstract T Bottom { get; }
+ protected abstract T Normal { get; }
+
+ /// <summary>
+ /// Checks that Meet(l, r, out result) == trivialSuccess && check(result);
+ /// </summary>
+ static void AssertMeetResultFor (T l, T r, Func<T, bool> check)
+ {
+ T result = l.Meet (r);
+ Assert.That (check (result));
+ }
+
+ /// <summary>
+ /// Checks that Join(l, r, out result) == trivialSuccess && check(result);
+ /// </summary>
+ static void AssertJoinResultFor (T l, T r, Func<T, bool> check)
+ {
+ bool weaker;
+ T result = l.Join (r, true, out weaker);
+ Assert.That (check (result));
+ }
+
+ /// <summary>
+ /// Checks that LessEqual(l, r, out result) == trivialSuccess && result == expectedResult;
+ /// </summary>
+ static void AssertLessEqualResultFor (T l, T r, bool expectedResult)
+ {
+ bool result = l.LessEqual (r);
+ Assert.That (result, Is.EqualTo (expectedResult));
+ }
+
+ [Test]
+ public void IsNormal ()
+ {
+ Assert.That (this.Top.IsNormal (), Is.False);
+ Assert.That (this.Bottom.IsNormal (), Is.False);
+ Assert.That (this.Normal.IsNormal (), Is.True);
+ }
+
+ [Test]
+ public void Join ()
+ {
+ AssertJoinResultFor (this.Top, this.Top, (r) => r.IsTop);
+ AssertJoinResultFor (this.Top, this.Bottom, (r) => r.IsTop);
+ AssertJoinResultFor (this.Top, this.Normal, (r) => r.IsTop);
+
+ AssertJoinResultFor (this.Bottom, this.Top, (r) => r.IsTop);
+ AssertJoinResultFor (this.Bottom, this.Bottom, (r) => r.IsBottom);
+ AssertJoinResultFor (this.Bottom, this.Normal, (r) => r.IsNormal ());
+
+ AssertJoinResultFor (this.Normal, this.Top, (r) => r.IsTop);
+ AssertJoinResultFor (this.Normal, this.Bottom, (r) => r.IsNormal ());
+ }
+
+ [Test]
+ public void LessEqual ()
+ {
+ AssertLessEqualResultFor (this.Top, this.Top, true);
+ AssertLessEqualResultFor (this.Top, this.Bottom, false);
+ AssertLessEqualResultFor (this.Top, this.Normal, false);
+
+ AssertLessEqualResultFor (this.Bottom, this.Top, true);
+ AssertLessEqualResultFor (this.Bottom, this.Bottom, true);
+ AssertLessEqualResultFor (this.Bottom, this.Normal, true);
+
+ AssertLessEqualResultFor (this.Normal, this.Top, true);
+ AssertLessEqualResultFor (this.Normal, this.Bottom, false);
+ }
+
+ [Test]
+ public void Meet ()
+ {
+ AssertMeetResultFor (this.Top, this.Top, r => r.IsTop);
+ AssertMeetResultFor (this.Top, this.Bottom, r => r.IsBottom);
+ AssertMeetResultFor (this.Top, this.Normal, r => r.IsNormal ());
+
+ AssertMeetResultFor (this.Bottom, this.Top, r => r.IsBottom);
+ AssertMeetResultFor (this.Bottom, this.Bottom, r => r.IsBottom);
+ AssertMeetResultFor (this.Bottom, this.Normal, r => r.IsBottom);
+
+ AssertMeetResultFor (this.Normal, this.Top, r => r.IsNormal ());
+ AssertMeetResultFor (this.Normal, this.Bottom, r => r.IsBottom);
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/FlatDomainTests.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/FlatDomainTests.cs
new file mode 100644
index 00000000000..95ec050ebe7
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/FlatDomainTests.cs
@@ -0,0 +1,40 @@
+//
+// FlatDomainTests.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.CodeContracts.Static.Lattices;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.CodeContracts {
+ [TestFixture (Category = "FlatDomainTrivialTests")]
+ class FlatDomainTests : DomainTestBase<FlatDomain<int>> {
+ protected override FlatDomain<int> Top { get { return FlatDomain<int>.TopValue; } }
+ protected override FlatDomain<int> Bottom { get { return FlatDomain<int>.BottomValue; } }
+ protected override FlatDomain<int> Normal { get { return 1; } }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/IntervalTests.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/IntervalTests.cs
new file mode 100644
index 00000000000..036293665ce
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/IntervalTests.cs
@@ -0,0 +1,173 @@
+//
+// IntervalTests.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.CodeContracts.Static.Analysis.Numerical;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.CodeContracts {
+ [TestFixture (typeof (Interval))]
+ class IntervalTests : DomainTestBase<Interval> {
+ readonly Interval _1__2 = Interval.For (1, 2);
+ readonly Interval _2__4 = Interval.For (2, 4);
+ readonly Interval _3__4 = Interval.For (3, 4);
+ readonly Interval _1__4 = Interval.For (1, 4);
+
+ readonly Interval zero_to_one = Interval.For (Rational.Zero, Rational.One);
+ readonly Interval minus_one_to_zero = Interval.For (Rational.MinusOne, Rational.Zero);
+
+ protected override Interval Top { get { return Interval.TopValue; } }
+ protected override Interval Bottom { get { return Interval.BottomValue; } }
+ protected override Interval Normal { get { return this._1__2; } }
+
+ [Test]
+ public void ConsecutiveIntegers ()
+ {
+ Assert.That (Interval.AreConsecutiveIntegers (this._1__2, this._3__4), Is.True);
+ Assert.That (Interval.AreConsecutiveIntegers (this._1__2, this._1__2), Is.False);
+ Assert.That (Interval.AreConsecutiveIntegers (this._3__4, this._1__2), Is.False);
+ Assert.That (Interval.AreConsecutiveIntegers (Interval.For (Rational.For (1, 3)), this._1__2),
+ Is.False);
+ }
+
+ [Test]
+ public void OnTheLeftOf ()
+ {
+ Assert.IsTrue (this._1__2.OnTheLeftOf (this._3__4));
+ Assert.IsTrue (this._1__2.OnTheLeftOf (this._2__4));
+
+ Assert.IsFalse (this._2__4.OnTheLeftOf (this._1__2));
+ Assert.IsFalse (this._1__4.OnTheLeftOf (this._1__2));
+ Assert.IsFalse (this._1__2.OnTheLeftOf (this._1__4));
+ }
+
+ [Test]
+ public void ShouldAddIntervalsByEachBound ()
+ {
+ Assert.That (this.Bottom + this._1__2, Is.EqualTo (this.Bottom), "bottom + normal = bottom");
+ Assert.That (this.Bottom + this.Top, Is.EqualTo (this.Bottom), "bottom + top = bottom");
+ Assert.That (this.Bottom + this.Bottom, Is.EqualTo (this.Bottom), "bottom + bottom = bottom");
+
+ Assert.That (this.Top + this.Top, Is.EqualTo (this.Top), "top + top = top");
+ Assert.That (this.Top + this._1__2, Is.EqualTo (this.Top), "top + normal = top");
+ Assert.That (this.Top + this.Bottom, Is.EqualTo (this.Bottom), "top + bottom = bottom");
+
+ Assert.That (this._1__2 + this.Bottom, Is.EqualTo (this.Bottom), "normal + bottom = bottom");
+ Assert.That (this._1__2 + this.Top, Is.EqualTo (this.Top), "normal + top = top");
+ Assert.That (this._1__2 + this._3__4, Is.EqualTo (Interval.For (1 + 3, 2 + 4)));
+ }
+
+ [Test]
+ public void ShouldDivIntervalsByMaxMin ()
+ {
+ Assert.That (this.Bottom / this._1__2, Is.EqualTo (this.Bottom), "bottom / normal = bottom");
+ Assert.That (this.Bottom / this.Top, Is.EqualTo (this.Bottom), "bottom / top = bottom");
+ Assert.That (this.Bottom / this.Bottom, Is.EqualTo (this.Bottom), "bottom / bottom = bottom");
+
+ Assert.That (this.Top / this.Top, Is.EqualTo (this.Top), "top / top = top");
+ Assert.That (this.Top / this._1__2, Is.EqualTo (this.Top), "top / normal = top");
+ Assert.That (this.Top / this.Bottom, Is.EqualTo (this.Bottom), "top / bottom = bottom");
+
+ Assert.That (this._1__2 / this.Bottom, Is.EqualTo (this.Bottom), "normal / bottom = bottom");
+ Assert.That (this._1__2 / this.Top, Is.EqualTo (this.Top), "normal / top = top");
+
+ Assert.That (this._1__2 / this.zero_to_one, Is.EqualTo (this.Top), "normal / zeroToOne = top");
+ Assert.That (this._1__2 / this.minus_one_to_zero, Is.EqualTo (this.Top),
+ "normal / minusOneToZero = top");
+ Assert.That (
+ this._1__2 / this._3__4,
+ Is.EqualTo (Interval.For (Rational.For (1, 4), Rational.For (2, 3))),
+ "normal / normal = normal");
+ }
+
+ [Test]
+ public void ShouldJoinByInclusion ()
+ {
+ Assert.That (this._1__2.Join (this._3__4), Is.EqualTo (Interval.For (1, 4)));
+ Assert.That (this._3__4.Join (this._1__2), Is.EqualTo (Interval.For (1, 4)));
+ }
+
+ [Test]
+ public void ShouldLessEqualByInclusion ()
+ {
+ Assert.That (this._1__2.LessEqual (this._1__2), Is.True);
+
+ Assert.That (this._1__2.LessEqual (this._1__4), Is.True);
+ Assert.That (this._3__4.LessEqual (this._1__4), Is.True);
+
+ Assert.That (this._1__2.LessEqual (this._3__4), Is.False);
+ Assert.That (this._3__4.LessEqual (this._1__2), Is.False);
+
+ Assert.That (this._1__4.LessEqual (this._1__2), Is.False);
+ Assert.That (this._1__4.LessEqual (this._3__4), Is.False);
+ }
+
+ [Test]
+ public void ShouldMultIntervalsByMaxMin ()
+ {
+ Assert.That (this.Bottom * this._1__2, Is.EqualTo (this.Bottom), "bottom * normal = bottom");
+ Assert.That (this.Bottom * this.Top, Is.EqualTo (this.Bottom), "bottom * top = bottom");
+ Assert.That (this.Bottom * this.Bottom, Is.EqualTo (this.Bottom), "bottom * bottom = bottom");
+
+ Assert.That (this.Top * this.Top, Is.EqualTo (this.Top), "top * top = top");
+ Assert.That (this.Top * this._1__2, Is.EqualTo (this.Top), "top * normal = top");
+ Assert.That (this.Top * this.Bottom, Is.EqualTo (this.Bottom), "top * bottom = bottom");
+
+ Assert.That (this._1__2 * this.Bottom, Is.EqualTo (this.Bottom), "normal * bottom = bottom");
+ Assert.That (this._1__2 * this.Top, Is.EqualTo (this.Top), "normal * top = top");
+
+ Assert.That (this._1__2 * this._3__4, Is.EqualTo (Interval.For (3, 8)),
+ "normal * normal = normal");
+ }
+
+ [Test]
+ public void ShouldSubIntervalsByMaxMin ()
+ {
+ Assert.That (this.Bottom - this._1__2, Is.EqualTo (this.Bottom), "bottom - normal = bottom");
+ Assert.That (this.Bottom - this.Top, Is.EqualTo (this.Bottom), "bottom - top = bottom");
+ Assert.That (this.Bottom - this.Bottom, Is.EqualTo (this.Bottom), "bottom - bottom = bottom");
+
+ Assert.That (this.Top - this.Top, Is.EqualTo (this.Top), "top - top = top");
+ Assert.That (this.Top - this._1__2, Is.EqualTo (this.Top), "top - normal = top");
+ Assert.That (this.Top - this.Bottom, Is.EqualTo (this.Bottom), "top - bottom = bottom");
+
+ Assert.That (this._1__2 - this.Bottom, Is.EqualTo (this.Bottom), "normal - bottom = bottom");
+ Assert.That (this._1__2 - this.Top, Is.EqualTo (this.Top), "normal - top = top");
+ Assert.That (this._1__2 - this._3__4, Is.EqualTo (Interval.For (1 - 4, 2 - 3)),
+ "normal - normal = normal");
+ }
+
+ [Test]
+ public void ShouldUnaryMinusIntervals ()
+ {
+ Assert.That (-this.Bottom, Is.EqualTo (this.Bottom), "-bottom = bottom");
+ Assert.That (-this.Top, Is.EqualTo (this.Top), "-top = top");
+ Assert.That (-this._1__2, Is.EqualTo (Interval.For (-2, -1)), "normal: -[l,r] = [-r,-l]");
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/PatriciaTrieTests.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/PatriciaTrieTests.cs
new file mode 100644
index 00000000000..57909397e43
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/PatriciaTrieTests.cs
@@ -0,0 +1,121 @@
+//
+// PatriciaTrieTests.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.CodeContracts.Static.DataStructures;
+using Mono.CodeContracts.Static.DataStructures.Patricia;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.CodeContracts {
+ [TestFixture]
+ public class PatriciaTrieTests {
+ readonly IImmutableIntMap<string> empty = ImmutableIntMap<string>.Empty;
+
+ [Test]
+ public void AddOnEmptyShouldCreateLeafNode ()
+ {
+ var one = this.empty.Add (1, "hello") as LeafNode<string>;
+
+ Assert.That (one.Key, Is.EqualTo (1));
+ Assert.That (one.Value, Is.EqualTo ("hello"));
+ Assert.That (one.Count, Is.EqualTo (1));
+ }
+
+ [Test]
+ public void AddOnLeafShouldCreateAnotherLeafIfKeysAreEqual ()
+ {
+ var leaf = new LeafNode<string> (1, "hello");
+
+ var result = (LeafNode<string>) leaf.Add (1, "there");
+
+ Assert.That (result.Key, Is.EqualTo (1));
+ Assert.That (result.Value, Is.EqualTo ("there"));
+ Assert.That (result.Count, Is.EqualTo (1));
+ }
+
+ [Test]
+ public void AddOnLeafShouldCreateBranchIfKeysAreDifferent ()
+ {
+ var leaf = new LeafNode<string> (5, "hello"); //101
+
+ var branch = (BranchNode<string>) leaf.Add (7, "there"); //111
+
+ Assert.That (branch.Prefix, Is.EqualTo (1)); //x*1
+ Assert.That (branch.BranchingBit, Is.EqualTo (2)); //
+ Assert.That (branch.Left, Is.SameAs (leaf));
+
+ var right = (branch.Right as LeafNode<string>);
+ Assert.That (right, Is.Not.Null);
+ Assert.That (right.Key, Is.EqualTo (7));
+ Assert.That (right.Value, Is.EqualTo ("there"));
+ }
+
+ [Test]
+ public void RemoveFromBranchWithLeafKeyEqualToArgumentShouldStayAnotherChild ()
+ {
+ IImmutableIntMap<string> left = this.empty.Add (5, "hello");
+ IImmutableIntMap<string> branch = left.Add (7, "there");
+
+ IImmutableIntMap<string> node1 = branch.Remove (7);
+ Assert.That (node1, Is.SameAs (left));
+
+ IImmutableIntMap<string> node2 = branch.Remove (5);
+ Assert.That (node2 is LeafNode<string>);
+ Assert.That ((node2 as LeafNode<string>).Key, Is.EqualTo (7));
+ Assert.That ((node2 as LeafNode<string>).Value, Is.EqualTo ("there"));
+ }
+
+ [Test]
+ public void RemoveOnEmptyShouldStayEmpty ()
+ {
+ var one = (EmptyNode<string>) this.empty.Remove (1);
+
+ Assert.That (one, Is.SameAs (this.empty));
+ }
+
+ [Test]
+ public void RemoveOnLeafShouldCreateEmptyIfKeysAreEqual ()
+ {
+ var leaf = new LeafNode<string> (1, "hello");
+
+ var result = (EmptyNode<string>) leaf.Remove (1);
+
+ Assert.That (result.Count, Is.EqualTo (0));
+ }
+
+ [Test]
+ public void RemoveOnLeafShouldStayTheSameIfKeysAreDifferent ()
+ {
+ var leaf = new LeafNode<string> (1, "hello");
+
+ var result = (LeafNode<string>) leaf.Remove (2);
+
+ Assert.That (result, Is.SameAs (leaf));
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalTestExtensions.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalTestExtensions.cs
new file mode 100644
index 00000000000..a30aab7cf2a
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalTestExtensions.cs
@@ -0,0 +1,55 @@
+//
+// RationalTestExtensions.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.CodeContracts.Static.Analysis.Numerical;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.CodeContracts {
+ static class RationalTestExtensions {
+ public static void ShouldBeLessEqualThan (this Rational l, Rational r)
+ {
+ Assert.IsTrue (l <= r);
+ }
+
+ public static void ShouldNotBeLessEqualThan (this Rational l, Rational r)
+ {
+ Assert.IsFalse (l <= r);
+ }
+
+ public static void ShouldBeLessThan (this Rational l, Rational r)
+ {
+ Assert.IsTrue (l < r);
+ }
+
+ public static void ShouldNotBeLessThan (this Rational l, Rational r)
+ {
+ Assert.IsFalse (l < r);
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalTests.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalTests.cs
new file mode 100644
index 00000000000..6f6c4b96708
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalTests.cs
@@ -0,0 +1,157 @@
+//
+// RationalTests.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.CodeContracts.Static.Analysis.Numerical;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.CodeContracts {
+ [TestFixture]
+ public class RationalTests {
+ static readonly Rational zero = Rational.For (0L);
+ static readonly Rational zero1 = Rational.For (0L);
+ static readonly Rational one = Rational.For (1L);
+ static readonly Rational threeFourth = Rational.For (3L, 4L);
+ static readonly Rational sixEighth = Rational.For (6, 8);
+
+ static readonly Rational plusInf = Rational.PlusInfinity;
+ static readonly Rational minusInf = Rational.MinusInfinity;
+
+ [Test]
+ public void ShouldBeEqualByModuloOfDenominator ()
+ {
+ Assert.IsTrue (threeFourth == sixEighth);
+ }
+
+ [Test]
+ public void ShouldHaveAddOperation ()
+ {
+ Rational seven20 = Rational.For (7, 20);
+ Rational eleven15 = Rational.For (11, 15);
+
+ Assert.That (seven20 + eleven15, Is.EqualTo (Rational.For (325, 300)));
+ }
+
+ [Test]
+ public void ShouldHaveDivOperation ()
+ {
+ Rational seven22 = Rational.For (7, 22);
+ Rational eleven21 = Rational.For (21, 11);
+
+ Assert.That (seven22 / eleven21, Is.EqualTo (Rational.For (1, 6)));
+
+ Rational result;
+ Assert.That (Rational.TryDivide (one, zero, out result), Is.False, "shouldn't div by zero");
+ Assert.That (Rational.TryDivide (seven22, zero, out result), Is.False, "shouldn't div by zero");
+ }
+
+ [Test]
+ public void ShouldHaveGreaterThanOperatorsWithLongs ()
+ {
+ Assert.That (threeFourth < 1L);
+ Assert.That (1L > threeFourth);
+
+ Assert.That (0L < threeFourth);
+ Assert.That (threeFourth > 0L);
+ }
+
+ [Test]
+ public void ShouldHaveInfinitiesAndNormalValuesWhichArentEqual ()
+ {
+ Assert.IsFalse (plusInf == minusInf);
+ Assert.IsFalse (plusInf == zero);
+ Assert.IsFalse (minusInf == zero);
+ Assert.IsTrue (zero == zero1);
+ Assert.IsFalse (one == zero);
+ }
+
+ [Test]
+ public void ShouldHaveLessEqualOperator ()
+ {
+ minusInf.ShouldBeLessEqualThan (minusInf);
+ minusInf.ShouldBeLessEqualThan (plusInf);
+ minusInf.ShouldBeLessEqualThan (one);
+
+ one.ShouldNotBeLessEqualThan (minusInf);
+ one.ShouldNotBeLessEqualThan (zero);
+ one.ShouldBeLessEqualThan (one);
+ one.ShouldBeLessEqualThan (plusInf);
+
+ plusInf.ShouldNotBeLessEqualThan (minusInf);
+ plusInf.ShouldBeLessEqualThan (plusInf);
+ plusInf.ShouldNotBeLessEqualThan (one);
+ }
+
+ [Test]
+ public void ShouldHaveLessThanOperator ()
+ {
+ minusInf.ShouldNotBeLessThan (minusInf);
+ minusInf.ShouldBeLessThan (plusInf);
+ minusInf.ShouldBeLessThan (one);
+
+ zero.ShouldNotBeLessThan (minusInf);
+ zero.ShouldBeLessThan (plusInf);
+ zero.ShouldBeLessThan (one);
+
+ plusInf.ShouldNotBeLessThan (minusInf);
+ plusInf.ShouldNotBeLessThan (plusInf);
+ plusInf.ShouldNotBeLessThan (one);
+ }
+
+ [Test]
+ public void ShouldHaveMulOperation ()
+ {
+ Rational seven22 = Rational.For (7, 22);
+ Rational eleven21 = Rational.For (11, 21);
+
+ Assert.That (seven22 * eleven21, Is.EqualTo (Rational.For (1, 6)));
+ }
+
+ [Test]
+ public void ShouldHaveNextInt32 ()
+ {
+ Assert.That (threeFourth.NextInt32, Is.EqualTo (Rational.One));
+ }
+
+ [Test]
+ public void ShouldHaveSubOperation ()
+ {
+ Rational seven20 = Rational.For (7, 20);
+ Rational eleven15 = Rational.For (11, 15);
+
+ Assert.That (seven20 - eleven15, Is.EqualTo (Rational.For (-23, 60)));
+ }
+
+ [Test]
+ public void ShouldInterpretMinusMinValueAsMaxValue ()
+ {
+ Rational maxValue = Rational.For (long.MinValue, -1L);
+ Assert.IsTrue ((long) maxValue == long.MaxValue);
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalThresholdTests.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalThresholdTests.cs
new file mode 100644
index 00000000000..5077aa85fcc
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/RationalThresholdTests.cs
@@ -0,0 +1,91 @@
+//
+// RationalThresholdTests.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.CodeContracts.Static.Analysis.Numerical;
+
+using NUnit.Framework;
+
+namespace Test {
+ [TestFixture]
+ [Timeout (1000)]
+ public class RationalThresholdTests {
+ // threshold contains -oo, 0, +oo
+
+ #region Setup/Teardown
+
+ [SetUp]
+ public void SetUp ()
+ {
+ this.threshold = new RationalThreshold (10);
+ }
+
+ #endregion
+
+ RationalThreshold threshold;
+
+ [Test]
+ public void GetNext_ShouldReturnArgumentIfFound ()
+ {
+ Rational next1 = this.threshold.GetNext (0);
+ Assert.That (next1, Is.EqualTo (Rational.Zero));
+
+ Rational next2 = this.threshold.GetNext (Rational.PlusInfinity);
+ Assert.That (next2, Is.EqualTo (Rational.PlusInfinity));
+ }
+
+ [Test]
+ public void GetNext_ShouldReturnNextValueInDBIfNotFound ()
+ {
+ Rational next3 = this.threshold.GetNext (Rational.MinusOne);
+ Assert.That (next3, Is.EqualTo (Rational.Zero));
+
+ Rational next4 = this.threshold.GetNext (Rational.One);
+ Assert.That (next4, Is.EqualTo (Rational.PlusInfinity));
+ }
+
+ [Test]
+ public void GetPrevious_ShouldReturnArgumentIfFoundInDB ()
+ {
+ Rational prev1 = this.threshold.GetPrevious (0);
+ Assert.That (prev1, Is.EqualTo (Rational.Zero));
+
+ Rational prev2 = this.threshold.GetPrevious (Rational.PlusInfinity);
+ Assert.That (prev2, Is.EqualTo (Rational.PlusInfinity));
+ }
+
+ [Test]
+ public void GetPrevious_ShouldReturnPreviousValueIfNotFoundInDB ()
+ {
+ Rational prev3 = this.threshold.GetPrevious (Rational.One);
+ Assert.That (prev3, Is.EqualTo (Rational.Zero));
+
+ Rational prev4 = this.threshold.GetPrevious (Rational.MinusOne);
+ Assert.That (prev4, Is.EqualTo (Rational.MinusInfinity));
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/SequenceTests.cs b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/SequenceTests.cs
new file mode 100644
index 00000000000..8b10e6790ba
--- /dev/null
+++ b/mcs/class/Mono.CodeContracts/Test/Mono.CodeContracts.Static/SequenceTests.cs
@@ -0,0 +1,80 @@
+//
+// SequenceTests.cs
+//
+// Authors:
+// Alexander Chebaturkin (chebaturkin@gmail.com)
+//
+// Copyright (C) 2012 Alexander Chebaturkin
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.CodeContracts.Static.DataStructures;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.CodeContracts {
+ [TestFixture]
+ public class SequenceTests {
+ readonly Sequence<int> empty = Sequence<int>.Empty;
+
+ [Test]
+ public void FromListShouldCreateSequenceInOrder ()
+ {
+ Sequence<int> seq = Sequence<int>.From (1, 2, 3);
+
+ Assert.That (seq.Length (), Is.EqualTo (3));
+ Assert.That (seq.Head, Is.EqualTo (1));
+ Assert.That (seq.Tail.Head, Is.EqualTo (2));
+ Assert.That (seq.Tail.Tail.Head, Is.EqualTo (3));
+ }
+
+ [Test]
+ public void MultipleConsAreInsertedAsAStack ()
+ {
+ Sequence<int> seq = this.empty.Cons (1).Cons (2).Cons (3);
+
+ Assert.That (seq.Head, Is.EqualTo (3));
+ Assert.That (seq.Tail.Head, Is.EqualTo (2));
+ Assert.That (seq.Tail.Tail.Head, Is.EqualTo (1));
+ }
+
+ [Test]
+ public void ReverseShouldReverse ()
+ {
+ Sequence<int> seq = Sequence<int>.From (1, 2);
+ Sequence<int> reversed = seq.Reverse ();
+
+ Assert.That (reversed.Length (), Is.EqualTo (2));
+ Assert.That (reversed.Head, Is.EqualTo (2));
+ Assert.That (reversed.Tail.Head, Is.EqualTo (1));
+ }
+
+ [Test]
+ public void ShouldHasCountEq1WithOneElement ()
+ {
+ Sequence<int> seq = Sequence<int>.From (5);
+
+ Assert.That (seq.Length (), Is.EqualTo (1));
+ Assert.That (seq.Head, Is.EqualTo (5));
+ Assert.That (seq.Tail, Is.Null);
+ }
+ }
+} \ No newline at end of file