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();
        }
        public void NumberTest()
        {
            var annotator1 = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator1.Open("data/100s");
            Assert.AreEqual(0, annotator1.Number);

            var annotator2 = new Annotator {
                Name = "hrv", Stat = Stat.Read
            };

            annotator2.Open("data/100s");
            Assert.AreEqual(0, annotator1.Number);
            Assert.AreEqual(1, annotator2.Number);

            annotator1.Close();
            Assert.AreEqual(-1, annotator1.Number);
            Assert.AreEqual(0, annotator2.Number);

            annotator1.Open("data/100s");
            Assert.AreEqual(0, annotator2.Number);
            Assert.AreEqual(1, annotator1.Number);
            Annotator.CloseAll();

            Assert.AreEqual(-1, annotator1.Number);
            Assert.AreEqual(-1, annotator2.Number);
        }
        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 OpenOpenedAnnotator()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            annotator.Open("data/100s");
        }
Beispiel #5
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 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 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 IsEofClosedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/100s");
     annotator.Close();
     var isEof = annotator.IsEof; // throws the exception.
 }
        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();
        }
        public void OpenInvalidRecordTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

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

            annotator.Close();
        }
        public void OpenIllegalStatAnotator()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.AhaRead
            };

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

            annotator.Open("some inexistent record");
        }
        public void SeekCountNegativeValue()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

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

            annotator.Open("data/100s");
            annotator.Close();
            var isEof = annotator.IsEof; // throws the exception.
        }
Beispiel #16
0
        public void ReadAllClosedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            annotator.Close();
            annotator.ReadAll().ToList(); // force a loop
        }
        public void ReadAllClosedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            annotator.Close();
            var annotations = annotator.ReadAll();
        }
 public static void UsingAnnotatorClass1()
 {
     Console.WriteLine("exgetann Using Annotator.ReadAll method");
     var annotator = new Annotator();
     annotator.Name = "atr";
     annotator.Stat = Stat.Read;
     annotator.Open("data/100s");
     foreach (var annotation in annotator.ReadAll())
     {
         Console.WriteLine(annotation.ToString());
     }
     annotator.Close();
 }
Beispiel #19
0
        public static void UsingAnnotatorClass1()
        {
            Console.WriteLine("exgetann Using Annotator.ReadAll method");
            var annotator = new Annotator();

            annotator.Name = "atr";
            annotator.Stat = Stat.Read;
            annotator.Open("data/100s");
            foreach (var annotation in annotator.ReadAll())
            {
                Console.WriteLine(annotation.ToString());
            }
            annotator.Close();
        }
        public void OpenClose1AnnotatorValidRecordTest()
        {
            // Valid annotator

            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };


            // ****************************
            // Keeping old annotators open.
            // ****************************

            annotator.Open("data/100s");
            Assert.IsTrue(annotator.IsOpen);
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);

            // Reopening the same annotator.
            annotator.Open("data/100s");
            Assert.IsTrue(annotator.IsOpen);
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);
        }
        public static void UsingAnnotatorClass2()
        {
            Console.WriteLine("exgetann Using Annotator.ReadNext(int count) method, reading 50 annotation.");
            var annotator = new Annotator();
            annotator.Name = "atr";
            annotator.Stat = Stat.Read;
            annotator.Open("data/100s");

            foreach (var annotation in annotator.ReadNext(50))
            {
                Console.WriteLine(annotation.ToString());
            }

            annotator.Close();
        }
        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);
        }
Beispiel #23
0
        public static void UsingAnnotatorClass2()
        {
            Console.WriteLine("exgetann Using Annotator.ReadNext(int count) method, reading 50 annotation.");
            var annotator = new Annotator();

            annotator.Name = "atr";
            annotator.Stat = Stat.Read;
            annotator.Open("data/100s");

            foreach (var annotation in annotator.ReadNext(50))
            {
                Console.WriteLine(annotation.ToString());
            }

            annotator.Close();
        }
        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);
        }
        public void OpenNAnnotatorCloseOldValidRecord()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            Assert.IsTrue(annotator.IsOpen);

            var annotator2 = new Annotator {
                Name = "hrv", Stat = Stat.Read
            };

            annotator2.Open("data/100s", false);
            Assert.IsFalse(annotator.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            annotator2.Close();
        }
