public void ToStringContainsProgrammerName()
        {
            var programmerName = "Joe";
            var interval       = new TestInterval(new DateTime(2000, 1, 1), new TimeSpan(0, 0, 10), new Programmer(programmerName));

            Assert.That(interval.ToString(), Contains.Substring(programmerName));
        }
Beispiel #2
0
        public void Equality_Default()
        {
            var i1 = new TestInterval();
            var i2 = new TestInterval();

            Assert.AreEqual(i1, i2);
        }
Beispiel #3
0
        public void EndTimeIsCorrect()
        {
            var i = new TestInterval {
                StartTime = Today(), Duration = TimeSpan.FromMinutes(1)
            };

            Assert.AreEqual(Today().AddMinutes(1), i.EndTime);
        }
Beispiel #4
0
        public void Equality_KaVEVersion()
        {
            var i1 = new TestInterval {
                KaVEVersion = "a"
            };
            var i2 = new TestInterval {
                KaVEVersion = "a"
            };
            var i3 = new TestInterval {
                KaVEVersion = "b"
            };

            Assert.AreEqual(i1, i2);
            Assert.AreNotEqual(i2, i3);
        }
Beispiel #5
0
        public void Equality_UserId()
        {
            var i1 = new TestInterval {
                UserId = "a"
            };
            var i2 = new TestInterval {
                UserId = "a"
            };
            var i3 = new TestInterval {
                UserId = "b"
            };

            Assert.AreEqual(i1, i2);
            Assert.AreNotEqual(i2, i3);
        }
Beispiel #6
0
        public void Equality_Duration()
        {
            var i1 = new TestInterval {
                Duration = TimeSpan.FromMinutes(1)
            };
            var i2 = new TestInterval {
                Duration = TimeSpan.FromMinutes(1)
            };
            var i3 = new TestInterval {
                Duration = TimeSpan.FromMinutes(2)
            };

            Assert.AreEqual(i1, i2);
            Assert.AreNotEqual(i2, i3);
        }
Beispiel #7
0
        public void Equality_StartTime()
        {
            var i1 = new TestInterval {
                StartTime = Today()
            };
            var i2 = new TestInterval {
                StartTime = Today()
            };
            var i3 = new TestInterval {
                StartTime = Today().AddMinutes(1)
            };

            Assert.AreEqual(i1, i2);
            Assert.AreNotEqual(i2, i3);
        }
Beispiel #8
0
        public void Equality_Project()
        {
            var i1 = new TestInterval {
                Project = "a"
            };
            var i2 = new TestInterval {
                Project = "a"
            };
            var i3 = new TestInterval {
                Project = "b"
            };

            Assert.AreEqual(i1, i2);
            Assert.AreNotEqual(i2, i3);
        }
Beispiel #9
0
        private IEnumerable <T> GetPreOrderIntervals(int start, int length, TestInterval testInterval, IIntervalIntrospector <T> introspector, bool skipZeroLengthIntervals)
        {
            if (root == null || GetEnd(root.MaxEndNode.Value, introspector) < start)
            {
                yield break;
            }

            int end        = start + length;
            var candidates = new Stack <Node>();

            candidates.Push(root);
            while (candidates.Count != 0)
            {
                var currentNode = candidates.Pop();

                // right children's starts will never be to the left of the parent's start
                // so we should consider right subtree
                // only if root's start overlaps with interval's End,
                if (introspector.GetStart(currentNode.Value) <= end)
                {
                    var right = currentNode.Right;
                    if (right != null && GetEnd(right.MaxEndNode.Value, introspector) >= start)
                    {
                        candidates.Push(right);
                    }
                }

                // only if left's maxVal overlaps with interval's start,
                // we should consider left subtree
                var left = currentNode.Left;
                if (left != null && GetEnd(left.MaxEndNode.Value, introspector) >= start)
                {
                    candidates.Push(left);
                }

                if (testInterval(currentNode.Value, start, length, introspector, skipZeroLengthIntervals))
                {
                    yield return(currentNode.Value);
                }
            }
        }
