Пример #1
0
        public void ReadAllOpenedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            var expectedAnnotations = new List <Annotation>();

            while (!annotator.IsEof)
            {
                expectedAnnotations.Add(annotator.ReadNext());
            }
            Assert.IsTrue(annotator.IsEof);
            annotator.Seek(Time.Zero);

            var annotations = annotator.ReadAll();

            Assert.AreEqual(expectedAnnotations, annotations);
            annotator.Close();

            // Reopening
            annotator.Open("data/100s");
            annotations = annotator.ReadAll();
            Assert.AreEqual(expectedAnnotations, annotations);
            annotator.Close();
        }
Пример #2
0
        public static void UsingAnnotatorClass3()
        {
            Console.WriteLine("exgetann Using Annotator.IsEof and Annotator.ReadNext method.");
            var annotator = new Annotator();

            annotator.Name = "atr";
            annotator.Stat = Stat.Read;

            annotator.Open("data/100s");

            while (!annotator.IsEof)
            {
                var annotation = annotator.ReadNext();
                Console.WriteLine(annotation);
            }

            Console.WriteLine("Seeking to 00:50:00");
            annotator.Seek(Time.Parse("00:50:00.000"));
            while (!annotator.IsEof)
            {
                var annotation = annotator.ReadNext();
                Console.WriteLine(annotation);
            }

            annotator.Dispose();
        }
Пример #3
0
        public void SeekInvalidTime()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll();
            var maxTime = expectedAllAnnotations[expectedAllAnnotations.Count - 1].Time;

            annotator.Seek(Time.Zero);

            Time invalidTime = (maxTime + 60); // + 60 seconds

            annotator.Seek(invalidTime);
        }
Пример #4
0
        public void IsEofTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");

            Assert.IsFalse(annotator.IsEof);

            // Reading some data
            annotator.ReadNext();
            Assert.IsFalse(annotator.IsEof);

            // Reading all available annotations.
            annotator.ReadAll();
            Assert.IsTrue(annotator.IsEof);

            // Seeking to the beginning.
            annotator.Seek(Time.Zero);
            Assert.IsFalse(annotator.IsEof);

            annotator.ReadAll();
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);
            // Reopening
            annotator.Open("data/100s");
            Assert.IsFalse(annotator.IsEof);
            annotator.Close();
        }
Пример #5
0
        public void ReadNextTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll();

            annotator.Seek(Time.Zero);
            var annotations = new List <Annotation>();

            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            Assert.AreEqual(expectedAllAnnotations, annotations);
            Assert.IsTrue(annotator.IsEof);

            try
            {
                annotator.ReadNext();
                Assert.Fail("InvalidOperationException should have been thrown.");
            }
            catch (InvalidOperationException) // end of file reached
            {
            }
        }
Пример #6
0
        public void SeekTimeUnopenedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Seek(Time.Zero);
        }
Пример #7
0
        public void SeekCountUnopenedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Seek(3);
        }
Пример #8
0
        public void SeekTimeTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll();
            var maxTime  = expectedAllAnnotations[expectedAllAnnotations.Count - 1].Time;
            int midIndex = expectedAllAnnotations.Count / 2;

            var midTime = expectedAllAnnotations[midIndex].Time;

            // Seek to zero
            Assert.IsTrue(annotator.IsEof);
            annotator.Seek(Time.Zero);
            Assert.IsFalse(annotator.IsEof);
            Assert.AreEqual(expectedAllAnnotations, annotator.ReadAll()); // all annotations are there.

            annotator.Seek(Time.Zero);
            annotator.Seek(maxTime);
            Assert.IsFalse(annotator.IsEof); // not the end of file, we still have to read another annotation.

            Assert.AreEqual(expectedAllAnnotations[expectedAllAnnotations.Count - 1], annotator.ReadNext());
            Assert.IsTrue(annotator.IsEof);

            annotator.Seek(Time.Zero);
            annotator.Seek(midTime);
            Assert.IsFalse(annotator.IsEof);

            var annotations = new List <Annotation>();
            var annotation  = annotator.ReadNext();

            annotations.Add(annotation);
            Assert.AreEqual(annotation, expectedAllAnnotations[midIndex]);

            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            Assert.AreEqual(expectedAllAnnotations.Count - midIndex, annotations.Count);
            expectedAllAnnotations.RemoveRange(0, midIndex);
            Assert.AreEqual(expectedAllAnnotations, annotations);
        }
Пример #9
0
        public void SeekCountNegativeValue()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            annotator.Seek(-1);
        }
