// Path: src/main/java/au/net/woodberry/ta/toolbox/enums/Sustainability.java
// public enum Sustainability {
// 
//     UNKNOWN, // Used under some conditions where the indicator cannot determine one of the other values
//     HOPE, 
//     CONFIDENT, 
//     CERTAINTY
// 
// }
// 
// Path: src/test/java/au/net/woodberry/ta/toolbox/indicators/StubDataTestUtils.java
// public class StubDataTestUtils {
// 
//     private static final String SEPARATOR = ",";
//     private static final String COMMENT_LINE = "#";
//     private static final int TIMESTAMP = 0;
//     private static final int OPEN = 1;
//     private static final int HIGH = 2;
//     private static final int LOW = 3;
//     private static final int CLOSE = 4;
//     private static final int VOLUME = 5;
// 
//     private StubDataTestUtils() {}
// 
//     public static List<Tick> createTickData(String stubData) {
//         return createTickData(stubData, SEPARATOR, null, null);
//     }
//     
//     public static List<Tick> createTickData(String stubData, DateTimeFormatter dtf) {
//         return createTickData(stubData, SEPARATOR, null, dtf);
//     }
// 
//     public static List<Tick> createTickData(String stubData, String separator, Pattern header, DateTimeFormatter dtf) {
//         List<Tick> ticks = new ArrayList<>();
//         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(StubDataTestUtils.class.getResourceAsStream(stubData)));
//         String line;
//         try {
//             while ((line = bufferedReader.readLine()) != null) {
//                 String[] data = line.split(separator);
//                 if (data == null || (header != null && header.matcher(line).matches()) || line.startsWith(COMMENT_LINE)) { // Headers, comments, no data
//                     continue;
//                 }
//                 DateTime dt = dtf != null ? DateTime.parse(data[TIMESTAMP], dtf) : DateTime.parse(data[TIMESTAMP]);
//                 Tick tick = new Tick(dt, Double.parseDouble(data[OPEN]), Double.parseDouble(data[HIGH]), Double.parseDouble(data[LOW]),
//                         Double.parseDouble(data[CLOSE]), Double.parseDouble(data[VOLUME]));
//                 ticks.add(tick);
//             }
//             bufferedReader.close();
//         } catch (IOException e) {
//             throw new RuntimeException(e);
//         }
//         return ticks;
//     }
// }
// 
// Path: src/main/java/au/net/woodberry/ta/toolbox/object/TrendVolatilityLine.java
// public class TrendVolatilityLine {
// 
//     private final TADecimal value;
//     private final Sustainability sustainability;
// 
//     public TrendVolatilityLine(TADecimal value, Sustainability sustainability) {
//         this.value = value;
//         this.sustainability = sustainability;
//     }
// 
//     public Sustainability getSustainability() {
//         return sustainability;
//     }
// 
//     public TADecimal getValue() {
//         return value;
//     }
// 
//     @Override
//     public boolean equals(Object aThat) {
//         if ( this == aThat ) {
//             return true;
//         }
//         if (!(aThat instanceof TrendVolatilityLine)) {
//             return false;
//         }
//         TrendVolatilityLine that = (TrendVolatilityLine)aThat;
//         return this.getSustainability().equals(that.getSustainability())
//                 && this.getValue().equals(that.getValue());
//     }
// 
//     @Override
//     public String toString() {
//         return "Value: " + value + " Sustainability: " + sustainability;
//     }
// }


import au.net.woodberry.ta.toolbox.enums.Sustainability;
import au.net.woodberry.ta.toolbox.indicators.StubDataTestUtils;
import au.net.woodberry.ta.toolbox.object.TrendVolatilityLine;
import eu.verdelhan.ta4j.TADecimal;
import eu.verdelhan.ta4j.TimeSeries;
import eu.verdelhan.ta4j.indicators.simple.ClosePriceIndicator;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
package au.net.woodberry.ta.toolbox.indicators.trend;



public class TrendVolatilityLineIndicatorTest {
    