Beispiel #10
0
        private IEnumerable <T> GetInOrderIntervals(int start, int length, TestInterval testInterval, IIntervalIntrospector <T> introspector)
        {
            if (root == null)
            {
                yield break;
            }

            var end = start + length;

            // The bool indicates if this is the first time we are seeing the node.
            var candidates = new Stack <ValueTuple <Node, bool> >();

            candidates.Push(ValueTuple.Create(root, true));

            while (candidates.Count > 0)
            {
                var currentTuple = candidates.Pop();
                var currentNode  = currentTuple.Item1;
                Debug.Assert(currentNode != null);

                var firstTime = currentTuple.Item2;

                if (!firstTime)
                {
                    // We're seeing this node for the second time (as we walk back up the left
                    // side of it).  Now see if it matches our test, and if so return it out.
                    if (testInterval(currentNode.Value, start, length, introspector))
                    {
                        yield return(currentNode.Value);
                    }
                }
                else
                {
                    // First time we're seeing this node.  In order to see the node 'in-order',
                    // we push the right side, then the node again, then the left side.  This
                    // time we mark the current node with 'false' to indicate that it's the
                    // second time we're seeing it the next time it comes around.

                    // right children's starts will never be to the left of the parent's start
                    // so we should consider right subtree only if root's start overlaps with
                    // interval's End,
                    if (introspector.GetStart(currentNode.Value) <= end)
                    {
                        var right = currentNode.Right;
                        if (right != null && GetEnd(right.MaxEndNode.Value, introspector) >= start)
                        {
                            candidates.Push(ValueTuple.Create(right, true));
                        }
                    }

                    candidates.Push(ValueTuple.Create(currentNode, false));

                    // only if left's maxVal overlaps with interval's start, we should consider
                    // left subtree
                    var left = currentNode.Left;
                    if (left != null && GetEnd(left.MaxEndNode.Value, introspector) >= start)
                    {
                        candidates.Push(ValueTuple.Create(left, true));
                    }
                }
            }
        }
Beispiel #11
0
        private IList <T> GetInOrderIntervals(int start, int length, TestInterval testInterval, IIntervalIntrospector <T> introspector, bool skipZeroLengthIntervals)
        {
            List <T> result = null;

            if (root != null && GetEnd(root.MaxEndNode.Value, introspector) >= start)
            {
                int end        = start + length;
                var candidates = new Stack <Node>();

                var currentNode = root;
                while (true)
                {
                    if (currentNode != null)
                    {
                        candidates.Push(currentNode);

                        // only if left's maxVal overlaps with interval's start,
                        // we should consider left subtree
                        var left = currentNode.Left;
                        if (left != null && GetEnd(left.MaxEndNode.Value, introspector) >= start)
                        {
                            currentNode = left;
                            continue;
                        }

                        // current node has no meaning now, set it to null
                        currentNode = null;
                    }

                    if (candidates.Count == 0)
                    {
                        break;
                    }

                    currentNode = candidates.Pop();
                    if (testInterval(currentNode.Value, start, length, introspector, skipZeroLengthIntervals))
                    {
                        result = result ?? new List <T>();
                        result.Add(currentNode.Value);
                    }

                    // right children's starts will never be to the left of the parent's start
                    // so we should consider right subtree
                    // only if root's start overlaps with interval's End,
                    if (introspector.GetStart(currentNode.Value) <= end)
                    {
                        var right = currentNode.Right;
                        if (right != null && GetEnd(right.MaxEndNode.Value, introspector) >= start)
                        {
                            currentNode = right;
                            continue;
                        }
                    }

                    // set to null to get new one from stack
                    currentNode = null;
                }
            }

            return(result ?? SpecializedCollections.EmptyList <T>());
        }