Пример #10
0
        public void ReadNextCountTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");

            // Gets the total number of annotations available in the current annotator file.
            var availableAnnotationsCount = annotator.ReadAll().Count;

            // Reset the pointer to the first annotation.
            annotator.Seek(Time.Zero);

            // Read all using ReadNext(Count)
            var readCount = annotator.ReadNext(availableAnnotationsCount).Count;

            Assert.AreEqual(availableAnnotationsCount, readCount);
            Assert.IsTrue(annotator.IsEof);

            // Cant read when the
            readCount = annotator.ReadNext(1).Count;
            Assert.AreEqual(0, readCount);

            // Seeking to the middle of the file.
            var middle = availableAnnotationsCount / 2;

            annotator.Seek(Time.Zero);
            annotator.Seek(middle);

            readCount = annotator.ReadNext(availableAnnotationsCount).Count;
            Assert.AreEqual(availableAnnotationsCount - middle, readCount);

            Assert.IsTrue(annotator.IsEof);

            // Testing boundaries
            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(1).Count;
            Assert.AreEqual(1, readCount);

            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(availableAnnotationsCount + 1).Count;
            Assert.AreEqual(availableAnnotationsCount, readCount);

            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(int.MaxValue).Count;
            Assert.AreEqual(availableAnnotationsCount, readCount);

            // Testing invalid values.
            try
            {
                annotator.ReadNext(-1);
                Assert.Fail("ArgumentOutOfRangeException should have been thrown.");
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            annotator.Close();
        }
Пример #11
0
        public void SeekCountTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll();
            var maxCount        = expectedAllAnnotations.Count;
            int midCount        = expectedAllAnnotations.Count / 2;
            var firstAnnotation = expectedAllAnnotations[0];
            var lastAnnotation  = expectedAllAnnotations[expectedAllAnnotations.Count - 1];

            annotator.Seek(Time.Zero);

            annotator.Seek(0);
            Assert.AreEqual(firstAnnotation, annotator.ReadNext());
            Assert.IsFalse(annotator.IsEof);

            annotator.Seek(Time.Zero);

            annotator.Seek(maxCount - 1);
            Assert.AreEqual(lastAnnotation, annotator.ReadNext());
            Assert.IsTrue(annotator.IsEof);

            annotator.Seek(Time.Zero);

            var annotations = new List <Annotation>();

            annotator.Seek(midCount);
            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            expectedAllAnnotations.RemoveRange(0, midCount);
            Assert.AreEqual(expectedAllAnnotations, annotations);
        }
        public void ReadAllOpenedAnnotatorTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAnnotations = new List<Annotation>();

            while (!annotator.IsEof)
            {
                expectedAnnotations.Add(annotator.ReadNext());
            }
            Assert.IsTrue(annotator.IsEof);
            annotator.Seek(Time.Zero);

            var annotations = annotator.ReadAll();
            Assert.AreEqual(expectedAnnotations, annotations);
            annotator.Close();

            // Reopening
            annotator.Open("data/100s");
            annotations = annotator.ReadAll();
            Assert.AreEqual(expectedAnnotations, annotations);
            annotator.Close();
        }
 public void SeekCountNegativeValue()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/100s");
     annotator.Seek(-1);
 }
        public void SeekCountTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll().ToList();
            var maxCount = expectedAllAnnotations.Count;
            int midCount = expectedAllAnnotations.Count / 2;
            var firstAnnotation = expectedAllAnnotations[0];
            var lastAnnotation = expectedAllAnnotations[expectedAllAnnotations.Count - 1];

            annotator.Seek(Time.Zero);

            annotator.Seek(0);
            Assert.AreEqual(firstAnnotation, annotator.ReadNext());
            Assert.IsFalse(annotator.IsEof);

            annotator.Seek(Time.Zero);

            annotator.Seek(maxCount - 1);
            Assert.AreEqual(lastAnnotation, annotator.ReadNext());
            Assert.IsTrue(annotator.IsEof);

            annotator.Seek(Time.Zero);

            var annotations = new List<Annotation>();
            annotator.Seek(midCount);
            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            expectedAllAnnotations.RemoveRange(0, midCount);
            Assert.AreEqual(expectedAllAnnotations, annotations);
        }
        public void ReadNextTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll();

            annotator.Seek(Time.Zero);
            var annotations = new List<Annotation>();
            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            Assert.AreEqual(expectedAllAnnotations, annotations);
            Assert.IsTrue(annotator.IsEof);

            try
            {
                annotator.ReadNext();
                Assert.Fail("InvalidOperationException should have been thrown.");
            }
            catch (InvalidOperationException) // end of file reached
            {
            }
        }
        public void IsEofTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };

            annotator.Open("data/100s");

            Assert.IsFalse(annotator.IsEof);

            // Reading some data
            annotator.ReadNext();
            Assert.IsFalse(annotator.IsEof);

            // Reading all available annotations.
            annotator.ReadAll().ToList(); // force a loop over the enumerator.
            Assert.IsTrue(annotator.IsEof);

            // Seeking to the beginning.
            annotator.Seek(Time.Zero);
            Assert.IsFalse(annotator.IsEof);

            annotator.ReadAll();
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);
            // Reopening
            annotator.Open("data/100s");
            Assert.IsFalse(annotator.IsEof);
            annotator.Close();
        }
 public void SeekTimeUnopenedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Seek(Time.Zero);
 }
        public void SeekTimeTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll().ToList();
            var maxTime = expectedAllAnnotations[expectedAllAnnotations.Count - 1].Time;
            int midIndex = expectedAllAnnotations.Count/2;

            var midTime = expectedAllAnnotations[midIndex].Time;

            // Seek to zero
            Assert.IsTrue(annotator.IsEof);
            annotator.Seek(Time.Zero);
            Assert.IsFalse(annotator.IsEof);
            Assert.AreEqual(expectedAllAnnotations, annotator.ReadAll()); // all annotations are there.

            annotator.Seek(Time.Zero);
            annotator.Seek(maxTime);
            Assert.IsFalse(annotator.IsEof); // not the end of file, we still have to read another annotation.

            Assert.AreEqual(expectedAllAnnotations[expectedAllAnnotations.Count - 1], annotator.ReadNext());
            Assert.IsTrue(annotator.IsEof);

            annotator.Seek(Time.Zero);
            annotator.Seek(midTime);
            Assert.IsFalse(annotator.IsEof);

            var annotations = new List<Annotation>();
            var annotation = annotator.ReadNext();
            annotations.Add(annotation);
            Assert.AreEqual(annotation, expectedAllAnnotations[midIndex]);

            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            Assert.AreEqual(expectedAllAnnotations.Count - midIndex, annotations.Count);
            expectedAllAnnotations.RemoveRange(0, midIndex);
            Assert.AreEqual(expectedAllAnnotations, annotations);
        }
        public void SeekInvalidTime()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll().ToList();
            var maxTime = expectedAllAnnotations[expectedAllAnnotations.Count - 1].Time;

            annotator.Seek(Time.Zero);

            Time invalidTime = (maxTime + 60); // + 60 seconds
            annotator.Seek(invalidTime);
        }
 public void SeekCountUnopenedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Seek(3);
 }
