package at.jku.pervasive.ecg.wfdb;

import java.io.File;

import org.joda.time.LocalTime;

public class HrvTest extends PhysioToolkitTestCase {

  public static void main(String[] args) throws Exception {
    new HrvTest().testHrv();
  }

  public void testHrv() throws Exception {
    File testFile = getFile("/test.dat");
    testFile = new File(testFile.getParentFile(), "test");
    HRV hrv = physioToolkit.hrv(testFile, "qrs");

    assertNotNull(hrv);
    assertEquals(1.31832D, hrv.getAVNN(), 0.001D);
    assertEquals(0.689728D, hrv.getSDNN(), 0.001D);
  }

  public void testHrvWithTimes() throws Exception {
    File testFile = getFile("/test.edf");
    testFile = new File(testFile.getParentFile(), "test");
    HRV hrv = physioToolkit.hrv(testFile, "qrs", new LocalTime(0, 0),
        new LocalTime(7, 0));

    assertNotNull(hrv);
    assertEquals(1.31832D, hrv.getAVNN(), 0.001D);
    assertEquals(0.689728D, hrv.getSDNN(), 0.001D);
  }

  public void testHrvWithTimes2() throws Exception {
    File testFile = getFile("/test.edf");
    testFile = new File(testFile.getParentFile(), "test");
    HRV hrv = physioToolkit.hrv(testFile, "qrs", new LocalTime(1, 0),
        new LocalTime(2, 0));

    assertNotNull(hrv);
    assertEquals(1.41793D, hrv.getAVNN(), 0.001D);
    assertEquals(0.810737D, hrv.getSDNN(), 0.001D);
  }

  public void testLargeFile() throws Exception {
    File chf03 = getFile("/chf03.dat");
    chf03 = new File(chf03.getParentFile(), "chf03");
    HRV hrv = physioToolkit.hrv(chf03, "ecg");

    assertNotNull(hrv);
    assertEquals(0.892769, hrv.getAVNN(), 0.000001D);
    assertEquals(0.0612485, hrv.getSDNN(), 0.000001D);
  }

  public void testLargeFileHRVOptions() throws Exception {
    File chf03dat = getFile("/chf03.dat");
    HRVOptions options = new HRVOptions("chf03", "ecg");
    options.setBaseDirectory(chf03dat.getParentFile());
    HRV hrv = physioToolkit.hrv(options);

    assertNotNull(hrv);
    assertEquals(0.892769, hrv.getAVNN(), 0.000001D);
    assertEquals(0.0612485, hrv.getSDNN(), 0.000001D);
  }

  public void testLargeFileWithOutlierDetection() throws Exception {
    File chf03 = getFile("/chf03.dat");
    chf03 = new File(chf03.getParentFile(), "chf03");
    HRV hrv = physioToolkit.hrv(chf03, "ecg", "-f 0.2 20 -x 0.4 2.0",
        "-p 20 50");

    assertNotNull(hrv);
    assertEquals(0.892206, hrv.getAVNN(), 0.000001D);
    assertEquals(0.054712, hrv.getSDNN(), 0.000001D);
  }

  public void testLargeFileWithOutlierDetectionAndStartAndEndTime()
      throws Exception {
    File chf03 = getFile("/chf03.dat");
    chf03 = new File(chf03.getParentFile(), "chf03");
    HRV hrv = physioToolkit.hrv(chf03, "ecg", new LocalTime(0, 0),
        new LocalTime(1, 0), "-s", "-M", "-f 0.2 20 -x 0.4 2.0", "-p 20 50");

    assertNotNull(hrv);
    assertEquals(867.958D, hrv.getAVNN(), 0.000001D);
    assertEquals(39.7191D, hrv.getSDNN(), 0.000001D);
  }

}

@@ -290,32 +290,36 @@
 e testFile = get
+WFDB
 File(%22/test.dat%22
@@ -325,67 +325,8 @@
 %22);%0A
-    testFile = new File(testFile.getParentFile(), %22test%22);%0A
     
@@ -571,32 +571,36 @@
 e testFile = get
+WFDB
 File(%22/test.edf%22
@@ -606,67 +606,8 @@
 %22);%0A
-    testFile = new File(testFile.getParentFile(), %22test%22);%0A
     
@@ -907,24 +907,28 @@
 stFile = get
+WFDB
 File(%22/test.
@@ -938,67 +938,8 @@
 %22);%0A
-    testFile = new File(testFile.getParentFile(), %22test%22);%0A
     
@@ -1228,32 +1228,36 @@
 File chf03 = get
+WFDB
 File(%22/chf03.dat
@@ -1264,62 +1264,8 @@
 %22);%0A
-    chf03 = new File(chf03.getParentFile(), %22chf03%22);%0A
     
@@ -1523,17 +1523,18 @@
 hf03
-dat
  = get
+WFDB
 File
@@ -1640,19 +1640,16 @@
 ry(chf03
-dat
 .getPare
@@ -1921,32 +1921,36 @@
 File chf03 = get
+WFDB
 File(%22/chf03.dat
@@ -1957,62 +1957,8 @@
 %22);%0A
-    chf03 = new File(chf03.getParentFile(), %22chf03%22);%0A
     
@@ -2295,16 +2295,20 @@
 03 = get
+WFDB
 File(%22/c
@@ -2323,62 +2323,8 @@
 %22);%0A
-    chf03 = new File(chf03.getParentFile(), %22chf03%22);%0A
     

modify tests to use new getWFDBFile method