Beispiel #26
0
        private static void UsingWrapperClasses()
        {
            var a = new Annotator();

            a.Stat = Stat.Read;
            a.Name = "atr";
            a.Open("data/100s");

            while (!a.IsEof)
            {
                var annot = a.ReadNext();
                Console.WriteLine("{0} ({1}) {2} {3} {4} {5} {6}",
                                  annot.Time.ToString(),
                                  annot.Time,
                                  annot.Type.ToString(), // or .String
                                  annot.SubType,
                                  annot.ChannelNumber,
                                  annot.AnnotatorNumber,
                                  (!string.IsNullOrEmpty(annot.Aux)) ? annot.Aux + 1 : "");
            }
        }
        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 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 OpenNAnnotatorCloseOldValidRecord()
        {
            var annotator = new Annotator {Name = "atr", Stat = Stat.Read};
            annotator.Open("data/100s");
            Assert.IsTrue(annotator.IsOpen);

            var annotator2 = new Annotator {Name = "hrv", Stat = Stat.Read};
            annotator2.Open("data/100s", false);
            Assert.IsFalse(annotator.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            annotator2.Close();
        }
        public void OpenNAnnotatorValidRecord()
        {
            var annotator1 = new Annotator { Name = "atr", Stat = Stat.Read };

            // Opening another annotator without closing the old annotator
            annotator1.Open("data/100s");
            Assert.IsTrue(annotator1.IsOpen);
            var expectedAnnotations1 = annotator1.ReadAll().ToList();

            var annotator2 = new Annotator { Name = "hrv", Stat = Stat.Read };
            annotator2.Open("data/100s");
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);
            var expectedAnnotations2 = annotator2.ReadAll().ToList();

            // Closing the first annotator and keeping the second one
            annotator1.Close();
            Assert.IsFalse(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            var annotations2 = annotator2.ReadAll();
            Assert.AreEqual(expectedAnnotations2, annotations2);

            // Reopening the first annotator, this time it should have the 1 number
            annotator1.Open("data/100s");
            var annotations1 = annotator1.ReadAll();
            Assert.AreEqual(expectedAnnotations1, annotations1);

            annotator1.Close();
            annotator2.Close();
            Assert.IsFalse(annotator1.IsOpen);
            Assert.IsFalse(annotator2.IsOpen);

            // Reopening in the same order
            annotator1.Open("data/100s"); //0
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsFalse(annotator2.IsOpen);

            annotator2.Open("data/100s"); //1
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            // Reading Some data
            annotations1 = annotator1.ReadAll();  // 0
            Assert.AreEqual(expectedAnnotations1, annotations1);

            annotations2 = annotator2.ReadAll(); // 1
            Assert.AreEqual(expectedAnnotations2, annotations2);

            annotator1.Close();
            annotator2.Close();

            // reopening in an inversed order
            annotator2.Open("data/100s"); //0
            Assert.IsTrue(annotator2.IsOpen);
            Assert.IsFalse(annotator1.IsOpen);

            annotator1.Open("data/100s"); //1
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            // Reading Some data
            annotations1 = annotator1.ReadAll();  // 0
            Assert.AreEqual(expectedAnnotations1, annotations1);

            annotations2 = annotator2.ReadAll(); // 1
            Assert.AreEqual(expectedAnnotations2, annotations2);

            annotator1.Close();
            annotator2.Close();
        }
        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 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 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 OpenIllegalStatAnotator()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.AhaRead };
     annotator.Open("data/100s");
 }
 public void OpenInvalidRecordTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/invalid");
 }
 public void SeekCountNegativeValue()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/100s");
     annotator.Seek(-1);
 }
        public void OpenNAnnotatorValidRecord()
        {
            var annotator1 = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            // Opening another annotator without closing the old annotator
            annotator1.Open("data/100s");
            Assert.IsTrue(annotator1.IsOpen);
            var expectedAnnotations1 = annotator1.ReadAll();

            var annotator2 = new Annotator {
                Name = "hrv", Stat = Stat.Read
            };

            annotator2.Open("data/100s");
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);
            var expectedAnnotations2 = annotator2.ReadAll();

            // Closing the first annotator and keeping the second one
            annotator1.Close();
            Assert.IsFalse(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            var annotations2 = annotator2.ReadAll();

            Assert.AreEqual(expectedAnnotations2, annotations2);

            // Reopening the first annotator, this time it should have the 1 number
            annotator1.Open("data/100s");
            var annotations1 = annotator1.ReadAll();

            Assert.AreEqual(expectedAnnotations1, annotations1);

            annotator1.Close();
            annotator2.Close();
            Assert.IsFalse(annotator1.IsOpen);
            Assert.IsFalse(annotator2.IsOpen);

            // Reopening in the same order
            annotator1.Open("data/100s"); //0
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsFalse(annotator2.IsOpen);

            annotator2.Open("data/100s"); //1
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            // Reading Some data
            annotations1 = annotator1.ReadAll();  // 0
            Assert.AreEqual(expectedAnnotations1, annotations1);

            annotations2 = annotator2.ReadAll(); // 1
            Assert.AreEqual(expectedAnnotations2, annotations2);

            annotator1.Close();
            annotator2.Close();

            // reopening in an inversed order
            annotator2.Open("data/100s"); //0
            Assert.IsTrue(annotator2.IsOpen);
            Assert.IsFalse(annotator1.IsOpen);

            annotator1.Open("data/100s"); //1
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            // Reading Some data
            annotations1 = annotator1.ReadAll();  // 0
            Assert.AreEqual(expectedAnnotations1, annotations1);

            annotations2 = annotator2.ReadAll(); // 1
            Assert.AreEqual(expectedAnnotations2, annotations2);

            annotator1.Close();
            annotator2.Close();
        }
 public void OpenInexistingRecordTest()
 {
     var annotator = new Annotator {Name = "atr", Stat = Stat.Read};
     annotator.Open("some inexistent record");
 }
        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();
        }
        public void OpenClose1AnnotatorValidRecordTest()
        {
            // Valid annotator

            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };

            // ****************************
            // Keeping old annotators open.
            // ****************************

            annotator.Open("data/100s");
            Assert.IsTrue(annotator.IsOpen);
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);

            // Reopening the same annotator.
            annotator.Open("data/100s");
            Assert.IsTrue(annotator.IsOpen);
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);
        }
        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 NumberTest()
        {
            var annotator1 = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator1.Open("data/100s");
            Assert.AreEqual(0, annotator1.Number);

            var annotator2 = new Annotator { Name = "hrv", Stat = Stat.Read };
            annotator2.Open("data/100s");
            Assert.AreEqual(0, annotator1.Number);
            Assert.AreEqual(1, annotator2.Number);

            annotator1.Close();
            Assert.AreEqual(-1, annotator1.Number);
            Assert.AreEqual(0, annotator2.Number);

            annotator1.Open("data/100s");
            Assert.AreEqual(0, annotator2.Number);
            Assert.AreEqual(1, annotator1.Number);
            Annotator.CloseAll();

            Assert.AreEqual(-1, annotator1.Number);
            Assert.AreEqual(-1, annotator2.Number);
        }
 public void ReadAllClosedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/100s");
     annotator.Close();
     annotator.ReadAll().ToList(); // force a loop
 }
 public void OpenOpenedAnnotator()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/100s");
     annotator.Open("data/100s");
 }
        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);
        }