Пример #21
0
        public static void UsingAnnotatorClass3()
        {
            Console.WriteLine("exgetann Using Annotator.IsEof and Annotator.ReadNext method.");
            var annotator = new Annotator();
            annotator.Name = "atr";
            annotator.Stat = Stat.Read;

            annotator.Open("data/100s");

            while (!annotator.IsEof)
            {
                var annotation = annotator.ReadNext();
                Console.WriteLine(annotation);
            }

            Console.WriteLine("Seeking to 00:50:00");
            annotator.Seek(Time.Parse("00:50:00.000"));
            while (!annotator.IsEof)
            {
                var annotation = annotator.ReadNext();
                Console.WriteLine(annotation);
            }

            annotator.Dispose();
        }
        public void ReadNextCountTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");

            // Gets the total number of annotations available in the current annotator file.
            var availableAnnotationsCount = annotator.ReadAll().Count();
            // Reset the pointer to the first annotation.
            annotator.Seek(Time.Zero);

            // Read all using ReadNext(Count)
            var readCount = annotator.ReadNext(availableAnnotationsCount).Count();
            Assert.AreEqual(availableAnnotationsCount, readCount);
            Assert.IsTrue(annotator.IsEof);

            // Cant read when the
            readCount = annotator.ReadNext(1).Count();
            Assert.AreEqual(0, readCount);

            // Seeking to the middle of the file.
            var middle = availableAnnotationsCount / 2;
            annotator.Seek(Time.Zero);
            annotator.Seek(middle);

            readCount = annotator.ReadNext(availableAnnotationsCount).Count();
            Assert.AreEqual(availableAnnotationsCount - middle, readCount);

            Assert.IsTrue(annotator.IsEof);

            // Testing boundaries
            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(1).Count();
            Assert.AreEqual(1, readCount);

            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(availableAnnotationsCount + 1).Count();
            Assert.AreEqual(availableAnnotationsCount, readCount);

            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(int.MaxValue).Count();
            Assert.AreEqual(availableAnnotationsCount, readCount);

            // Testing invalid values.
            try
            {
                annotator.ReadNext(-1).ToList(); // force loop
                Assert.Fail("ArgumentOutOfRangeException should have been thrown.");
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            annotator.Close();
        }