[Test()] // NUnit.Framework.TestAttribute public void Constructing() { List <Interval <int> > intervals_int = new List <Interval <int> >() { new Interval <int>(-3), new Interval <int>(-3, 6), new Interval <int>(0, 3, false, false), new Interval <int>(0, 3, false, true), new Interval <int>(0, 3, true, false), new Interval <int>(0, 3, true, true), new Interval <int>(11, 11, true, true), }; foreach (Interval <int> i in intervals_int) { Console.WriteLine($"interval = {i}"); } List <Interval <double> > intervals_double = new List <Interval <double> >() { new Interval <double>(-10.1, 3.3), new Interval <double>(-10.1, 3.3, false, false), new Interval <double>(-10.1, 3.3, false, true), new Interval <double>(-10.1, 3.3, true, false), new Interval <double>(-10.1, 3.3, true, true), }; foreach (Interval <double> i in intervals_double) { Console.WriteLine($"interval = {i}"); } bool contains = false; interval_datetime_11 = new Interval <DateTime>("[20171011, 2018-01-10]"); contains = interval_datetime_11.Contains(new DateTime(2018, 01, 10)); Assert.AreEqual(contains, true); contains = interval_datetime_11.Contains(new DateTime(2017, 10, 11)); Assert.AreEqual(contains, true); interval_datetime_11 = new Interval <DateTime>("[20171011, 2018-01-10)"); contains = interval_datetime_11.Contains(new DateTime(2018, 01, 10)); Assert.AreEqual(contains, false); contains = interval_datetime_11.Contains(new DateTime(2017, 10, 11)); Assert.AreEqual(contains, true); interval_datetime_11 = new Interval <DateTime>("(20171011, 2018-01-10]"); contains = interval_datetime_11.Contains(new DateTime(2018, 01, 10)); Assert.AreEqual(contains, true); contains = interval_datetime_11.Contains(new DateTime(2017, 10, 11)); Assert.AreEqual(contains, false); interval_datetime_11 = new Interval <DateTime>("(20171011, 2018-01-10)"); contains = interval_datetime_11.Contains(new DateTime(2018, 01, 10)); Assert.AreEqual(contains, false); contains = interval_datetime_11.Contains(new DateTime(2017, 10, 11)); Assert.AreEqual(contains, false); return; }
public static bool Overlaps(this Interval self, Interval other) { return(self.Contains(other.Start) || self.Contains(other.End) || other.Contains(self.Start) || other.Contains(self.End)); }
public void Contains_Infinite() { var interval = new Interval(null, null); Assert.IsTrue(interval.Contains(Instant.MaxValue)); Assert.IsTrue(interval.Contains(Instant.MinValue)); }
public void FullInterval() { Interval full = new Interval(int.MinValue, int.MinValue); Assert.IsFalse(full.IsEmpty); Assert.IsTrue(full.Contains(int.MinValue)); Assert.IsTrue(full.Contains(0)); Assert.IsTrue(full.Contains(int.MaxValue)); }
public void TestContains() { var interval = new Interval(0, 5); Assert.That(interval.Contains(3), Is.True); Assert.That(interval.Contains(0), Is.True); Assert.That(interval.Contains(5), Is.True); Assert.That(interval.Contains(-1), Is.False); }
public void Contains() { Interval interval = new Interval(0, 1, IntervalEndpoint.Closed, IntervalEndpoint.Open); Assert.IsFalse(interval.Contains(-1)); Assert.IsTrue(interval.Contains(0)); Assert.IsTrue(interval.Contains(0.5)); Assert.IsFalse(interval.Contains(1)); Assert.IsFalse(interval.Contains(2)); }
public void OneToThree() { Interval i = new Interval(1, 3); Assert.IsFalse(i.IsEmpty); Assert.IsFalse(i.Contains(0)); Assert.IsTrue(i.Contains(1)); Assert.IsTrue(i.Contains(2)); Assert.IsFalse(i.Contains(3)); }
public void ContainsInstant() { var start = new DateTime(2016, 07, 06); var duration = TimeSpan.FromHours(1); var interval = new Interval(start, duration); Assert.IsFalse(interval.Contains(start.AddHours(-0.5))); Assert.IsTrue(interval.Contains(start.AddHours(0.5))); Assert.IsFalse(interval.Contains(start.AddHours(1.5))); }
public void Contains() { IInterval<int> interval = new Interval<int>(5, 10); Assert.IsTrue(interval.Contains(5)); Assert.IsTrue(interval.Contains(7)); Assert.IsTrue(interval.Contains(10)); Assert.IsFalse(interval.Contains(4)); Assert.IsFalse(interval.Contains(11)); }
public void Can_CheckContainment() { var i = new Interval(0.455, 4.134); const double n1 = 0.0; const double n2 = 5.0; const double n3 = 2.33; Assert.False(i.Contains(n1)); Assert.False(i.Contains(n2)); Assert.True(i.Contains(n3)); }
public void Contains() { IInterval <int> interval = new Interval <int>(5, 10); Assert.IsTrue(interval.Contains(5)); Assert.IsTrue(interval.Contains(7)); Assert.IsTrue(interval.Contains(10)); Assert.IsFalse(interval.Contains(4)); Assert.IsFalse(interval.Contains(11)); }
public void ContainsInterval() { var start = new DateTime(2016, 07, 06); var duration = TimeSpan.FromHours(1); var interval = new Interval(start, duration); Assert.IsTrue(interval.Contains(new Interval(start.AddSeconds(1), TimeSpan.FromSeconds(1)))); Assert.IsFalse(interval.Contains(new Interval(start.AddSeconds(-1), TimeSpan.FromSeconds(2)))); Assert.IsFalse(interval.Contains(new Interval(start.AddSeconds(-2), TimeSpan.FromSeconds(1)))); Assert.IsFalse(interval.Contains(new Interval(start + duration + TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)))); }
public void ContainsValue() { var epsilon = 1E-12; Interval x; x = new Interval(); Assert.IsTrue(x.Contains(0)); Assert.IsFalse(x.Contains(0 + 2 * epsilon)); x = new Interval(-1, 1, epsilon); Assert.IsTrue(x.Contains(0)); Assert.IsTrue(x.Contains(-1 - epsilon / 2)); Assert.IsFalse(x.Contains(3)); Assert.IsFalse(x.Contains(1 + 2 * epsilon)); }
/// <summary> /// Returns a new time series which is a view of a subset of the current series. /// <para> /// The new series has begin and end indexes which correspond to the bounds of the sub-set into the full series.<br/> /// The tick of the series are shared between the original time series and the returned one (i.e. no copy). /// </para> /// </summary> /// <param name="beginIndex"> the begin index (inclusive) of the time series </param> /// <param name="duration"> the duration of the time series </param> /// <returns> a constrained <seealso cref="TimeSeries"/> which is a sub-set of the current series </returns> public virtual TimeSeries Subseries(int beginIndex, Period duration) { // Calculating the sub-series interval var tickEndTime = GetTick(beginIndex).EndTime; var beginInterval = Instant.FromDateTimeUtc(tickEndTime.InUtc().ToDateTimeUtc()); var endInterval = Instant.FromDateTimeUtc(tickEndTime.Plus(duration).InUtc().ToDateTimeUtc()); var subseriesInterval = new Interval(beginInterval, endInterval); // Checking ticks belonging to the sub-series (starting at the provided index) var subseriesNbTicks = 0; for (var i = beginIndex; i <= _endIndex; i++) { // For each tick... var tickTime = Instant.FromDateTimeUtc(GetTick(i).EndTime.InUtc().ToDateTimeUtc()); if (!subseriesInterval.Contains(tickTime)) { // Tick out of the interval break; } // Tick in the interval // --> Incrementing the number of ticks in the subseries subseriesNbTicks++; } return(Subseries(beginIndex, beginIndex + subseriesNbTicks - 1)); }
/// <summary> /// Populate another polycurve with the portions of this one which lie within /// the specified subDomain /// </summary> /// <param name="subDomain"></param> /// <param name="result"></param> private void PopulateWithSubCurves(Interval subDomain, PolyCurve result) { double segCount = SegmentCount; double segStart = 0; foreach (Curve subCrv in SubCurves) { double subSC = subCrv.SegmentCount; double segEnd = segStart + subSC; Interval crvDom = new Interval(segStart / segCount, segEnd / segCount); if (subDomain.Contains(crvDom)) { result.Add(subCrv.Duplicate()); } else if (subDomain.Overlaps(crvDom)) { Curve subSubCrv = subCrv.Extract(crvDom.ParameterOf(subDomain.Overlap(crvDom))); if (subSubCrv != null) { result.Add(subSubCrv); } } segStart = segEnd; } }
public void Contains_EmptyInterval_EndOfTime() { var instant = Instant.MaxValue; var interval = new Interval(instant, instant); Assert.IsTrue(interval.Contains(instant)); }
private static void Contains <T>(bool expect, T l, T r, T value, bool closed) where T : IComparable <T> { var interval = new Interval <T>(l, r); Assert.AreEqual(expect, interval.Contains(value, closed)); }
protected ComparerResult CompareDecimals(Interval interval, decimal actual) { if (interval.Contains(actual)) return ComparerResult.Equality; return new ComparerResult(interval.ToString()); }
public void AddRange(char lo, char hi) { Interval i = new Interval(lo, hi); if (ignore) { if (upper_case_characters.Intersects(i)) { Interval i2; if (i.low < upper_case_characters.low) { i2 = new Interval(upper_case_characters.low + 32, i.high + 32); i.high = upper_case_characters.low - 1; } else { i2 = new Interval(i.low + 32, upper_case_characters.high + 32); i.low = upper_case_characters.high + 1; } intervals.Add(i2); } else if (upper_case_characters.Contains(i)) { i.high += 32; i.low += 32; } } intervals.Add(i); }
public void Contains_EmptyInterval() { var instant = NodaConstants.UnixEpoch; var interval = new Interval(instant, instant); Assert.IsFalse(interval.Contains(instant)); }
// Complete the arrayManipulation function below. static long arrayManipulation(int n, int m, int[][] queries) { // approach: array with 'n' items will not be created, instead only some processing over the 'm' queries will be made // rational: O(m^2) is potentially faster than O(n*m) // more on "https://github.com/franciscoraphael/HackerRank/blob/master/ArrayManipulation_approach_Om2.cs" long max = 0; ListNode processedIntervalsHead = new ListNode(new Interval(1, n, 0)); for (int i = 0; i < m; i++) { Interval processing = new Interval(queries[i][0], queries[i][1], queries[i][2]); for (ListNode processedNode = processedIntervalsHead; processedNode != null; processedNode = processedNode.Next) { Interval processed = processedNode.Value; if (processing.End < processed.Begin) { break; } if (processing.Begin > processed.End) { continue; } Interval intersection = processing.Intersection(processed); // intersection already have as its value the sum of each given Interval if (intersection == null) { continue; } max = GetMaxBetween(max, intersection.Value); if (processing.Contains(processed)) // means that 'intersection' and 'processed' have the same positions range { processedNode.Value = intersection; } else { List <Interval> resultantIntervals = processed.Except(processing); int positionToInsert = (intersection.Begin < resultantIntervals[0].Begin) ? 0 : 1; resultantIntervals.Insert(positionToInsert, intersection); processedNode.Value = resultantIntervals[0]; processedNode.Next = new ListNode(resultantIntervals[1], processedNode.Next); processedNode = processedNode.Next; if (resultantIntervals.Count > 2) { processedNode.Next = new ListNode(resultantIntervals[2], processedNode.Next); processedNode = processedNode.Next; } } } } return(max); }
private bool Overlaps(Interval interval, Interval resInterval) { if (interval.Contains(resInterval.Start)) return true; if (interval.Contains(resInterval.End)) return true; if (resInterval.Contains(interval.Start)) return true; if (resInterval.Contains(interval.End)) return true; return false; }
/// <summary> /// brings the first leaf which interval was hit and the delegate is happy with the object /// </summary> /// <param name="point"></param> /// <param name="hitTestFordoubleDelegate"></param> /// <returns></returns> public IntervalNode <TData> FirstHitNode(double point, Func <double, TData, HitTestBehavior> hitTestFordoubleDelegate) { if (interval.Contains(point)) { if (IsLeaf) { if (hitTestFordoubleDelegate != null) { return(hitTestFordoubleDelegate(point, UserData) == HitTestBehavior.Stop ? this : null); } return(this); } return(Left.FirstHitNode(point, hitTestFordoubleDelegate) ?? Right.FirstHitNode(point, hitTestFordoubleDelegate)); } return(null); }
public void Contains() { Instant start = Instant.FromUtc(2019, 1, 1, 15, 25, 48); Instant end = Instant.FromUtc(2019, 1, 1, 16, 25, 48); Interval interval = new Interval(start, end); Assert.True(Snippet.For(interval.Contains(Instant.FromUtc(2019, 1, 1, 15, 50, 50)))); }
public void Contains_EmptyInterval_MaxValue() { var instant = Instant.MaxValue; var interval = new Interval(instant, instant); // This would have been true under Noda Time 1.x Assert.IsFalse(interval.Contains(instant)); }
public static void Step3() { Interval i = new Interval(); i.a = 41; i.b = 43; Console.WriteLine(i.Contains(50)); }
public void Contains_TwoIntervals() { var interval1 = new Interval(1, 10); var interval2 = new Interval(5, 6); var observedResult = interval1.Contains(interval2); Assert.True(observedResult); }
public void TestContains() { var int1 = new Interval(3, 6); var int2 = new Interval(4, 5); Assert.That(int1.Contains(int2), Is.True); int2 = new Interval(6, 7); Assert.That(int1.Contains(int2), Is.False); int2 = new Interval(7, 8); Assert.That(int1.Contains(int2), Is.False); int2 = new Interval(5, 6.1); Assert.That(int1.Contains(int2), Is.False); int2 = new Interval(2, 3); Assert.That(int1.Contains(int2), Is.False); int2 = new Interval(1.9, 4); Assert.That(int1.Contains(int2), Is.False); int2 = new Interval(1, 2); Assert.That(int1.Contains(int2), Is.False); }
public void TestEmptyInterval() { var empty = new Interval(); var a = new Interval(-1, 3); Contract.Assert(empty.DisjointFrom(empty)); Contract.Assert(!empty.OverlapsWith(empty)); Contract.Assert(!empty.Contains(empty)); }
public IObservable <IFile> RecordingsBetween(Interval interval) { var inside = fileSystem.GetAllFiles() .SelectMany(async file => new { Interval = await file.GetInterval(), File = file }) .Where(x => x.Interval != null && interval.Contains(x.Interval.Value)) .Select(x => x.File); return(inside); }
public void Contains(string candidateText, bool expectedResult) { var start = Instant.FromUtc(2000, 1, 1, 0, 0); var end = Instant.FromUtc(2020, 1, 1, 0, 0); var interval = new Interval(start, end); var candidate = InstantPattern.ExtendedIsoPattern.Parse(candidateText).Value; Assert.AreEqual(expectedResult, interval.Contains(candidate)); }
protected ComparerResult CompareDecimals(Interval interval, decimal actual) { if (interval.Contains(actual)) { return(ComparerResult.Equality); } return(new ComparerResult(interval.ToString())); }
public void TestEmptyWithOtherInterval() { var empty = new Interval(); var other = new Interval(-1, 3); Contract.Assert(other.DisjointFrom(empty)); Contract.Assert(!other.OverlapsWith(empty)); Contract.Assert(other.Contains(empty)); Contract.Assert(!empty.Contains(other)); }
public void TestContainment() { var a = new Interval(0, 3); var b = new Interval(-1, 3, endInclusive: true); Contract.Assert(a.OverlapsWith(b)); Contract.Assert(!a.DisjointFrom(b)); Contract.Assert(!a.Contains(b)); Contract.Assert(b.Contains(a)); }
public void ContainsTest_Bound_ExclusiveOnUpperExclusive() { int lowerBound = 2; BoundType lowerBoundType = BoundType.Inclusive; int upperBound = 5; BoundType upperBoundType = BoundType.Exclusive; Interval<int> target = new Interval<int>(lowerBound, lowerBoundType, upperBound, upperBoundType); IBound<int> bound = new Bound<int>(5, BoundType.Exclusive); bool expected = true; bool actual; actual = target.Contains(bound); Assert.AreEqual(expected, actual); }
public void AtLeast() { var list = new int[] { 1, 2, 3 }; Assert.True(list.AtLeast(2)); Assert.True(list.AtLeast(3)); Assert.False(list.AtLeast(4)); Assert.True(list.AtLeast(2, i => i < 3)); Assert.False(list.AtLeast(3, i => i < 3)); // Should work for infinite sequences as well Assert.True(1.Inc().AtLeast(2)); var interval = new Interval<int>(3, 7); Assert.True(1.Inc().AtLeast(2, i => interval.Contains(i))); }
/// <summary> /// Liefert alle Intersections im Bogenlängenintervall intervall /// </summary> /// <param name="interval">Bogenlängeintervall in dem die Intersections liegen sollen</param> /// <returns>Eine Liste von Intersections, die im Bogenlängenintervall intervall liegen</returns> public List<SpecificIntersection> GetIntersectionsWithinArcLength(Interval<double> interval) { List<SpecificIntersection> toReturn = new List<SpecificIntersection>(); foreach (Intersection i in this.intersections) { if (this == i._aConnection) { if (interval.Contains(i.aArcPosition)) { toReturn.Add(new SpecificIntersection(this, i)); } } else { if (interval.Contains(i.bArcPosition)) { toReturn.Add(new SpecificIntersection(this, i)); } } } return toReturn; }
/// <summary> /// Returns all intersections within the given interval. Returned List is guaranteed to be sorted in ascending order. /// </summary> /// <param name="interval">Arc length interval to search for.</param> /// <returns>A list of all intersections within the given interval, guaranteed to be sorted in ascending order.</returns> public List<SpecificIntersection> GetSortedIntersectionsWithinArcLength(Interval<double> interval) { // possibly redundant to the version above, but I don't want to trust the iterator. List<SpecificIntersection> toReturn = new List<SpecificIntersection>(); LinkedListNode<Intersection> lln = intersections.First; while (lln != null) { if (interval.Contains(lln.Value.GetMyArcPosition(this))) { toReturn.Add(new SpecificIntersection(this, lln.Value)); } lln = lln.Next; } return toReturn; }
/// <summary> /// Liefert alle Intersections im Zeitintervall interval /// </summary> /// <param name="interval">Intervall in dem nach Intersections gesucht werden soll</param> /// <returns>Eine Liste von Intersections die im Zeitintervall interval auf dieser Linie vorkommen</returns> public List<Intersection> GetIntersectionsWithinTime(Interval<double> interval) { List<Intersection> toReturn = new List<Intersection>(); foreach (Intersection i in this.intersections) { if (this == i._aConnection) { if (interval.Contains(i._aTime)) { toReturn.Add(i); } } else { if (interval.Contains(i._bTime)) { toReturn.Add(i); } } } return toReturn; }
public void IntervalContainment(int s1, int e1, int s2, int e2, bool expected) { Interval<int> a = new Interval<int>(s1, e1); Interval<int> b = new Interval<int>(s2, e2); if (expected) { Assert.True(a.Contains(b)); Assert.False(b.Contains(a)); } else Assert.False(a.Contains(b)); }
private void CheckContains(Interval interval1, Interval interval2, bool expextedResult) { Assert.AreEqual(interval1.Contains(interval2), expextedResult); }
public void IntervalContainment(int s1, int e1, int v, bool expected) { Interval<int> a = new Interval<int>(s1, e1); if (expected) Assert.True(a.Contains(v)); else Assert.False(a.Contains(v)); }
public void ContainsTest_Key_TooLow() { int lowerBound = 2; BoundType lowerBoundType = BoundType.Inclusive; int upperBound = 5; BoundType upperBoundType = BoundType.Inclusive; Interval<int> target = new Interval<int>(lowerBound, lowerBoundType, upperBound, upperBoundType); int key = 1; bool expected = false; bool actual; actual = target.Contains(key); Assert.AreEqual(expected, actual); }