    private static final DateTimeFormatter DTF = DateTimeFormat.forPattern("dd/MM/YY");
    private static final double DELTA = 0.0001;

    
    @Test(expected = IllegalArgumentException.class)
    public void testNullGMMAIndicatorThrowsException() {
        new TrendVolatilityLineIndicator(null, TADecimal.ONE);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNullEntryValueThrowsException() {
        TimeSeries timeSeries = new TimeSeries(StubDataTestUtils.createTickData("/TEST_TREND_VOLATILITY_LINE_TC1.stub", "\t", null, DTF));
        new TrendVolatilityLineIndicator(new GuppyMultipleMovingAverageIndicator(new ClosePriceIndicator(timeSeries)), null);
    }
    
    @Test
    public void testCalculateForFirstEntryTC1() {
        final TADecimal entry = TADecimal.valueOf(4245.7);
        TimeSeries timeSeries = new TimeSeries(StubDataTestUtils.createTickData("/TEST_TREND_VOLATILITY_LINE_TC1.stub", "\t", null, DTF));
        TrendVolatilityLineIndicator tvlIndicator = new TrendVolatilityLineIndicator(new GuppyMultipleMovingAverageIndicator(new ClosePriceIndicator(timeSeries)), entry);
        TrendVolatilityLine tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("1/3/12", DTF)));
        assertNull(tvl.getValue());
// Path: src/main/java/au/net/woodberry/ta/toolbox/enums/Sustainability.java
// public enum Sustainability {
// 
//     UNKNOWN, // Used under some conditions where the indicator cannot determine one of the other values
//     HOPE, 
//     CONFIDENT, 
//     CERTAINTY
// 
// }
// 
// Path: src/test/java/au/net/woodberry/ta/toolbox/indicators/StubDataTestUtils.java
// public class StubDataTestUtils {
// 
//     private static final String SEPARATOR = ",";
//     private static final String COMMENT_LINE = "#";
//     private static final int TIMESTAMP = 0;
//     private static final int OPEN = 1;
//     private static final int HIGH = 2;
//     private static final int LOW = 3;
//     private static final int CLOSE = 4;
//     private static final int VOLUME = 5;
// 
//     private StubDataTestUtils() {}
// 
//     public static List<Tick> createTickData(String stubData) {
//         return createTickData(stubData, SEPARATOR, null, null);
//     }
//     
//     public static List<Tick> createTickData(String stubData, DateTimeFormatter dtf) {
//         return createTickData(stubData, SEPARATOR, null, dtf);
//     }
// 
//     public static List<Tick> createTickData(String stubData, String separator, Pattern header, DateTimeFormatter dtf) {
//         List<Tick> ticks = new ArrayList<>();
//         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(StubDataTestUtils.class.getResourceAsStream(stubData)));
//         String line;
//         try {
//             while ((line = bufferedReader.readLine()) != null) {
//                 String[] data = line.split(separator);
//                 if (data == null || (header != null && header.matcher(line).matches()) || line.startsWith(COMMENT_LINE)) { // Headers, comments, no data
//                     continue;
//                 }
//                 DateTime dt = dtf != null ? DateTime.parse(data[TIMESTAMP], dtf) : DateTime.parse(data[TIMESTAMP]);
//                 Tick tick = new Tick(dt, Double.parseDouble(data[OPEN]), Double.parseDouble(data[HIGH]), Double.parseDouble(data[LOW]),
//                         Double.parseDouble(data[CLOSE]), Double.parseDouble(data[VOLUME]));
//                 ticks.add(tick);
//             }
//             bufferedReader.close();
//         } catch (IOException e) {
//             throw new RuntimeException(e);
//         }
//         return ticks;
//     }
// }
// 
// Path: src/main/java/au/net/woodberry/ta/toolbox/object/TrendVolatilityLine.java
// public class TrendVolatilityLine {
// 
//     private final TADecimal value;
//     private final Sustainability sustainability;
// 
//     public TrendVolatilityLine(TADecimal value, Sustainability sustainability) {
//         this.value = value;
//         this.sustainability = sustainability;
//     }
// 
//     public Sustainability getSustainability() {
//         return sustainability;
//     }
// 
//     public TADecimal getValue() {
//         return value;
//     }
// 
//     @Override
//     public boolean equals(Object aThat) {
//         if ( this == aThat ) {
//             return true;
//         }
//         if (!(aThat instanceof TrendVolatilityLine)) {
//             return false;
//         }
//         TrendVolatilityLine that = (TrendVolatilityLine)aThat;
//         return this.getSustainability().equals(that.getSustainability())
//                 && this.getValue().equals(that.getValue());
//     }
// 
//     @Override
//     public String toString() {
//         return "Value: " + value + " Sustainability: " + sustainability;
//     }
// }


// Path: src/test/java/au/net/woodberry/ta/toolbox/indicators/trend/TrendVolatilityLineIndicatorTest.java
import au.net.woodberry.ta.toolbox.enums.Sustainability;
import au.net.woodberry.ta.toolbox.indicators.StubDataTestUtils;
import au.net.woodberry.ta.toolbox.object.TrendVolatilityLine;
import eu.verdelhan.ta4j.TADecimal;
import eu.verdelhan.ta4j.TimeSeries;
import eu.verdelhan.ta4j.indicators.simple.ClosePriceIndicator;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

package au.net.woodberry.ta.toolbox.indicators.trend;



public class TrendVolatilityLineIndicatorTest {
    
    private static final DateTimeFormatter DTF = DateTimeFormat.forPattern("dd/MM/YY");
    private static final double DELTA = 0.0001;

    
    @Test(expected = IllegalArgumentException.class)
    public void testNullGMMAIndicatorThrowsException() {
        new TrendVolatilityLineIndicator(null, TADecimal.ONE);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNullEntryValueThrowsException() {
        TimeSeries timeSeries = new TimeSeries(StubDataTestUtils.createTickData("/TEST_TREND_VOLATILITY_LINE_TC1.stub", "\t", null, DTF));
        new TrendVolatilityLineIndicator(new GuppyMultipleMovingAverageIndicator(new ClosePriceIndicator(timeSeries)), null);
    }
    
    @Test
    public void testCalculateForFirstEntryTC1() {
        final TADecimal entry = TADecimal.valueOf(4245.7);
        TimeSeries timeSeries = new TimeSeries(StubDataTestUtils.createTickData("/TEST_TREND_VOLATILITY_LINE_TC1.stub", "\t", null, DTF));
        TrendVolatilityLineIndicator tvlIndicator = new TrendVolatilityLineIndicator(new GuppyMultipleMovingAverageIndicator(new ClosePriceIndicator(timeSeries)), entry);
        TrendVolatilityLine tvl = tvlIndicator.getValue(index(timeSeries, DateTime.parse("1/3/12", DTF)));
        assertNull(tvl.getValue());
        assertEquals(Sustainability.UNKNOWN, tvl.getSustainability());